From ab9db141acdb79f6425a73f38c9a85092ee7a5c7 Mon Sep 17 00:00:00 2001 From: Robert-Beckett Date: Fri, 13 Jun 2025 18:31:23 -0300 Subject: [PATCH] When an error code between `0x0051` and `0x0054` inclusive is caught by `MCError`, the application throws two exceptions before crashing. The first is that `MCError: has failed, and the second is the cause of the nested error, `TypeError '>=' not supported between instances of 'str' and 'int'`. This is an attempted fix for that user, though I do not have a PLC to test on myself. I believe this will handle all cases, but since I'm uncertain what the real value of errorcode is, I've made a best effort correction based on what I can infer from the code. Hopefully this PR is welcome! --- pymelsec/exceptions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pymelsec/exceptions.py b/pymelsec/exceptions.py index 591e238..3011e29 100644 --- a/pymelsec/exceptions.py +++ b/pymelsec/exceptions.py @@ -12,7 +12,10 @@ class MCError(Exception): """ def __init__(self, errorcode): - self.errorcode = f'0x{str(errorcode).rjust(4, "0").upper()}' + if isinstance(errorcode, str): + self.errorcode = int(f'0x{errorcode.rjust(4, "0").upper()}', 16) + elif isinstance(errorcode, int): + self.errorcode = errorcode def __str__(self): @@ -71,6 +74,7 @@ def __str__(self): elif self.errorcode == 0xC204: return (f'{self.errorcode}: The connected device is different from the one that requested for ' 'unlock processing of the remote password.') + return f'{self.errorcode}: Unknown error.' class DataTypeError(Exception):