@@ -69,6 +69,39 @@ class S7UserDataSubfunction(IntEnum):
6969 SET_CLOCK = 0x02
7070
7171
72+ # S7 data section return codes with human-readable descriptions
73+ S7_RETURN_CODES : Dict [int , str ] = {
74+ 0x00 : "Reserved" ,
75+ 0x01 : "Hardware error" ,
76+ 0x03 : "Accessing the object not allowed" ,
77+ 0x05 : "Invalid address" ,
78+ 0x06 : "Data type not supported" ,
79+ 0x07 : "Data type inconsistent" ,
80+ 0x0A : "Object does not exist" ,
81+ 0x10 : "Invalid block type number" ,
82+ 0x11 : "Block not found in storage medium" ,
83+ 0x12 : "Block already exists" ,
84+ 0x13 : "Block is protected" ,
85+ 0x14 : "Block download without proper block first" ,
86+ 0x19 : "Block download sequence error" ,
87+ 0x1A : "Insufficient working memory" ,
88+ 0x1B : "Insufficient load memory" ,
89+ 0x1C : "Not enough work retentive data (instance DBs)" ,
90+ 0x1D : "Interface error" ,
91+ 0x1E : "Delete block refused" ,
92+ 0x20 : "Invalid parameter" ,
93+ 0x21 : "PG resource error (max connections reached)" ,
94+ 0xFF : "Success" ,
95+ }
96+
97+
98+ def get_return_code_description (return_code : int ) -> str :
99+ """Get human-readable description for S7 return code."""
100+ if return_code in S7_RETURN_CODES :
101+ return S7_RETURN_CODES [return_code ]
102+ return "Unknown error"
103+
104+
72105class S7Protocol :
73106 """
74107 S7 protocol implementation.
@@ -1315,8 +1348,8 @@ def extract_read_data(self, response: Dict[str, Any], word_len: S7WordLen, count
13151348 return_code = data_info .get ("return_code" , 0 )
13161349
13171350 if return_code != 0xFF : # 0xFF = Success
1318- error_msg = f"Read operation failed with return code: { return_code :#02x } "
1319- raise S7ProtocolError (error_msg )
1351+ desc = get_return_code_description ( return_code )
1352+ raise S7ProtocolError (f"Read operation failed: { desc } (0x { return_code :02x } )" )
13201353
13211354 raw_data = data_info .get ("data" , b"" )
13221355
@@ -1346,6 +1379,6 @@ def check_write_response(self, response: Dict[str, Any]) -> None:
13461379 return_code = data_info .get ("return_code" , 0xFF ) # Default to success
13471380
13481381 if return_code != 0xFF : # 0xFF = Success
1349- error_msg = f"Write operation failed with return code: { return_code :#02x } "
1350- raise S7ProtocolError (error_msg )
1382+ desc = get_return_code_description ( return_code )
1383+ raise S7ProtocolError (f"Write operation failed: { desc } (0x { return_code :02x } )" )
13511384 # If no data and no header error, the write was successful (ACK without data)
0 commit comments