diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/DataItem.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/DataItem.py index ed1e6be6fc0..f41fbff50ec 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/DataItem.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/DataItem.py @@ -21,879 +21,641 @@ from loguru import logging as log from plc4py.protocols.modbus.readwrite.ModbusDataType import ModbusDataType import math - + class DataItem: + @staticmethod - def static_parse( - read_buffer: ReadBuffer, data_type: ModbusDataType, number_of_values: int - ): - if EvaluationHelper.equals( - data_type, ModbusDataType.BOOL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # BOOL + def static_parse(read_buffer: ReadBuffer, data_type: ModbusDataType, number_of_values: int): + if EvaluationHelper.equals( data_type, ModbusDataType.BOOL ) and EvaluationHelper.equals( number_of_values, int(1) ) : # BOOL + # Reserved Field (Compartmentalized so the "reserved" variable can't leak) reserved: int = read_buffer.read_unsigned_int(15, logical_name="") if reserved != int(0x0000): - log.info( - "Expected constant value " - + str(0x0000) - + " but got " - + reserved - + " for reserved field." - ) + log.info("Expected constant value " + str(0x0000) + " but got " + reserved + " for reserved field.") # Simple Field (value) value: bool = read_buffer.read_bit("") return PlcBOOL(value) - if EvaluationHelper.equals(data_type, ModbusDataType.BOOL): # List + if EvaluationHelper.equals( data_type, ModbusDataType.BOOL ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcBOOL(bool(read_buffer.read_bit("")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.BYTE - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # BYTE + if EvaluationHelper.equals( data_type, ModbusDataType.BYTE ) and EvaluationHelper.equals( number_of_values, int(1) ) : # BYTE + # Reserved Field (Compartmentalized so the "reserved" variable can't leak) reserved: int = read_buffer.read_unsigned_short(8, logical_name="") if reserved != int(0x00): - log.info( - "Expected constant value " - + str(0x00) - + " but got " - + reserved - + " for reserved field." - ) + log.info("Expected constant value " + str(0x00) + " but got " + reserved + " for reserved field.") # Simple Field (value) value: int = read_buffer.read_unsigned_short(8, logical_name="") return PlcBYTE(value) - if EvaluationHelper.equals(data_type, ModbusDataType.BYTE): # List + if EvaluationHelper.equals( data_type, ModbusDataType.BYTE ) : # List # Array field (value) # Count array - if number_of_values * int(8) > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values * int(8)) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) - - item_count: int = int(number_of_values * int(8)) + if number_of_values* int(8) > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values* int(8)) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + + item_count: int = int(number_of_values* int(8)) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcBOOL(bool(read_buffer.read_bit("")))) + return PlcList(value) - if EvaluationHelper.equals(data_type, ModbusDataType.WORD): # WORD + if EvaluationHelper.equals( data_type, ModbusDataType.WORD ) : # WORD + # Simple Field (value) value: int = read_buffer.read_unsigned_int(16, logical_name="") return PlcWORD(value) - if EvaluationHelper.equals(data_type, ModbusDataType.DWORD): # DWORD + if EvaluationHelper.equals( data_type, ModbusDataType.DWORD ) : # DWORD + # Simple Field (value) value: int = read_buffer.read_unsigned_long(32, logical_name="") return PlcDWORD(value) - if EvaluationHelper.equals(data_type, ModbusDataType.LWORD): # LWORD + if EvaluationHelper.equals( data_type, ModbusDataType.LWORD ) : # LWORD + # Simple Field (value) value: int = read_buffer.read_unsigned_big_integer(64, logical_name="") return PlcLWORD(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.SINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # SINT + if EvaluationHelper.equals( data_type, ModbusDataType.SINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # SINT + # Reserved Field (Compartmentalized so the "reserved" variable can't leak) reserved: int = read_buffer.read_unsigned_short(8, logical_name="") if reserved != int(0x00): - log.info( - "Expected constant value " - + str(0x00) - + " but got " - + reserved - + " for reserved field." - ) + log.info("Expected constant value " + str(0x00) + " but got " + reserved + " for reserved field.") # Simple Field (value) value: int = read_buffer.read_signed_byte(8, logical_name="") return PlcSINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.SINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.SINT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcSINT(int(read_buffer.read_signed_byte(8, logical_name=""))) - ) + value.append(PlcSINT(int(read_buffer.read_signed_byte(8, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.INT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # INT + if EvaluationHelper.equals( data_type, ModbusDataType.INT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # INT + # Simple Field (value) value: int = read_buffer.read_short(16, logical_name="") return PlcINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.INT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.INT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcINT(int(read_buffer.read_short(16, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.DINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # DINT + if EvaluationHelper.equals( data_type, ModbusDataType.DINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # DINT + # Simple Field (value) value: int = read_buffer.read_int(32, logical_name="") return PlcDINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.DINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.DINT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcDINT(int(read_buffer.read_int(32, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.LINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # LINT + if EvaluationHelper.equals( data_type, ModbusDataType.LINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # LINT + # Simple Field (value) value: int = read_buffer.read_long(64, logical_name="") return PlcLINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.LINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.LINT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcLINT(int(read_buffer.read_long(64, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.USINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # USINT + if EvaluationHelper.equals( data_type, ModbusDataType.USINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # USINT + # Reserved Field (Compartmentalized so the "reserved" variable can't leak) reserved: int = read_buffer.read_unsigned_short(8, logical_name="") if reserved != int(0x00): - log.info( - "Expected constant value " - + str(0x00) - + " but got " - + reserved - + " for reserved field." - ) + log.info("Expected constant value " + str(0x00) + " but got " + reserved + " for reserved field.") # Simple Field (value) value: int = read_buffer.read_unsigned_short(8, logical_name="") return PlcUSINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.USINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.USINT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcUINT(int(read_buffer.read_unsigned_short(8, logical_name=""))) - ) + value.append(PlcUINT(int(read_buffer.read_unsigned_short(8, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.UINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # UINT + if EvaluationHelper.equals( data_type, ModbusDataType.UINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # UINT + # Simple Field (value) value: int = read_buffer.read_unsigned_int(16, logical_name="") return PlcUINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.UINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.UINT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcUDINT(int(read_buffer.read_unsigned_int(16, logical_name=""))) - ) + value.append(PlcUDINT(int(read_buffer.read_unsigned_int(16, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.UDINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # UDINT + if EvaluationHelper.equals( data_type, ModbusDataType.UDINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # UDINT + # Simple Field (value) value: int = read_buffer.read_unsigned_long(32, logical_name="") return PlcUDINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.UDINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.UDINT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcULINT(int(read_buffer.read_unsigned_long(32, logical_name=""))) - ) + value.append(PlcULINT(int(read_buffer.read_unsigned_long(32, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.ULINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # ULINT + if EvaluationHelper.equals( data_type, ModbusDataType.ULINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # ULINT + # Simple Field (value) value: int = read_buffer.read_unsigned_big_integer(64, logical_name="") return PlcULINT(value) - if EvaluationHelper.equals(data_type, ModbusDataType.ULINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.ULINT ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcLINT( - int(read_buffer.read_unsigned_big_integer(64, logical_name="")) - ) - ) + value.append(PlcLINT(int(read_buffer.read_unsigned_big_integer(64, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.REAL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # REAL + if EvaluationHelper.equals( data_type, ModbusDataType.REAL ) and EvaluationHelper.equals( number_of_values, int(1) ) : # REAL + # Simple Field (value) value: float = read_buffer.read_float(32, logical_name="") return PlcREAL(value) - if EvaluationHelper.equals(data_type, ModbusDataType.REAL): # List + if EvaluationHelper.equals( data_type, ModbusDataType.REAL ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcREAL(float(read_buffer.read_float(32, logical_name=""))) - ) + value.append(PlcREAL(float(read_buffer.read_float(32, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.LREAL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # LREAL + if EvaluationHelper.equals( data_type, ModbusDataType.LREAL ) and EvaluationHelper.equals( number_of_values, int(1) ) : # LREAL + # Simple Field (value) value: float = read_buffer.read_double(64, logical_name="") return PlcLREAL(value) - if EvaluationHelper.equals(data_type, ModbusDataType.LREAL): # List + if EvaluationHelper.equals( data_type, ModbusDataType.LREAL ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcLREAL(float(read_buffer.read_double(64, logical_name=""))) - ) + value.append(PlcLREAL(float(read_buffer.read_double(64, logical_name="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.CHAR - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # CHAR + if EvaluationHelper.equals( data_type, ModbusDataType.CHAR ) and EvaluationHelper.equals( number_of_values, int(1) ) : # CHAR + # Simple Field (value) value: str = read_buffer.read_string(8, logical_name="", encoding="") return PlcCHAR(value) - if EvaluationHelper.equals(data_type, ModbusDataType.CHAR): # List + if EvaluationHelper.equals( data_type, ModbusDataType.CHAR ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcSTRING( - str(read_buffer.read_string(8, logical_name="", encoding="")) - ) - ) + value.append(PlcSTRING(str(read_buffer.read_string(8, logical_name="", encoding="")))) + return PlcList(value) - if EvaluationHelper.equals( - data_type, ModbusDataType.WCHAR - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # WCHAR + if EvaluationHelper.equals( data_type, ModbusDataType.WCHAR ) and EvaluationHelper.equals( number_of_values, int(1) ) : # WCHAR + # Simple Field (value) value: str = read_buffer.read_string(16, logical_name="", encoding="") return PlcWCHAR(value) - if EvaluationHelper.equals(data_type, ModbusDataType.WCHAR): # List + if EvaluationHelper.equals( data_type, ModbusDataType.WCHAR ) : # List # Array field (value) # Count array if number_of_values > Integer.MAX_VALUE: - raise ParseException( - "Array count of " - + (number_of_values) - + " exceeds the maximum allowed count of " - + Integer.MAX_VALUE - ) + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): - value.append( - PlcSTRING( - str(read_buffer.read_string(16, logical_name="", encoding="")) - ) - ) + value.append(PlcSTRING(str(read_buffer.read_string(16, logical_name="", encoding="")))) + return PlcList(value) return None @staticmethod - def static_serialize( - writeBuffer: WriteBuffer, - _value: PlcValue, - dataType: ModbusDataType, - numberOfValues: int, - ) -> None: - static_serialize( - writeBuffer, _value, dataType, numberOfValues, ByteOrder.BIG_ENDIAN - ) + def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: ModbusDataType, numberOfValues: int) -> None: + static_serialize(writeBuffer, _value, dataType, numberOfValues, ByteOrder.BIG_ENDIAN) @staticmethod - def static_serialize( - writeBuffer: WriteBuffer, - _value: PlcValue, - dataType: ModbusDataType, - numberOfValues: int, - byteOrder: ByteOrder, - ) -> None: - if EvaluationHelper.equals( - data_type, ModbusDataType.BOOL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # BOOL + def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: ModbusDataType, numberOfValues: int, byteOrder: ByteOrder) -> None: + if EvaluationHelper.equals( data_type, ModbusDataType.BOOL ) and EvaluationHelper.equals( number_of_values, int(1) ) : # BOOL + # Reserved Field writeBuffer.WriteUint16("int0x0000", 15, int(0x0000)) # Simple Field (value) value: bool = _value.getBool() writeBuffer.WriteBit("value", (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.BOOL): # List + if EvaluationHelper.equals( data_type, ModbusDataType.BOOL ) : # List + values: PlcList = _value for val in values.getList(): value: bool = val.getBool() writeBuffer.WriteBit("value", (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.BYTE - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # BYTE + if EvaluationHelper.equals( data_type, ModbusDataType.BYTE ) and EvaluationHelper.equals( number_of_values, int(1) ) : # BYTE + # Reserved Field writeBuffer.WriteUint8("int0x00", 8, int(0x00)) # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint8("value", 8, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.BYTE): # List + if EvaluationHelper.equals( data_type, ModbusDataType.BYTE ) : # List + values: PlcList = _value for val in values.getList(): value: bool = val.getBool() writeBuffer.WriteBit("value", (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.WORD): # WORD + if EvaluationHelper.equals( data_type, ModbusDataType.WORD ) : # WORD + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint16("value", 16, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.DWORD): # DWORD + if EvaluationHelper.equals( data_type, ModbusDataType.DWORD ) : # DWORD + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint32("value", 32, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.LWORD): # LWORD + if EvaluationHelper.equals( data_type, ModbusDataType.LWORD ) : # LWORD + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint64("value", 64, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.SINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # SINT + if EvaluationHelper.equals( data_type, ModbusDataType.SINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # SINT + # Reserved Field writeBuffer.WriteUint8("int0x00", 8, int(0x00)) # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt8("value", 8, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.SINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.SINT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteInt8("value", 8, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.INT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # INT + if EvaluationHelper.equals( data_type, ModbusDataType.INT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # INT + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt16("value", 16, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.INT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.INT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteInt16("value", 16, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.DINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # DINT + if EvaluationHelper.equals( data_type, ModbusDataType.DINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # DINT + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt32("value", 32, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.DINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.DINT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteInt32("value", 32, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.LINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # LINT + if EvaluationHelper.equals( data_type, ModbusDataType.LINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # LINT + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt64("value", 64, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.LINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.LINT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteInt64("value", 64, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.USINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # USINT + if EvaluationHelper.equals( data_type, ModbusDataType.USINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # USINT + # Reserved Field writeBuffer.WriteUint8("int0x00", 8, int(0x00)) # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint8("value", 8, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.USINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.USINT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteUint8("value", 8, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.UINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # UINT + if EvaluationHelper.equals( data_type, ModbusDataType.UINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # UINT + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint16("value", 16, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.UINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.UINT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteUint16("value", 16, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.UDINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # UDINT + if EvaluationHelper.equals( data_type, ModbusDataType.UDINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # UDINT + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint32("value", 32, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.UDINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.UDINT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteUint32("value", 32, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.ULINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # ULINT + if EvaluationHelper.equals( data_type, ModbusDataType.ULINT ) and EvaluationHelper.equals( number_of_values, int(1) ) : # ULINT + # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint64("value", 64, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.ULINT): # List + if EvaluationHelper.equals( data_type, ModbusDataType.ULINT ) : # List + values: PlcList = _value for val in values.getList(): value: int = val.getInt() writeBuffer.WriteUint64("value", 64, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.REAL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # REAL + if EvaluationHelper.equals( data_type, ModbusDataType.REAL ) and EvaluationHelper.equals( number_of_values, int(1) ) : # REAL + # Simple Field (value) value: float = _value.getFloat() writeBuffer.WriteFloat32("value", 32, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.REAL): # List + if EvaluationHelper.equals( data_type, ModbusDataType.REAL ) : # List + values: PlcList = _value for val in values.getList(): value: float = val.getFloat() writeBuffer.WriteFloat32("value", 32, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.LREAL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # LREAL + if EvaluationHelper.equals( data_type, ModbusDataType.LREAL ) and EvaluationHelper.equals( number_of_values, int(1) ) : # LREAL + # Simple Field (value) value: float = _value.getFloat() writeBuffer.WriteFloat64("value", 64, (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.LREAL): # List + if EvaluationHelper.equals( data_type, ModbusDataType.LREAL ) : # List + values: PlcList = _value for val in values.getList(): value: float = val.getFloat() writeBuffer.WriteFloat64("value", 64, (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.CHAR - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # CHAR + if EvaluationHelper.equals( data_type, ModbusDataType.CHAR ) and EvaluationHelper.equals( number_of_values, int(1) ) : # CHAR + # Simple Field (value) value: str = _value.getStr() writeBuffer.WriteString("value", uint32(8), "UTF-8", (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.CHAR): # List + if EvaluationHelper.equals( data_type, ModbusDataType.CHAR ) : # List + values: PlcList = _value for val in values.getList(): value: str = val.getStr() writeBuffer.WriteString("value", uint32(8), "UTF-8", (value)) - if EvaluationHelper.equals( - data_type, ModbusDataType.WCHAR - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # WCHAR + if EvaluationHelper.equals( data_type, ModbusDataType.WCHAR ) and EvaluationHelper.equals( number_of_values, int(1) ) : # WCHAR + # Simple Field (value) value: str = _value.getStr() writeBuffer.WriteString("value", uint32(16), "UTF-16", (value)) - if EvaluationHelper.equals(data_type, ModbusDataType.WCHAR): # List + if EvaluationHelper.equals( data_type, ModbusDataType.WCHAR ) : # List + values: PlcList = _value for val in values.getList(): value: str = val.getStr() writeBuffer.WriteString("value", uint32(16), "UTF-16", (value)) + @staticmethod - def get_length_in_bytes( - _value: PlcValue, dataType: ModbusDataType, numberOfValues: int - ) -> int: - return int( - math.ceil(float(getLengthInBits(_value, dataType, numberOfValues)) / 8.0) - ) + def get_length_in_bytes(_value: PlcValue, dataType: ModbusDataType, numberOfValues: int) -> int: + return int(math.ceil(float(getLengthInBits(_value, dataType, numberOfValues)) / 8.0)) + @staticmethod - def get_length_in_bits( - _value: PlcValue, dataType: ModbusDataType, numberOfValues: int - ) -> int: + def get_length_in_bits(_value: PlcValue, dataType: ModbusDataType, numberOfValues: int) -> int: sizeInBits: int = 0 - if EvaluationHelper.equals( - data_type, ModbusDataType.BOOL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # BOOL - # Reserved Field - sizeInBits += 15 - # Simple Field (value) - sizeInBits += 1 - if EvaluationHelper.equals(data_type, ModbusDataType.BOOL): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 1 - if EvaluationHelper.equals( - data_type, ModbusDataType.BYTE - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # BYTE - # Reserved Field - sizeInBits += 8 - # Simple Field (value) - sizeInBits += 8 - if EvaluationHelper.equals(data_type, ModbusDataType.BYTE): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 1 - if EvaluationHelper.equals(data_type, ModbusDataType.WORD): # WORD - # Simple Field (value) - sizeInBits += 16 - if EvaluationHelper.equals(data_type, ModbusDataType.DWORD): # DWORD - # Simple Field (value) - sizeInBits += 32 - if EvaluationHelper.equals(data_type, ModbusDataType.LWORD): # LWORD - # Simple Field (value) - sizeInBits += 64 - if EvaluationHelper.equals( - data_type, ModbusDataType.SINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # SINT - # Reserved Field - sizeInBits += 8 - # Simple Field (value) - sizeInBits += 8 - if EvaluationHelper.equals(data_type, ModbusDataType.SINT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 8 - if EvaluationHelper.equals( - data_type, ModbusDataType.INT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # INT - # Simple Field (value) - sizeInBits += 16 - if EvaluationHelper.equals(data_type, ModbusDataType.INT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 16 - if EvaluationHelper.equals( - data_type, ModbusDataType.DINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # DINT - # Simple Field (value) - sizeInBits += 32 - if EvaluationHelper.equals(data_type, ModbusDataType.DINT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 32 - if EvaluationHelper.equals( - data_type, ModbusDataType.LINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # LINT - # Simple Field (value) - sizeInBits += 64 - if EvaluationHelper.equals(data_type, ModbusDataType.LINT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 64 - if EvaluationHelper.equals( - data_type, ModbusDataType.USINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # USINT - # Reserved Field - sizeInBits += 8 - # Simple Field (value) - sizeInBits += 8 - if EvaluationHelper.equals(data_type, ModbusDataType.USINT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 8 - if EvaluationHelper.equals( - data_type, ModbusDataType.UINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # UINT - # Simple Field (value) - sizeInBits += 16 - if EvaluationHelper.equals(data_type, ModbusDataType.UINT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 16 - if EvaluationHelper.equals( - data_type, ModbusDataType.UDINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # UDINT - # Simple Field (value) - sizeInBits += 32 - if EvaluationHelper.equals(data_type, ModbusDataType.UDINT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 32 - if EvaluationHelper.equals( - data_type, ModbusDataType.ULINT - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # ULINT - # Simple Field (value) - sizeInBits += 64 - if EvaluationHelper.equals(data_type, ModbusDataType.ULINT): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 64 - if EvaluationHelper.equals( - data_type, ModbusDataType.REAL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # REAL - # Simple Field (value) - sizeInBits += 32 - if EvaluationHelper.equals(data_type, ModbusDataType.REAL): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 32 - if EvaluationHelper.equals( - data_type, ModbusDataType.LREAL - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # LREAL - # Simple Field (value) - sizeInBits += 64 - if EvaluationHelper.equals(data_type, ModbusDataType.LREAL): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 64 - if EvaluationHelper.equals( - data_type, ModbusDataType.CHAR - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # CHAR - # Simple Field (value) - sizeInBits += 8 - if EvaluationHelper.equals(data_type, ModbusDataType.CHAR): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 8 - if EvaluationHelper.equals( - data_type, ModbusDataType.WCHAR - ) and EvaluationHelper.equals( - number_of_values, int(1) - ): # WCHAR - # Simple Field (value) - sizeInBits += 16 - if EvaluationHelper.equals(data_type, ModbusDataType.WCHAR): # List - values: PlcList = _value - sizeInBits += values.getList().size() * 16 + if EvaluationHelper.equals( data_type, ModbusDataType.BOOL ) and EvaluationHelper.equals( number_of_values, int(1) ): # BOOL + # Reserved Field + sizeInBits += 15 + # Simple Field (value) + sizeInBits += 1 + if EvaluationHelper.equals( data_type, ModbusDataType.BOOL ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 1 + if EvaluationHelper.equals( data_type, ModbusDataType.BYTE ) and EvaluationHelper.equals( number_of_values, int(1) ): # BYTE + # Reserved Field + sizeInBits += 8 + # Simple Field (value) + sizeInBits += 8 + if EvaluationHelper.equals( data_type, ModbusDataType.BYTE ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 1 + if EvaluationHelper.equals( data_type, ModbusDataType.WORD ): # WORD + # Simple Field (value) + sizeInBits += 16 + if EvaluationHelper.equals( data_type, ModbusDataType.DWORD ): # DWORD + # Simple Field (value) + sizeInBits += 32 + if EvaluationHelper.equals( data_type, ModbusDataType.LWORD ): # LWORD + # Simple Field (value) + sizeInBits += 64 + if EvaluationHelper.equals( data_type, ModbusDataType.SINT ) and EvaluationHelper.equals( number_of_values, int(1) ): # SINT + # Reserved Field + sizeInBits += 8 + # Simple Field (value) + sizeInBits += 8 + if EvaluationHelper.equals( data_type, ModbusDataType.SINT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 8 + if EvaluationHelper.equals( data_type, ModbusDataType.INT ) and EvaluationHelper.equals( number_of_values, int(1) ): # INT + # Simple Field (value) + sizeInBits += 16 + if EvaluationHelper.equals( data_type, ModbusDataType.INT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 16 + if EvaluationHelper.equals( data_type, ModbusDataType.DINT ) and EvaluationHelper.equals( number_of_values, int(1) ): # DINT + # Simple Field (value) + sizeInBits += 32 + if EvaluationHelper.equals( data_type, ModbusDataType.DINT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 32 + if EvaluationHelper.equals( data_type, ModbusDataType.LINT ) and EvaluationHelper.equals( number_of_values, int(1) ): # LINT + # Simple Field (value) + sizeInBits += 64 + if EvaluationHelper.equals( data_type, ModbusDataType.LINT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 64 + if EvaluationHelper.equals( data_type, ModbusDataType.USINT ) and EvaluationHelper.equals( number_of_values, int(1) ): # USINT + # Reserved Field + sizeInBits += 8 + # Simple Field (value) + sizeInBits += 8 + if EvaluationHelper.equals( data_type, ModbusDataType.USINT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 8 + if EvaluationHelper.equals( data_type, ModbusDataType.UINT ) and EvaluationHelper.equals( number_of_values, int(1) ): # UINT + # Simple Field (value) + sizeInBits += 16 + if EvaluationHelper.equals( data_type, ModbusDataType.UINT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 16 + if EvaluationHelper.equals( data_type, ModbusDataType.UDINT ) and EvaluationHelper.equals( number_of_values, int(1) ): # UDINT + # Simple Field (value) + sizeInBits += 32 + if EvaluationHelper.equals( data_type, ModbusDataType.UDINT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 32 + if EvaluationHelper.equals( data_type, ModbusDataType.ULINT ) and EvaluationHelper.equals( number_of_values, int(1) ): # ULINT + # Simple Field (value) + sizeInBits += 64 + if EvaluationHelper.equals( data_type, ModbusDataType.ULINT ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 64 + if EvaluationHelper.equals( data_type, ModbusDataType.REAL ) and EvaluationHelper.equals( number_of_values, int(1) ): # REAL + # Simple Field (value) + sizeInBits += 32 + if EvaluationHelper.equals( data_type, ModbusDataType.REAL ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 32 + if EvaluationHelper.equals( data_type, ModbusDataType.LREAL ) and EvaluationHelper.equals( number_of_values, int(1) ): # LREAL + # Simple Field (value) + sizeInBits += 64 + if EvaluationHelper.equals( data_type, ModbusDataType.LREAL ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 64 + if EvaluationHelper.equals( data_type, ModbusDataType.CHAR ) and EvaluationHelper.equals( number_of_values, int(1) ): # CHAR + # Simple Field (value) + sizeInBits += 8 + if EvaluationHelper.equals( data_type, ModbusDataType.CHAR ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 8 + if EvaluationHelper.equals( data_type, ModbusDataType.WCHAR ) and EvaluationHelper.equals( number_of_values, int(1) ): # WCHAR + # Simple Field (value) + sizeInBits += 16 + if EvaluationHelper.equals( data_type, ModbusDataType.WCHAR ): # List + values: PlcList = _value + sizeInBits += values.getList().size() * 16 return sizeInBits + + + + diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusADU.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusADU.py index 6646847c8f6..785b3172371 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusADU.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusADU.py @@ -21,7 +21,9 @@ from abc import ABC from abc import abstractmethod +from plc4py.api.exceptions.exceptions import ParseException from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.DriverType import DriverType from plc4py.spi.generation.ReadBuffer import ReadBuffer @@ -33,10 +35,6 @@ class ModbusADU(ABC, PlcMessage): # Arguments. response: bool - - def __post_init__(self): - super().__init__( ) - # Abstract accessors for discriminator values. @property @abstractmethod @@ -58,9 +56,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusADU = self @@ -69,29 +67,31 @@ def get_length_in_bits(self) -> int: return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - if args is None: + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + + if kwargs is None: raise PlcRuntimeException("Wrong number of arguments, expected 2, but got None") - elif args.length != 2: - raise PlcRuntimeException("Wrong number of arguments, expected 2, but got " + str(len(args))) - - driverType: DriverType = 0 - if isinstance(args[0], DriverType): - driverType = DriverType(args[0]) - elif isinstance(args[0], str): - driverType = DriverType(str(args[0])) + elif len(kwargs) == 2: + raise PlcRuntimeException("Wrong number of arguments, expected 2, but got " + str(len(kwargs))) + + driver_type: DriverType = 0 + if isinstance(kwargs.get("driverType"), DriverType): + driver_type = DriverType(kwargs.get("driverType")) + elif isinstance(kwargs.get("driverType"), str): + driver_type = DriverType(str(kwargs.get("driverType"))) else: - raise PlcRuntimeException("Argument 0 expected to be of type DriverType or a string which is parseable but was " + args[0].getClass().getName()) + raise PlcRuntimeException("Argument 0 expected to be of type DriverType or a string which is parseable but was " + kwargs.get("driverType").getClass().getName()) response: bool = False - if isinstance(args[1], bool): - response = bool(args[1]) - elif isinstance(args[1], str): - response = bool(str(args[1])) + if isinstance(kwargs.get("response"), bool): + response = bool(kwargs.get("response")) + elif isinstance(kwargs.get("response"), str): + response = bool(str(kwargs.get("response"))) else: - raise PlcRuntimeException("Argument 1 expected to be of type bool or a string which is parseable but was " + args[1].getClass().getName()) + raise PlcRuntimeException("Argument 1 expected to be of type bool or a string which is parseable but was " + kwargs.get("response").getClass().getName()) - return self.static_parse_context(read_buffer, driverType, response) + return ModbusADU.static_parse_context(read_buffer, driver_type, response) @staticmethod @@ -100,17 +100,20 @@ def static_parse_context(read_buffer: ReadBuffer, driver_type: DriverType, respo # Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) builder: ModbusADUBuilder = None - if EvaluationHelper.equals( driverType, DriverType.get_modbu_s__tcp() ): + from plc4py.protocols.modbus.readwrite.ModbusTcpADU import ModbusTcpADU + if driver_type == DriverType.MODBUS_TCP : - builder = ModbusTcpADU.staticParseBuilder(read_buffer, driverType, response) - if EvaluationHelper.equals( driverType, DriverType.get_modbu_s__rtu() ): + builder = ModbusTcpADU.static_parse_builder(read_buffer, driver_type, response) + from plc4py.protocols.modbus.readwrite.ModbusRtuADU import ModbusRtuADU + if driver_type == DriverType.MODBUS_RTU : - builder = ModbusRtuADU.staticParseBuilder(read_buffer, driverType, response) - if EvaluationHelper.equals( driverType, DriverType.get_modbu_s__ascii() ): + builder = ModbusRtuADU.static_parse_builder(read_buffer, driver_type, response) + from plc4py.protocols.modbus.readwrite.ModbusAsciiADU import ModbusAsciiADU + if driver_type == DriverType.MODBUS_ASCII : - builder = ModbusAsciiADU.staticParseBuilder(read_buffer, driverType, response) + builder = ModbusAsciiADU.static_parse_builder(read_buffer, driver_type, response) if builder is None: - raise ParseException("Unsupported case for discriminated type"+" parameters ["+"driverType="+driverType+"]") + raise ParseException("Unsupported case for discriminated type"+" parameters ["+"driverType="+str(driver_type)+"]") read_buffer.pop_context("ModbusADU") @@ -133,13 +136,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" class ModbusADUBuilder: def build(self, response: bool ) -> ModbusADU: diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusAsciiADU.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusAsciiADU.py index 17b148c4d23..569506a6cd0 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusAsciiADU.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusAsciiADU.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus import StaticHelper from plc4py.protocols.modbus.readwrite.DriverType import DriverType @@ -27,10 +29,11 @@ from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from plc4py.utils.GenericTypes import ByteOrder import math @dataclass -class ModbusAsciiADU(PlcMessage,ModbusADU): +class ModbusAsciiADU(ModbusADU): address: int pdu: ModbusPDU # Arguments. @@ -39,10 +42,6 @@ class ModbusAsciiADU(PlcMessage,ModbusADU): driver_type: DriverType = DriverType.MODBUS_ASCII - def __post_init__(self): - super().__init__( self.response ) - - def serialize_modbus_adu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusAsciiADU") @@ -54,23 +53,23 @@ def serialize_modbus_adu_child(self, write_buffer: WriteBuffer): write_buffer.write_serializable(self.pdu, logical_name="pdu") # Checksum Field (checksum) (Calculated) - write_buffer.write_unsigned_byte(int(StaticHelper.ascii_lrc_check(self.address, self.pdu)), logical_name="crc") + write_buffer.write_unsigned_byte(int(StaticHelper.ascii_lrc_check(address, pdu)), logical_name="crc") write_buffer.pop_context("ModbusAsciiADU") def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusAsciiADU = self # Simple field (address) length_in_bits += 8 # Simple field (pdu) - length_in_bits += self.pdu.get_length_in_bits() + length_in_bits += self.pdu.length_in_bits() # Checksum Field (checksum) length_in_bits += 8 @@ -82,11 +81,11 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, driver_type: DriverType, response: bool): read_buffer.push_context("ModbusAsciiADU") - self.address= read_simple_field("address", read_unsigned_short, WithOption.WithByteOrder(get_bi_g__endian())) + address: int = read_buffer.read_unsigned_short(logical_name="address", byte_order=ByteOrder.BIG_ENDIAN) - self.pdu= read_simple_field("pdu", DataReaderComplexDefault(ModbusPDU.static_parse(read_buffer, bool(response)), read_buffer), WithOption.WithByteOrder(get_bi_g__endian())) + pdu: ModbusPDU = read_buffer.read_complex(read_function=ModbusPDU.static_parse, logical_name="pdu", byte_order=ByteOrder.BIG_ENDIAN) - crc: int = read_checksum_field("crc", read_unsigned_short, (int) (ascii_lrc_check(self.address, self.pdu)), WithOption.WithByteOrder(get_bi_g__endian())) + crc: int = read_buffer.read_unsigned_short(logical_name="crc", byte_order=ByteOrder.BIG_ENDIAN) read_buffer.pop_context("ModbusAsciiADU") # Create the instance @@ -107,26 +106,23 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusAsciiADUBuilder(ModbusADUBuilder): address: int pdu: ModbusPDU - response: bool - - def __post_init__(self): - pass - def build(self,response: bool ) -> ModbusAsciiADU: - modbus_ascii_adu: ModbusAsciiADU = ModbusAsciiADU(self.address, self.pdu , response ) + def build(self,response: bool , ) -> ModbusAsciiADU: + modbus_ascii_adu: ModbusAsciiADU = ModbusAsciiADU(response , self.address, self.pdu ) return modbus_ascii_adu diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusConstants.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusConstants.py index 6ef27613155..42272ae44ac 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusConstants.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusConstants.py @@ -19,18 +19,16 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer import math @dataclass -class ModbusConstants(PlcMessage): - MODBUSTCPDEFAULTPORT: int = int(502) - - - def __post_init__(self): - super().__init__( ) +class ModbusConstants(): + MODBUS_TCP_DEFAULT_PORT: int = int(502) @@ -38,15 +36,15 @@ def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusConstants") # Const Field (modbusTcpDefaultPort) - write_buffer.write_unsigned_short(self.modbus_tcp_default_port.value, logical_name="modbusTcpDefaultPort") + write_buffer.write_unsigned_short(self.MODBUS_TCP_DEFAULT_PORT, logical_name="modbusTcpDefaultPort") write_buffer.pop_context("ModbusConstants") def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusConstants = self @@ -56,15 +54,16 @@ def get_length_in_bits(self) -> int: return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - return self.static_parse_context(read_buffer) + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + return ModbusConstants.static_parse_context(read_buffer) @staticmethod def static_parse_context(read_buffer: ReadBuffer): read_buffer.push_context("ModbusConstants") - self.modbus_tcp_default_port: int = read_const_field("modbusTcpDefaultPort", read_unsigned_int, ModbusConstants.MODBUSTCPDEFAULTPORT) + MODBUS_TCP_DEFAULT_PORT: int = read_buffer.read_unsigned_int(logical_name="modbusTcpDefaultPort") read_buffer.pop_context("ModbusConstants") # Create the instance @@ -86,13 +85,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) - - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) + + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusDeviceInformationObject.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusDeviceInformationObject.py index 36eeb1694d5..97d9fbdf234 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusDeviceInformationObject.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusDeviceInformationObject.py @@ -19,22 +19,21 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusDeviceInformationObject(PlcMessage): +class ModbusDeviceInformationObject(): object_id: int data: List[int] - def __post_init__(self): - super().__init__( ) - - def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusDeviceInformationObject") @@ -53,9 +52,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusDeviceInformationObject = self @@ -66,26 +65,27 @@ def get_length_in_bits(self) -> int: length_in_bits += 8 # Array field - if self.data != None: + if self.data is not None: length_in_bits += 8 * len(self.data) return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - return self.static_parse_context(read_buffer) + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + return ModbusDeviceInformationObject.static_parse_context(read_buffer) @staticmethod def static_parse_context(read_buffer: ReadBuffer): read_buffer.push_context("ModbusDeviceInformationObject") - self.object_id= read_simple_field("objectId", read_unsigned_short) + object_id: int = read_buffer.read_unsigned_short(logical_name="objectId") - object_length: int = read_implicit_field("objectLength", read_unsigned_short) + object_length: int = read_buffer.read_unsigned_short(logical_name="objectLength") - data: List[int] = read_buffer.read_byte_array("data", int(object_length)) + data: List[Any] = read_buffer.read_array_field(logical_name="data", read_function=read_buffer.read_byte, count=object_length) read_buffer.pop_context("ModbusDeviceInformationObject") # Create the instance @@ -107,13 +107,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) - - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) + + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDU.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDU.py index 375f8b0e760..372f064ef88 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDU.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDU.py @@ -21,7 +21,9 @@ from abc import ABC from abc import abstractmethod +from plc4py.api.exceptions.exceptions import ParseException from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer @@ -30,10 +32,6 @@ @dataclass class ModbusPDU(ABC, PlcMessage): - - def __post_init__(self): - super().__init__( ) - # Abstract accessors for discriminator values. @property @abstractmethod @@ -57,10 +55,10 @@ def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDU") # Discriminator Field (errorFlag) (Used as input to a switch field) - write_buffer.write_boolean(self.error_flag(), logical_name="errorFlag") + write_buffer.write_bit(self.error_flag, logical_name="errorFlag", bit_length=1, ) # Discriminator Field (functionFlag) (Used as input to a switch field) - write_buffer.write_unsigned_byte(self.function_flag(), logical_name="functionFlag") + write_buffer.write_unsigned_byte(self.function_flag, logical_name="functionFlag", bit_length=7, ) # Switch field (Serialize the sub-type) self.serialize_modbus_pdu_child(write_buffer) @@ -69,9 +67,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusPDU = self @@ -86,152 +84,193 @@ def get_length_in_bits(self) -> int: return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - if args is None: + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + + if kwargs is None: raise PlcRuntimeException("Wrong number of arguments, expected 1, but got None") - elif args.length != 1: - raise PlcRuntimeException("Wrong number of arguments, expected 1, but got " + str(len(args))) + elif len(kwargs) == 1: + raise PlcRuntimeException("Wrong number of arguments, expected 1, but got " + str(len(kwargs))) response: bool = False - if isinstance(args[0], bool): - response = bool(args[0]) - elif isinstance(args[0], str): - response = bool(str(args[0])) + if isinstance(kwargs.get("response"), bool): + response = bool(kwargs.get("response")) + elif isinstance(kwargs.get("response"), str): + response = bool(str(kwargs.get("response"))) else: - raise PlcRuntimeException("Argument 0 expected to be of type bool or a string which is parseable but was " + args[0].getClass().getName()) + raise PlcRuntimeException("Argument 0 expected to be of type bool or a string which is parseable but was " + kwargs.get("response").getClass().getName()) - return self.static_parse_context(read_buffer, response) + return ModbusPDU.static_parse_context(read_buffer, response) @staticmethod def static_parse_context(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDU") - error_flag: bool = read_discriminator_field("errorFlag", read_bit) + error_flag: bool = read_buffer.read_bit(logical_name="errorFlag") - function_flag: int = read_discriminator_field("functionFlag", read_unsigned_short) + function_flag: int = read_buffer.read_unsigned_short(logical_name="functionFlag") # Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) builder: ModbusPDUBuilder = None - if EvaluationHelper.equals( errorFlag, bool(True) ): + from plc4py.protocols.modbus.readwrite.ModbusPDUError import ModbusPDUError + if error_flag == bool(True) : - builder = ModbusPDUError.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x02) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUError.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadDiscreteInputsRequest import ModbusPDUReadDiscreteInputsRequest + if error_flag == bool(False) and function_flag == int(0x02) and response == bool(False) : - builder = ModbusPDUReadDiscreteInputsRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x02) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadDiscreteInputsRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadDiscreteInputsResponse import ModbusPDUReadDiscreteInputsResponse + if error_flag == bool(False) and function_flag == int(0x02) and response == bool(True) : - builder = ModbusPDUReadDiscreteInputsResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x01) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadDiscreteInputsResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadCoilsRequest import ModbusPDUReadCoilsRequest + if error_flag == bool(False) and function_flag == int(0x01) and response == bool(False) : - builder = ModbusPDUReadCoilsRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x01) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadCoilsRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadCoilsResponse import ModbusPDUReadCoilsResponse + if error_flag == bool(False) and function_flag == int(0x01) and response == bool(True) : - builder = ModbusPDUReadCoilsResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x05) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadCoilsResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteSingleCoilRequest import ModbusPDUWriteSingleCoilRequest + if error_flag == bool(False) and function_flag == int(0x05) and response == bool(False) : - builder = ModbusPDUWriteSingleCoilRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x05) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUWriteSingleCoilRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteSingleCoilResponse import ModbusPDUWriteSingleCoilResponse + if error_flag == bool(False) and function_flag == int(0x05) and response == bool(True) : - builder = ModbusPDUWriteSingleCoilResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x0F) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUWriteSingleCoilResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteMultipleCoilsRequest import ModbusPDUWriteMultipleCoilsRequest + if error_flag == bool(False) and function_flag == int(0x0F) and response == bool(False) : - builder = ModbusPDUWriteMultipleCoilsRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x0F) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUWriteMultipleCoilsRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteMultipleCoilsResponse import ModbusPDUWriteMultipleCoilsResponse + if error_flag == bool(False) and function_flag == int(0x0F) and response == bool(True) : - builder = ModbusPDUWriteMultipleCoilsResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x04) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUWriteMultipleCoilsResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadInputRegistersRequest import ModbusPDUReadInputRegistersRequest + if error_flag == bool(False) and function_flag == int(0x04) and response == bool(False) : - builder = ModbusPDUReadInputRegistersRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x04) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadInputRegistersRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadInputRegistersResponse import ModbusPDUReadInputRegistersResponse + if error_flag == bool(False) and function_flag == int(0x04) and response == bool(True) : - builder = ModbusPDUReadInputRegistersResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x03) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadInputRegistersResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadHoldingRegistersRequest import ModbusPDUReadHoldingRegistersRequest + if error_flag == bool(False) and function_flag == int(0x03) and response == bool(False) : - builder = ModbusPDUReadHoldingRegistersRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x03) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadHoldingRegistersRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadHoldingRegistersResponse import ModbusPDUReadHoldingRegistersResponse + if error_flag == bool(False) and function_flag == int(0x03) and response == bool(True) : - builder = ModbusPDUReadHoldingRegistersResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x06) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadHoldingRegistersResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteSingleRegisterRequest import ModbusPDUWriteSingleRegisterRequest + if error_flag == bool(False) and function_flag == int(0x06) and response == bool(False) : - builder = ModbusPDUWriteSingleRegisterRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x06) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUWriteSingleRegisterRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteSingleRegisterResponse import ModbusPDUWriteSingleRegisterResponse + if error_flag == bool(False) and function_flag == int(0x06) and response == bool(True) : - builder = ModbusPDUWriteSingleRegisterResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x10) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUWriteSingleRegisterResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteMultipleHoldingRegistersRequest import ModbusPDUWriteMultipleHoldingRegistersRequest + if error_flag == bool(False) and function_flag == int(0x10) and response == bool(False) : - builder = ModbusPDUWriteMultipleHoldingRegistersRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x10) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUWriteMultipleHoldingRegistersRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteMultipleHoldingRegistersResponse import ModbusPDUWriteMultipleHoldingRegistersResponse + if error_flag == bool(False) and function_flag == int(0x10) and response == bool(True) : - builder = ModbusPDUWriteMultipleHoldingRegistersResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x17) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUWriteMultipleHoldingRegistersResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadWriteMultipleHoldingRegistersRequest import ModbusPDUReadWriteMultipleHoldingRegistersRequest + if error_flag == bool(False) and function_flag == int(0x17) and response == bool(False) : - builder = ModbusPDUReadWriteMultipleHoldingRegistersRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x17) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadWriteMultipleHoldingRegistersRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadWriteMultipleHoldingRegistersResponse import ModbusPDUReadWriteMultipleHoldingRegistersResponse + if error_flag == bool(False) and function_flag == int(0x17) and response == bool(True) : - builder = ModbusPDUReadWriteMultipleHoldingRegistersResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x16) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadWriteMultipleHoldingRegistersResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUMaskWriteHoldingRegisterRequest import ModbusPDUMaskWriteHoldingRegisterRequest + if error_flag == bool(False) and function_flag == int(0x16) and response == bool(False) : - builder = ModbusPDUMaskWriteHoldingRegisterRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x16) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUMaskWriteHoldingRegisterRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUMaskWriteHoldingRegisterResponse import ModbusPDUMaskWriteHoldingRegisterResponse + if error_flag == bool(False) and function_flag == int(0x16) and response == bool(True) : - builder = ModbusPDUMaskWriteHoldingRegisterResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x18) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUMaskWriteHoldingRegisterResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadFifoQueueRequest import ModbusPDUReadFifoQueueRequest + if error_flag == bool(False) and function_flag == int(0x18) and response == bool(False) : - builder = ModbusPDUReadFifoQueueRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x18) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadFifoQueueRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadFifoQueueResponse import ModbusPDUReadFifoQueueResponse + if error_flag == bool(False) and function_flag == int(0x18) and response == bool(True) : - builder = ModbusPDUReadFifoQueueResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x14) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadFifoQueueResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadFileRecordRequest import ModbusPDUReadFileRecordRequest + if error_flag == bool(False) and function_flag == int(0x14) and response == bool(False) : - builder = ModbusPDUReadFileRecordRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x14) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadFileRecordRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadFileRecordResponse import ModbusPDUReadFileRecordResponse + if error_flag == bool(False) and function_flag == int(0x14) and response == bool(True) : - builder = ModbusPDUReadFileRecordResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x15) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadFileRecordResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteFileRecordRequest import ModbusPDUWriteFileRecordRequest + if error_flag == bool(False) and function_flag == int(0x15) and response == bool(False) : - builder = ModbusPDUWriteFileRecordRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x15) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUWriteFileRecordRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUWriteFileRecordResponse import ModbusPDUWriteFileRecordResponse + if error_flag == bool(False) and function_flag == int(0x15) and response == bool(True) : - builder = ModbusPDUWriteFileRecordResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x07) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUWriteFileRecordResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadExceptionStatusRequest import ModbusPDUReadExceptionStatusRequest + if error_flag == bool(False) and function_flag == int(0x07) and response == bool(False) : - builder = ModbusPDUReadExceptionStatusRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x07) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadExceptionStatusRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadExceptionStatusResponse import ModbusPDUReadExceptionStatusResponse + if error_flag == bool(False) and function_flag == int(0x07) and response == bool(True) : - builder = ModbusPDUReadExceptionStatusResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x08) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReadExceptionStatusResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUDiagnosticRequest import ModbusPDUDiagnosticRequest + if error_flag == bool(False) and function_flag == int(0x08) and response == bool(False) : - builder = ModbusPDUDiagnosticRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x08) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUDiagnosticRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUDiagnosticResponse import ModbusPDUDiagnosticResponse + if error_flag == bool(False) and function_flag == int(0x08) and response == bool(True) : - builder = ModbusPDUDiagnosticResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x0B) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUDiagnosticResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUGetComEventCounterRequest import ModbusPDUGetComEventCounterRequest + if error_flag == bool(False) and function_flag == int(0x0B) and response == bool(False) : - builder = ModbusPDUGetComEventCounterRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x0B) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUGetComEventCounterRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUGetComEventCounterResponse import ModbusPDUGetComEventCounterResponse + if error_flag == bool(False) and function_flag == int(0x0B) and response == bool(True) : - builder = ModbusPDUGetComEventCounterResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x0C) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUGetComEventCounterResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUGetComEventLogRequest import ModbusPDUGetComEventLogRequest + if error_flag == bool(False) and function_flag == int(0x0C) and response == bool(False) : - builder = ModbusPDUGetComEventLogRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x0C) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUGetComEventLogRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUGetComEventLogResponse import ModbusPDUGetComEventLogResponse + if error_flag == bool(False) and function_flag == int(0x0C) and response == bool(True) : - builder = ModbusPDUGetComEventLogResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x11) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUGetComEventLogResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReportServerIdRequest import ModbusPDUReportServerIdRequest + if error_flag == bool(False) and function_flag == int(0x11) and response == bool(False) : - builder = ModbusPDUReportServerIdRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x11) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReportServerIdRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReportServerIdResponse import ModbusPDUReportServerIdResponse + if error_flag == bool(False) and function_flag == int(0x11) and response == bool(True) : - builder = ModbusPDUReportServerIdResponse.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x2B) ) and EvaluationHelper.equals( response, bool(False) ): + builder = ModbusPDUReportServerIdResponse.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadDeviceIdentificationRequest import ModbusPDUReadDeviceIdentificationRequest + if error_flag == bool(False) and function_flag == int(0x2B) and response == bool(False) : - builder = ModbusPDUReadDeviceIdentificationRequest.staticParseBuilder(read_buffer, response) - if EvaluationHelper.equals( errorFlag, bool(False) ) and EvaluationHelper.equals( functionFlag, int(0x2B) ) and EvaluationHelper.equals( response, bool(True) ): + builder = ModbusPDUReadDeviceIdentificationRequest.static_parse_builder(read_buffer, response) + from plc4py.protocols.modbus.readwrite.ModbusPDUReadDeviceIdentificationResponse import ModbusPDUReadDeviceIdentificationResponse + if error_flag == bool(False) and function_flag == int(0x2B) and response == bool(True) : - builder = ModbusPDUReadDeviceIdentificationResponse.staticParseBuilder(read_buffer, response) + builder = ModbusPDUReadDeviceIdentificationResponse.static_parse_builder(read_buffer, response) if builder is None: - raise ParseException("Unsupported case for discriminated type"+" parameters ["+"errorFlag="+errorFlag+" "+"functionFlag="+functionFlag+" "+"response="+response+"]") + raise ParseException("Unsupported case for discriminated type"+" parameters ["+"errorFlag="+str(error_flag)+" "+"functionFlag="+str(function_flag)+" "+"response="+str(response)+"]") read_buffer.pop_context("ModbusPDU") @@ -254,13 +293,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" class ModbusPDUBuilder: def build(self, ) -> ModbusPDU: diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticRequest.py index 71d7ae1d876..3b26b0ce19e 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUDiagnosticRequest(PlcMessage,ModbusPDU): +class ModbusPDUDiagnosticRequest(ModbusPDU): sub_function: int data: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUDiagnosticRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUDiagnosticRequest") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUDiagnosticRequest = self # Simple field (subFunction) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUDiagnosticRequest") - self.sub_function= read_simple_field("subFunction", read_unsigned_int) + sub_function: int = read_buffer.read_unsigned_int(logical_name="subFunction") - self.data= read_simple_field("data", read_unsigned_int) + data: int = read_buffer.read_unsigned_int(logical_name="data") read_buffer.pop_context("ModbusPDUDiagnosticRequest") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUDiagnosticRequestBuilder(ModbusPDUBuilder): - subFunction: int + sub_function: int data: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUDiagnosticRequest: modbus_pdu_diagnostic_request: ModbusPDUDiagnosticRequest = ModbusPDUDiagnosticRequest(self.sub_function, self.data ) return modbus_pdu_diagnostic_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticResponse.py index 536c0f7e613..deb96d15cba 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUDiagnosticResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUDiagnosticResponse(PlcMessage,ModbusPDU): +class ModbusPDUDiagnosticResponse(ModbusPDU): sub_function: int data: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUDiagnosticResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUDiagnosticResponse") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUDiagnosticResponse = self # Simple field (subFunction) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUDiagnosticResponse") - self.sub_function= read_simple_field("subFunction", read_unsigned_int) + sub_function: int = read_buffer.read_unsigned_int(logical_name="subFunction") - self.data= read_simple_field("data", read_unsigned_int) + data: int = read_buffer.read_unsigned_int(logical_name="data") read_buffer.pop_context("ModbusPDUDiagnosticResponse") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUDiagnosticResponseBuilder(ModbusPDUBuilder): - subFunction: int + sub_function: int data: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUDiagnosticResponse: modbus_pdu_diagnostic_response: ModbusPDUDiagnosticResponse = ModbusPDUDiagnosticResponse(self.sub_function, self.data ) return modbus_pdu_diagnostic_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUError.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUError.py index bc5b34a0629..b6ff6f57eda 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUError.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUError.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusErrorCode import ModbusErrorCode from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU @@ -28,7 +30,7 @@ import math @dataclass -class ModbusPDUError(PlcMessage,ModbusPDU): +class ModbusPDUError(ModbusPDU): exception_code: ModbusErrorCode # Accessors for discriminator values. error_flag: bool = True @@ -36,26 +38,22 @@ class ModbusPDUError(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUError") # Simple Field (exceptionCode) - write_buffer.DataWriterEnumDefault(ModbusErrorCode.value, ModbusErrorCode.name, write_unsigned_byte)(self.exception_code, logical_name="exceptionCode") + write_buffer.write_unsigned_byte(self.exception_code, logical_name="exceptionCode") write_buffer.pop_context("ModbusPDUError") def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUError = self # Simple field (exceptionCode) @@ -68,7 +66,7 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUError") - self.exception_code= read_enum_field("exceptionCode", "ModbusErrorCode", DataReaderEnumDefault(ModbusErrorCode.enumForValue, read_unsigned_short)) + exception_code: ModbusErrorCode = read_buffer.read_complex(read_function=ModbusErrorCode,logical_name="exceptionCode") read_buffer.pop_context("ModbusPDUError") # Create the instance @@ -89,21 +87,19 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUErrorBuilder(ModbusPDUBuilder): - exceptionCode: ModbusErrorCode - - def __post_init__(self): - pass + exception_code: ModbusErrorCode def build(self,) -> ModbusPDUError: modbus_pdu_error: ModbusPDUError = ModbusPDUError(self.exception_code ) diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterRequest.py index fa168e67756..f476162525d 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,17 +29,13 @@ import math @dataclass -class ModbusPDUGetComEventCounterRequest(PlcMessage,ModbusPDU): +class ModbusPDUGetComEventCounterRequest(ModbusPDU): # Accessors for discriminator values. error_flag: bool = False function_flag: int = 0x0B response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUGetComEventCounterRequest") @@ -46,10 +44,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUGetComEventCounterRequest = self return length_in_bits @@ -78,21 +76,19 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUGetComEventCounterRequestBuilder(ModbusPDUBuilder): - def __post_init__(self): - pass - def build(self,) -> ModbusPDUGetComEventCounterRequest: modbus_pdu_get_com_event_counter_request: ModbusPDUGetComEventCounterRequest = ModbusPDUGetComEventCounterRequest() return modbus_pdu_get_com_event_counter_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterResponse.py index 2f936dfc8b1..33624979146 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventCounterResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUGetComEventCounterResponse(PlcMessage,ModbusPDU): +class ModbusPDUGetComEventCounterResponse(ModbusPDU): status: int event_count: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUGetComEventCounterResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUGetComEventCounterResponse") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUGetComEventCounterResponse = self # Simple field (status) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUGetComEventCounterResponse") - self.status= read_simple_field("status", read_unsigned_int) + status: int = read_buffer.read_unsigned_int(logical_name="status") - self.event_count= read_simple_field("eventCount", read_unsigned_int) + event_count: int = read_buffer.read_unsigned_int(logical_name="eventCount") read_buffer.pop_context("ModbusPDUGetComEventCounterResponse") # Create the instance @@ -96,22 +94,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUGetComEventCounterResponseBuilder(ModbusPDUBuilder): status: int - eventCount: int - - def __post_init__(self): - pass + event_count: int def build(self,) -> ModbusPDUGetComEventCounterResponse: modbus_pdu_get_com_event_counter_response: ModbusPDUGetComEventCounterResponse = ModbusPDUGetComEventCounterResponse(self.status, self.event_count ) diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogRequest.py index 48f054e73c9..740e76fff1f 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,17 +29,13 @@ import math @dataclass -class ModbusPDUGetComEventLogRequest(PlcMessage,ModbusPDU): +class ModbusPDUGetComEventLogRequest(ModbusPDU): # Accessors for discriminator values. error_flag: bool = False function_flag: int = 0x0C response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUGetComEventLogRequest") @@ -46,10 +44,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUGetComEventLogRequest = self return length_in_bits @@ -78,21 +76,19 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUGetComEventLogRequestBuilder(ModbusPDUBuilder): - def __post_init__(self): - pass - def build(self,) -> ModbusPDUGetComEventLogRequest: modbus_pdu_get_com_event_log_request: ModbusPDUGetComEventLogRequest = ModbusPDUGetComEventLogRequest() return modbus_pdu_get_com_event_log_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogResponse.py index 82487455f94..665ecb9526e 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUGetComEventLogResponse.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUGetComEventLogResponse(PlcMessage,ModbusPDU): +class ModbusPDUGetComEventLogResponse(ModbusPDU): status: int event_count: int message_count: int @@ -39,10 +42,6 @@ class ModbusPDUGetComEventLogResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUGetComEventLogResponse") @@ -67,10 +66,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUGetComEventLogResponse = self # Implicit Field (byteCount) @@ -86,7 +85,7 @@ def get_length_in_bits(self) -> int: length_in_bits += 16 # Array field - if self.events != None: + if self.events is not None: length_in_bits += 8 * len(self.events) @@ -97,15 +96,15 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUGetComEventLogResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - self.status= read_simple_field("status", read_unsigned_int) + status: int = read_buffer.read_unsigned_int(logical_name="status") - self.event_count= read_simple_field("eventCount", read_unsigned_int) + event_count: int = read_buffer.read_unsigned_int(logical_name="eventCount") - self.message_count= read_simple_field("messageCount", read_unsigned_int) + message_count: int = read_buffer.read_unsigned_int(logical_name="messageCount") - events: List[int] = read_buffer.read_byte_array("events", int(byte_count- int(6))) + events: List[Any] = read_buffer.read_array_field(logical_name="events", read_function=read_buffer.read_byte, count=byte_count- int(6)) read_buffer.pop_context("ModbusPDUGetComEventLogResponse") # Create the instance @@ -126,25 +125,23 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUGetComEventLogResponseBuilder(ModbusPDUBuilder): status: int - eventCount: int - messageCount: int + event_count: int + message_count: int events: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUGetComEventLogResponse: modbus_pdu_get_com_event_log_response: ModbusPDUGetComEventLogResponse = ModbusPDUGetComEventLogResponse(self.status, self.event_count, self.message_count, self.events ) return modbus_pdu_get_com_event_log_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterRequest.py index 5c6b647be53..f1b5ba64e74 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUMaskWriteHoldingRegisterRequest(PlcMessage,ModbusPDU): +class ModbusPDUMaskWriteHoldingRegisterRequest(ModbusPDU): reference_address: int and_mask: int or_mask: int @@ -37,10 +39,6 @@ class ModbusPDUMaskWriteHoldingRegisterRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUMaskWriteHoldingRegisterRequest") @@ -58,10 +56,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUMaskWriteHoldingRegisterRequest = self # Simple field (referenceAddress) @@ -80,11 +78,11 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUMaskWriteHoldingRegisterRequest") - self.reference_address= read_simple_field("referenceAddress", read_unsigned_int) + reference_address: int = read_buffer.read_unsigned_int(logical_name="referenceAddress") - self.and_mask= read_simple_field("andMask", read_unsigned_int) + and_mask: int = read_buffer.read_unsigned_int(logical_name="andMask") - self.or_mask= read_simple_field("orMask", read_unsigned_int) + or_mask: int = read_buffer.read_unsigned_int(logical_name="orMask") read_buffer.pop_context("ModbusPDUMaskWriteHoldingRegisterRequest") # Create the instance @@ -105,23 +103,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUMaskWriteHoldingRegisterRequestBuilder(ModbusPDUBuilder): - referenceAddress: int - andMask: int - orMask: int - - def __post_init__(self): - pass + reference_address: int + and_mask: int + or_mask: int def build(self,) -> ModbusPDUMaskWriteHoldingRegisterRequest: modbus_pdu_mask_write_holding_register_request: ModbusPDUMaskWriteHoldingRegisterRequest = ModbusPDUMaskWriteHoldingRegisterRequest(self.reference_address, self.and_mask, self.or_mask ) diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterResponse.py index bf63c1ae25a..42bc6c66f84 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUMaskWriteHoldingRegisterResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUMaskWriteHoldingRegisterResponse(PlcMessage,ModbusPDU): +class ModbusPDUMaskWriteHoldingRegisterResponse(ModbusPDU): reference_address: int and_mask: int or_mask: int @@ -37,10 +39,6 @@ class ModbusPDUMaskWriteHoldingRegisterResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUMaskWriteHoldingRegisterResponse") @@ -58,10 +56,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUMaskWriteHoldingRegisterResponse = self # Simple field (referenceAddress) @@ -80,11 +78,11 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUMaskWriteHoldingRegisterResponse") - self.reference_address= read_simple_field("referenceAddress", read_unsigned_int) + reference_address: int = read_buffer.read_unsigned_int(logical_name="referenceAddress") - self.and_mask= read_simple_field("andMask", read_unsigned_int) + and_mask: int = read_buffer.read_unsigned_int(logical_name="andMask") - self.or_mask= read_simple_field("orMask", read_unsigned_int) + or_mask: int = read_buffer.read_unsigned_int(logical_name="orMask") read_buffer.pop_context("ModbusPDUMaskWriteHoldingRegisterResponse") # Create the instance @@ -105,23 +103,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUMaskWriteHoldingRegisterResponseBuilder(ModbusPDUBuilder): - referenceAddress: int - andMask: int - orMask: int - - def __post_init__(self): - pass + reference_address: int + and_mask: int + or_mask: int def build(self,) -> ModbusPDUMaskWriteHoldingRegisterResponse: modbus_pdu_mask_write_holding_register_response: ModbusPDUMaskWriteHoldingRegisterResponse = ModbusPDUMaskWriteHoldingRegisterResponse(self.reference_address, self.and_mask, self.or_mask ) diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsRequest.py index fe142c9ba12..41ce04381ca 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUReadCoilsRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadCoilsRequest(ModbusPDU): starting_address: int quantity: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUReadCoilsRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadCoilsRequest") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadCoilsRequest = self # Simple field (startingAddress) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadCoilsRequest") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") read_buffer.pop_context("ModbusPDUReadCoilsRequest") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadCoilsRequestBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadCoilsRequest: modbus_pdu_read_coils_request: ModbusPDUReadCoilsRequest = ModbusPDUReadCoilsRequest(self.starting_address, self.quantity ) return modbus_pdu_read_coils_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsResponse.py index ebc242fa050..13b87fd2b80 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadCoilsResponse.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadCoilsResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadCoilsResponse(ModbusPDU): value: List[int] # Accessors for discriminator values. error_flag: bool = False @@ -36,10 +39,6 @@ class ModbusPDUReadCoilsResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadCoilsResponse") @@ -55,17 +54,17 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadCoilsResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -76,9 +75,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadCoilsResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUReadCoilsResponse") # Create the instance @@ -99,22 +98,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadCoilsResponseBuilder(ModbusPDUBuilder): value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadCoilsResponse: modbus_pdu_read_coils_response: ModbusPDUReadCoilsResponse = ModbusPDUReadCoilsResponse(self.value ) return modbus_pdu_read_coils_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationRequest.py index aafec0182d9..abd0e397945 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusDeviceInformationLevel import ModbusDeviceInformationLevel from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU @@ -28,29 +30,25 @@ import math @dataclass -class ModbusPDUReadDeviceIdentificationRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadDeviceIdentificationRequest(ModbusPDU): level: ModbusDeviceInformationLevel object_id: int - MEITYPE: int = 0x0E + MEI_TYPE: int = 0x0E # Accessors for discriminator values. error_flag: bool = False function_flag: int = 0x2B response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadDeviceIdentificationRequest") # Const Field (meiType) - write_buffer.write_unsigned_byte(self.mei_type.value, logical_name="meiType") + write_buffer.write_unsigned_byte(self.MEI_TYPE, logical_name="meiType") # Simple Field (level) - write_buffer.DataWriterEnumDefault(ModbusDeviceInformationLevel.value, ModbusDeviceInformationLevel.name, write_unsigned_byte)(self.level, logical_name="level") + write_buffer.write_unsigned_byte(self.level, logical_name="level") # Simple Field (objectId) @@ -60,10 +58,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadDeviceIdentificationRequest = self # Const Field (meiType) @@ -82,11 +80,11 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadDeviceIdentificationRequest") - self.mei_type: int = read_const_field("meiType", read_unsigned_short, ModbusPDUReadDeviceIdentificationRequest.MEITYPE) + MEI_TYPE: int = read_buffer.read_unsigned_short(logical_name="meiType") - self.level= read_enum_field("level", "ModbusDeviceInformationLevel", DataReaderEnumDefault(ModbusDeviceInformationLevel.enumForValue, read_unsigned_short)) + level: ModbusDeviceInformationLevel = read_buffer.read_complex(read_function=ModbusDeviceInformationLevel,logical_name="level") - self.object_id= read_simple_field("objectId", read_unsigned_short) + object_id: int = read_buffer.read_unsigned_short(logical_name="objectId") read_buffer.pop_context("ModbusPDUReadDeviceIdentificationRequest") # Create the instance @@ -107,22 +105,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadDeviceIdentificationRequestBuilder(ModbusPDUBuilder): level: ModbusDeviceInformationLevel - objectId: int - - def __post_init__(self): - pass + object_id: int def build(self,) -> ModbusPDUReadDeviceIdentificationRequest: modbus_pdu_read_device_identification_request: ModbusPDUReadDeviceIdentificationRequest = ModbusPDUReadDeviceIdentificationRequest(self.level, self.object_id ) diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationResponse.py index 3b95753ad03..ca84d1acd60 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDeviceIdentificationResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusDeviceInformationConformityLevel import ModbusDeviceInformationConformityLevel from plc4py.protocols.modbus.readwrite.ModbusDeviceInformationLevel import ModbusDeviceInformationLevel @@ -33,44 +35,40 @@ import math @dataclass -class ModbusPDUReadDeviceIdentificationResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadDeviceIdentificationResponse(ModbusPDU): level: ModbusDeviceInformationLevel individual_access: bool conformity_level: ModbusDeviceInformationConformityLevel more_follows: ModbusDeviceInformationMoreFollows next_object_id: int objects: List[ModbusDeviceInformationObject] - MEITYPE: int = 0x0E + MEI_TYPE: int = 0x0E # Accessors for discriminator values. error_flag: bool = False function_flag: int = 0x2B response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadDeviceIdentificationResponse") # Const Field (meiType) - write_buffer.write_unsigned_byte(self.mei_type.value, logical_name="meiType") + write_buffer.write_unsigned_byte(self.MEI_TYPE, logical_name="meiType") # Simple Field (level) - write_buffer.DataWriterEnumDefault(ModbusDeviceInformationLevel.value, ModbusDeviceInformationLevel.name, write_unsigned_byte)(self.level, logical_name="level") + write_buffer.write_unsigned_byte(self.level, logical_name="level") # Simple Field (individualAccess) - write_buffer.write_boolean(self.individual_access, logical_name="individualAccess") + write_buffer.write_bit(self.individual_access, logical_name="individualAccess") # Simple Field (conformityLevel) - write_buffer.DataWriterEnumDefault(ModbusDeviceInformationConformityLevel.value, ModbusDeviceInformationConformityLevel.name, write_unsigned_byte)(self.conformity_level, logical_name="conformityLevel") + write_buffer.write_unsigned_byte(self.conformity_level, logical_name="conformityLevel") # Simple Field (moreFollows) - write_buffer.DataWriterEnumDefault(ModbusDeviceInformationMoreFollows.value, ModbusDeviceInformationMoreFollows.name, write_unsigned_byte)(self.more_follows, logical_name="moreFollows") + write_buffer.write_unsigned_byte(self.more_follows, logical_name="moreFollows") # Simple Field (nextObjectId) @@ -87,10 +85,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadDeviceIdentificationResponse = self # Const Field (meiType) @@ -115,11 +113,9 @@ def get_length_in_bits(self) -> int: length_in_bits += 8 # Array field - if self.objects != None: - i: int = 0 + if self.objects is not None: for element in self.objects: - last: bool = ++i >= len(self.objects) - length_in_bits += element.get_length_in_bits() + length_in_bits += element.length_in_bits() @@ -130,21 +126,21 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadDeviceIdentificationResponse") - self.mei_type: int = read_const_field("meiType", read_unsigned_short, ModbusPDUReadDeviceIdentificationResponse.MEITYPE) + MEI_TYPE: int = read_buffer.read_unsigned_short(logical_name="meiType") - self.level= read_enum_field("level", "ModbusDeviceInformationLevel", DataReaderEnumDefault(ModbusDeviceInformationLevel.enumForValue, read_unsigned_short)) + level: ModbusDeviceInformationLevel = read_buffer.read_complex(read_function=ModbusDeviceInformationLevel,logical_name="level") - self.individual_access= read_simple_field("individualAccess", read_bit) + individual_access: bool = read_buffer.read_bit(logical_name="individualAccess") - self.conformity_level= read_enum_field("conformityLevel", "ModbusDeviceInformationConformityLevel", DataReaderEnumDefault(ModbusDeviceInformationConformityLevel.enumForValue, read_unsigned_short)) + conformity_level: ModbusDeviceInformationConformityLevel = read_buffer.read_complex(read_function=ModbusDeviceInformationConformityLevel,logical_name="conformityLevel") - self.more_follows= read_enum_field("moreFollows", "ModbusDeviceInformationMoreFollows", DataReaderEnumDefault(ModbusDeviceInformationMoreFollows.enumForValue, read_unsigned_short)) + more_follows: ModbusDeviceInformationMoreFollows = read_buffer.read_complex(read_function=ModbusDeviceInformationMoreFollows,logical_name="moreFollows") - self.next_object_id= read_simple_field("nextObjectId", read_unsigned_short) + next_object_id: int = read_buffer.read_unsigned_short(logical_name="nextObjectId") - number_of_objects: int = read_implicit_field("numberOfObjects", read_unsigned_short) + number_of_objects: int = read_buffer.read_unsigned_short(logical_name="numberOfObjects") - objects: List[Any] = read_buffer.read_array_field("objects", read_buffer.DataReaderComplexDefault(ModbusDeviceInformationObject.static_parse(read_buffer), read_buffer), count=number_of_objects) + objects: List[Any] = read_buffer.read_array_field(logical_name="objects", read_function=ModbusDeviceInformationObject.static_parse, count=number_of_objects) read_buffer.pop_context("ModbusPDUReadDeviceIdentificationResponse") # Create the instance @@ -165,27 +161,25 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadDeviceIdentificationResponseBuilder(ModbusPDUBuilder): level: ModbusDeviceInformationLevel - individualAccess: bool - conformityLevel: ModbusDeviceInformationConformityLevel - moreFollows: ModbusDeviceInformationMoreFollows - nextObjectId: int + individual_access: bool + conformity_level: ModbusDeviceInformationConformityLevel + more_follows: ModbusDeviceInformationMoreFollows + next_object_id: int objects: List[ModbusDeviceInformationObject] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadDeviceIdentificationResponse: modbus_pdu_read_device_identification_response: ModbusPDUReadDeviceIdentificationResponse = ModbusPDUReadDeviceIdentificationResponse(self.level, self.individual_access, self.conformity_level, self.more_follows, self.next_object_id, self.objects ) return modbus_pdu_read_device_identification_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsRequest.py index af16e66183a..e99a150ab4c 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUReadDiscreteInputsRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadDiscreteInputsRequest(ModbusPDU): starting_address: int quantity: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUReadDiscreteInputsRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadDiscreteInputsRequest") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadDiscreteInputsRequest = self # Simple field (startingAddress) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadDiscreteInputsRequest") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") read_buffer.pop_context("ModbusPDUReadDiscreteInputsRequest") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadDiscreteInputsRequestBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadDiscreteInputsRequest: modbus_pdu_read_discrete_inputs_request: ModbusPDUReadDiscreteInputsRequest = ModbusPDUReadDiscreteInputsRequest(self.starting_address, self.quantity ) return modbus_pdu_read_discrete_inputs_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsResponse.py index cd4e14d8996..0ec1c7a7f50 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadDiscreteInputsResponse.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadDiscreteInputsResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadDiscreteInputsResponse(ModbusPDU): value: List[int] # Accessors for discriminator values. error_flag: bool = False @@ -36,10 +39,6 @@ class ModbusPDUReadDiscreteInputsResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadDiscreteInputsResponse") @@ -55,17 +54,17 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadDiscreteInputsResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -76,9 +75,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadDiscreteInputsResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUReadDiscreteInputsResponse") # Create the instance @@ -99,22 +98,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadDiscreteInputsResponseBuilder(ModbusPDUBuilder): value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadDiscreteInputsResponse: modbus_pdu_read_discrete_inputs_response: ModbusPDUReadDiscreteInputsResponse = ModbusPDUReadDiscreteInputsResponse(self.value ) return modbus_pdu_read_discrete_inputs_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusRequest.py index c4cdd4917bf..bb54d2a6345 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,17 +29,13 @@ import math @dataclass -class ModbusPDUReadExceptionStatusRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadExceptionStatusRequest(ModbusPDU): # Accessors for discriminator values. error_flag: bool = False function_flag: int = 0x07 response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadExceptionStatusRequest") @@ -46,10 +44,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadExceptionStatusRequest = self return length_in_bits @@ -78,21 +76,19 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadExceptionStatusRequestBuilder(ModbusPDUBuilder): - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadExceptionStatusRequest: modbus_pdu_read_exception_status_request: ModbusPDUReadExceptionStatusRequest = ModbusPDUReadExceptionStatusRequest() return modbus_pdu_read_exception_status_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusResponse.py index cacad0d619f..28190b5a3f2 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadExceptionStatusResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUReadExceptionStatusResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadExceptionStatusResponse(ModbusPDU): value: int # Accessors for discriminator values. error_flag: bool = False @@ -35,10 +37,6 @@ class ModbusPDUReadExceptionStatusResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadExceptionStatusResponse") @@ -50,10 +48,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadExceptionStatusResponse = self # Simple field (value) @@ -66,7 +64,7 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadExceptionStatusResponse") - self.value= read_simple_field("value", read_unsigned_short) + value: int = read_buffer.read_unsigned_short(logical_name="value") read_buffer.pop_context("ModbusPDUReadExceptionStatusResponse") # Create the instance @@ -87,22 +85,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadExceptionStatusResponseBuilder(ModbusPDUBuilder): value: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadExceptionStatusResponse: modbus_pdu_read_exception_status_response: ModbusPDUReadExceptionStatusResponse = ModbusPDUReadExceptionStatusResponse(self.value ) return modbus_pdu_read_exception_status_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueRequest.py index e0de508408a..91533f9786e 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUReadFifoQueueRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadFifoQueueRequest(ModbusPDU): fifo_pointer_address: int # Accessors for discriminator values. error_flag: bool = False @@ -35,10 +37,6 @@ class ModbusPDUReadFifoQueueRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadFifoQueueRequest") @@ -50,10 +48,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadFifoQueueRequest = self # Simple field (fifoPointerAddress) @@ -66,7 +64,7 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadFifoQueueRequest") - self.fifo_pointer_address= read_simple_field("fifoPointerAddress", read_unsigned_int) + fifo_pointer_address: int = read_buffer.read_unsigned_int(logical_name="fifoPointerAddress") read_buffer.pop_context("ModbusPDUReadFifoQueueRequest") # Create the instance @@ -87,21 +85,19 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadFifoQueueRequestBuilder(ModbusPDUBuilder): - fifoPointerAddress: int - - def __post_init__(self): - pass + fifo_pointer_address: int def build(self,) -> ModbusPDUReadFifoQueueRequest: modbus_pdu_read_fifo_queue_request: ModbusPDUReadFifoQueueRequest = ModbusPDUReadFifoQueueRequest(self.fifo_pointer_address ) diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueResponse.py index 98ff7a17fdd..fcdfcea19ed 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFifoQueueResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -29,7 +31,7 @@ import math @dataclass -class ModbusPDUReadFifoQueueResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadFifoQueueResponse(ModbusPDU): fifo_value: List[int] # Accessors for discriminator values. error_flag: bool = False @@ -37,10 +39,6 @@ class ModbusPDUReadFifoQueueResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadFifoQueueResponse") @@ -60,10 +58,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadFifoQueueResponse = self # Implicit Field (byteCount) @@ -73,7 +71,7 @@ def get_length_in_bits(self) -> int: length_in_bits += 16 # Array field - if self.fifo_value != None: + if self.fifo_value is not None: length_in_bits += 16 * len(self.fifo_value) @@ -84,11 +82,11 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadFifoQueueResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_int) + byte_count: int = read_buffer.read_unsigned_int(logical_name="byteCount") - fifo_count: int = read_implicit_field("fifoCount", read_unsigned_int) + fifo_count: int = read_buffer.read_unsigned_int(logical_name="fifoCount") - fifo_value: List[Any] = read_buffer.read_array_field("fifoValue", read_buffer.read_unsigned_int, count=fifo_count) + fifo_value: List[Any] = read_buffer.read_array_field(logical_name="fifoValue", read_function=read_buffer.read_unsigned_int, count=fifo_count) read_buffer.pop_context("ModbusPDUReadFifoQueueResponse") # Create the instance @@ -109,21 +107,19 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadFifoQueueResponseBuilder(ModbusPDUBuilder): - fifoValue: List[int] - - def __post_init__(self): - pass + fifo_value: List[int] def build(self,) -> ModbusPDUReadFifoQueueResponse: modbus_pdu_read_fifo_queue_response: ModbusPDUReadFifoQueueResponse = ModbusPDUReadFifoQueueResponse(self.fifo_value ) diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequest.py index 3e0a55b8bc3..84f9f991404 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -26,11 +28,12 @@ from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer from sys import getsizeof +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadFileRecordRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadFileRecordRequest(ModbusPDU): items: List[ModbusPDUReadFileRecordRequestItem] # Accessors for discriminator values. error_flag: bool = False @@ -38,10 +41,6 @@ class ModbusPDUReadFileRecordRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadFileRecordRequest") @@ -57,19 +56,19 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadFileRecordRequest = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.items != None: + if self.items is not None: for element in self.items: - length_in_bits += element.get_length_in_bits() + length_in_bits += element.length_in_bits() @@ -80,9 +79,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadFileRecordRequest") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - items: List[Any] = read_buffer.read_array_field("items", read_buffer.DataReaderComplexDefault(ModbusPDUReadFileRecordRequestItem.static_parse(read_buffer), read_buffer), length=byte_count) + items: List[Any] = read_buffer.read_array_field(logical_name="items", read_function=ModbusPDUReadFileRecordRequestItem.static_parse, length=byte_count) read_buffer.pop_context("ModbusPDUReadFileRecordRequest") # Create the instance @@ -103,22 +102,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadFileRecordRequestBuilder(ModbusPDUBuilder): items: List[ModbusPDUReadFileRecordRequestItem] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadFileRecordRequest: modbus_pdu_read_file_record_request: ModbusPDUReadFileRecordRequest = ModbusPDUReadFileRecordRequest(self.items ) return modbus_pdu_read_file_record_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequestItem.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequestItem.py index 0997bb356aa..378b6e11179 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequestItem.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordRequestItem.py @@ -19,23 +19,21 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer import math @dataclass -class ModbusPDUReadFileRecordRequestItem(PlcMessage): +class ModbusPDUReadFileRecordRequestItem(): reference_type: int file_number: int record_number: int record_length: int - def __post_init__(self): - super().__init__( ) - - def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadFileRecordRequestItem") @@ -56,9 +54,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusPDUReadFileRecordRequestItem = self @@ -77,21 +75,22 @@ def get_length_in_bits(self) -> int: return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - return self.static_parse_context(read_buffer) + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + return ModbusPDUReadFileRecordRequestItem.static_parse_context(read_buffer) @staticmethod def static_parse_context(read_buffer: ReadBuffer): read_buffer.push_context("ModbusPDUReadFileRecordRequestItem") - self.reference_type= read_simple_field("referenceType", read_unsigned_short) + reference_type: int = read_buffer.read_unsigned_short(logical_name="referenceType") - self.file_number= read_simple_field("fileNumber", read_unsigned_int) + file_number: int = read_buffer.read_unsigned_int(logical_name="fileNumber") - self.record_number= read_simple_field("recordNumber", read_unsigned_int) + record_number: int = read_buffer.read_unsigned_int(logical_name="recordNumber") - self.record_length= read_simple_field("recordLength", read_unsigned_int) + record_length: int = read_buffer.read_unsigned_int(logical_name="recordLength") read_buffer.pop_context("ModbusPDUReadFileRecordRequestItem") # Create the instance @@ -113,13 +112,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) - - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) + + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponse.py index ce2ce730468..e9672113a44 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -26,11 +28,12 @@ from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer from sys import getsizeof +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadFileRecordResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadFileRecordResponse(ModbusPDU): items: List[ModbusPDUReadFileRecordResponseItem] # Accessors for discriminator values. error_flag: bool = False @@ -38,10 +41,6 @@ class ModbusPDUReadFileRecordResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadFileRecordResponse") @@ -57,19 +56,19 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadFileRecordResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.items != None: + if self.items is not None: for element in self.items: - length_in_bits += element.get_length_in_bits() + length_in_bits += element.length_in_bits() @@ -80,9 +79,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadFileRecordResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - items: List[Any] = read_buffer.read_array_field("items", read_buffer.DataReaderComplexDefault(ModbusPDUReadFileRecordResponseItem.static_parse(read_buffer), read_buffer), length=byte_count) + items: List[Any] = read_buffer.read_array_field(logical_name="items", read_function=ModbusPDUReadFileRecordResponseItem.static_parse, length=byte_count) read_buffer.pop_context("ModbusPDUReadFileRecordResponse") # Create the instance @@ -103,22 +102,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadFileRecordResponseBuilder(ModbusPDUBuilder): items: List[ModbusPDUReadFileRecordResponseItem] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadFileRecordResponse: modbus_pdu_read_file_record_response: ModbusPDUReadFileRecordResponse = ModbusPDUReadFileRecordResponse(self.items ) return modbus_pdu_read_file_record_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponseItem.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponseItem.py index 9e2c5898732..941d9bf1ae8 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponseItem.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadFileRecordResponseItem.py @@ -19,22 +19,21 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadFileRecordResponseItem(PlcMessage): +class ModbusPDUReadFileRecordResponseItem(): reference_type: int data: List[int] - def __post_init__(self): - super().__init__( ) - - def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadFileRecordResponseItem") @@ -53,9 +52,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusPDUReadFileRecordResponseItem = self @@ -66,26 +65,27 @@ def get_length_in_bits(self) -> int: length_in_bits += 8 # Array field - if self.data != None: + if self.data is not None: length_in_bits += 8 * len(self.data) return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - return self.static_parse_context(read_buffer) + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + return ModbusPDUReadFileRecordResponseItem.static_parse_context(read_buffer) @staticmethod def static_parse_context(read_buffer: ReadBuffer): read_buffer.push_context("ModbusPDUReadFileRecordResponseItem") - data_length: int = read_implicit_field("dataLength", read_unsigned_short) + data_length: int = read_buffer.read_unsigned_short(logical_name="dataLength") - self.reference_type= read_simple_field("referenceType", read_unsigned_short) + reference_type: int = read_buffer.read_unsigned_short(logical_name="referenceType") - data: List[int] = read_buffer.read_byte_array("data", int(data_length- int(1))) + data: List[Any] = read_buffer.read_array_field(logical_name="data", read_function=read_buffer.read_byte, count=data_length- int(1)) read_buffer.pop_context("ModbusPDUReadFileRecordResponseItem") # Create the instance @@ -107,13 +107,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) - - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) + + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersRequest.py index 01b52c17fb0..acd17a1469a 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUReadHoldingRegistersRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadHoldingRegistersRequest(ModbusPDU): starting_address: int quantity: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUReadHoldingRegistersRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadHoldingRegistersRequest") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadHoldingRegistersRequest = self # Simple field (startingAddress) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadHoldingRegistersRequest") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") read_buffer.pop_context("ModbusPDUReadHoldingRegistersRequest") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadHoldingRegistersRequestBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadHoldingRegistersRequest: modbus_pdu_read_holding_registers_request: ModbusPDUReadHoldingRegistersRequest = ModbusPDUReadHoldingRegistersRequest(self.starting_address, self.quantity ) return modbus_pdu_read_holding_registers_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersResponse.py index dd2bf21ec66..44ae2e10b4a 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadHoldingRegistersResponse.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadHoldingRegistersResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadHoldingRegistersResponse(ModbusPDU): value: List[int] # Accessors for discriminator values. error_flag: bool = False @@ -36,10 +39,6 @@ class ModbusPDUReadHoldingRegistersResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadHoldingRegistersResponse") @@ -55,17 +54,17 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadHoldingRegistersResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -76,9 +75,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadHoldingRegistersResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUReadHoldingRegistersResponse") # Create the instance @@ -99,22 +98,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadHoldingRegistersResponseBuilder(ModbusPDUBuilder): value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadHoldingRegistersResponse: modbus_pdu_read_holding_registers_response: ModbusPDUReadHoldingRegistersResponse = ModbusPDUReadHoldingRegistersResponse(self.value ) return modbus_pdu_read_holding_registers_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersRequest.py index a8d0bc40d71..5f1def74e1e 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUReadInputRegistersRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadInputRegistersRequest(ModbusPDU): starting_address: int quantity: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUReadInputRegistersRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadInputRegistersRequest") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadInputRegistersRequest = self # Simple field (startingAddress) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadInputRegistersRequest") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") read_buffer.pop_context("ModbusPDUReadInputRegistersRequest") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadInputRegistersRequestBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadInputRegistersRequest: modbus_pdu_read_input_registers_request: ModbusPDUReadInputRegistersRequest = ModbusPDUReadInputRegistersRequest(self.starting_address, self.quantity ) return modbus_pdu_read_input_registers_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersResponse.py index 9fef623746d..4749b8fe424 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadInputRegistersResponse.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadInputRegistersResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadInputRegistersResponse(ModbusPDU): value: List[int] # Accessors for discriminator values. error_flag: bool = False @@ -36,10 +39,6 @@ class ModbusPDUReadInputRegistersResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadInputRegistersResponse") @@ -55,17 +54,17 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadInputRegistersResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -76,9 +75,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadInputRegistersResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUReadInputRegistersResponse") # Create the instance @@ -99,22 +98,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadInputRegistersResponseBuilder(ModbusPDUBuilder): value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadInputRegistersResponse: modbus_pdu_read_input_registers_response: ModbusPDUReadInputRegistersResponse = ModbusPDUReadInputRegistersResponse(self.value ) return modbus_pdu_read_input_registers_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersRequest.py index d0adbca2051..13d6f4c36ca 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersRequest.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadWriteMultipleHoldingRegistersRequest(PlcMessage,ModbusPDU): +class ModbusPDUReadWriteMultipleHoldingRegistersRequest(ModbusPDU): read_starting_address: int read_quantity: int write_starting_address: int @@ -40,10 +43,6 @@ class ModbusPDUReadWriteMultipleHoldingRegistersRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadWriteMultipleHoldingRegistersRequest") @@ -71,10 +70,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadWriteMultipleHoldingRegistersRequest = self # Simple field (readStartingAddress) @@ -93,7 +92,7 @@ def get_length_in_bits(self) -> int: length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -104,17 +103,17 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadWriteMultipleHoldingRegistersRequest") - self.read_starting_address= read_simple_field("readStartingAddress", read_unsigned_int) + read_starting_address: int = read_buffer.read_unsigned_int(logical_name="readStartingAddress") - self.read_quantity= read_simple_field("readQuantity", read_unsigned_int) + read_quantity: int = read_buffer.read_unsigned_int(logical_name="readQuantity") - self.write_starting_address= read_simple_field("writeStartingAddress", read_unsigned_int) + write_starting_address: int = read_buffer.read_unsigned_int(logical_name="writeStartingAddress") - self.write_quantity= read_simple_field("writeQuantity", read_unsigned_int) + write_quantity: int = read_buffer.read_unsigned_int(logical_name="writeQuantity") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUReadWriteMultipleHoldingRegistersRequest") # Create the instance @@ -135,26 +134,24 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadWriteMultipleHoldingRegistersRequestBuilder(ModbusPDUBuilder): - readStartingAddress: int - readQuantity: int - writeStartingAddress: int - writeQuantity: int + read_starting_address: int + read_quantity: int + write_starting_address: int + write_quantity: int value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadWriteMultipleHoldingRegistersRequest: modbus_pdu_read_write_multiple_holding_registers_request: ModbusPDUReadWriteMultipleHoldingRegistersRequest = ModbusPDUReadWriteMultipleHoldingRegistersRequest(self.read_starting_address, self.read_quantity, self.write_starting_address, self.write_quantity, self.value ) return modbus_pdu_read_write_multiple_holding_registers_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersResponse.py index 22ed9dab1ba..40bc10bcff7 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReadWriteMultipleHoldingRegistersResponse.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReadWriteMultipleHoldingRegistersResponse(PlcMessage,ModbusPDU): +class ModbusPDUReadWriteMultipleHoldingRegistersResponse(ModbusPDU): value: List[int] # Accessors for discriminator values. error_flag: bool = False @@ -36,10 +39,6 @@ class ModbusPDUReadWriteMultipleHoldingRegistersResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReadWriteMultipleHoldingRegistersResponse") @@ -55,17 +54,17 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReadWriteMultipleHoldingRegistersResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -76,9 +75,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReadWriteMultipleHoldingRegistersResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUReadWriteMultipleHoldingRegistersResponse") # Create the instance @@ -99,22 +98,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReadWriteMultipleHoldingRegistersResponseBuilder(ModbusPDUBuilder): value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReadWriteMultipleHoldingRegistersResponse: modbus_pdu_read_write_multiple_holding_registers_response: ModbusPDUReadWriteMultipleHoldingRegistersResponse = ModbusPDUReadWriteMultipleHoldingRegistersResponse(self.value ) return modbus_pdu_read_write_multiple_holding_registers_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdRequest.py index c9e346bacf9..68bd8edc075 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,17 +29,13 @@ import math @dataclass -class ModbusPDUReportServerIdRequest(PlcMessage,ModbusPDU): +class ModbusPDUReportServerIdRequest(ModbusPDU): # Accessors for discriminator values. error_flag: bool = False function_flag: int = 0x11 response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReportServerIdRequest") @@ -46,10 +44,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReportServerIdRequest = self return length_in_bits @@ -78,21 +76,19 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReportServerIdRequestBuilder(ModbusPDUBuilder): - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReportServerIdRequest: modbus_pdu_report_server_id_request: ModbusPDUReportServerIdRequest = ModbusPDUReportServerIdRequest() return modbus_pdu_report_server_id_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdResponse.py index 6f6659bbdca..eb05a3ad000 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUReportServerIdResponse.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUReportServerIdResponse(PlcMessage,ModbusPDU): +class ModbusPDUReportServerIdResponse(ModbusPDU): value: List[int] # Accessors for discriminator values. error_flag: bool = False @@ -36,10 +39,6 @@ class ModbusPDUReportServerIdResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUReportServerIdResponse") @@ -55,17 +54,17 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUReportServerIdResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -76,9 +75,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUReportServerIdResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUReportServerIdResponse") # Create the instance @@ -99,22 +98,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUReportServerIdResponseBuilder(ModbusPDUBuilder): value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUReportServerIdResponse: modbus_pdu_report_server_id_response: ModbusPDUReportServerIdResponse = ModbusPDUReportServerIdResponse(self.value ) return modbus_pdu_report_server_id_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequest.py index 7506391cafc..b65c979c4c4 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -26,11 +28,12 @@ from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer from sys import getsizeof +from typing import Any from typing import List import math @dataclass -class ModbusPDUWriteFileRecordRequest(PlcMessage,ModbusPDU): +class ModbusPDUWriteFileRecordRequest(ModbusPDU): items: List[ModbusPDUWriteFileRecordRequestItem] # Accessors for discriminator values. error_flag: bool = False @@ -38,10 +41,6 @@ class ModbusPDUWriteFileRecordRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteFileRecordRequest") @@ -57,19 +56,19 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteFileRecordRequest = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.items != None: + if self.items is not None: for element in self.items: - length_in_bits += element.get_length_in_bits() + length_in_bits += element.length_in_bits() @@ -80,9 +79,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteFileRecordRequest") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - items: List[Any] = read_buffer.read_array_field("items", read_buffer.DataReaderComplexDefault(ModbusPDUWriteFileRecordRequestItem.static_parse(read_buffer), read_buffer), length=byte_count) + items: List[Any] = read_buffer.read_array_field(logical_name="items", read_function=ModbusPDUWriteFileRecordRequestItem.static_parse, length=byte_count) read_buffer.pop_context("ModbusPDUWriteFileRecordRequest") # Create the instance @@ -103,22 +102,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUWriteFileRecordRequestBuilder(ModbusPDUBuilder): items: List[ModbusPDUWriteFileRecordRequestItem] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteFileRecordRequest: modbus_pdu_write_file_record_request: ModbusPDUWriteFileRecordRequest = ModbusPDUWriteFileRecordRequest(self.items ) return modbus_pdu_write_file_record_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequestItem.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequestItem.py index 905590c0a42..678ae3997c4 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequestItem.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordRequestItem.py @@ -19,24 +19,23 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUWriteFileRecordRequestItem(PlcMessage): +class ModbusPDUWriteFileRecordRequestItem(): reference_type: int file_number: int record_number: int record_data: List[int] - def __post_init__(self): - super().__init__( ) - - def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteFileRecordRequestItem") @@ -61,9 +60,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusPDUWriteFileRecordRequestItem = self @@ -80,30 +79,31 @@ def get_length_in_bits(self) -> int: length_in_bits += 16 # Array field - if self.record_data != None: + if self.record_data is not None: length_in_bits += 8 * len(self.record_data) return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - return self.static_parse_context(read_buffer) + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + return ModbusPDUWriteFileRecordRequestItem.static_parse_context(read_buffer) @staticmethod def static_parse_context(read_buffer: ReadBuffer): read_buffer.push_context("ModbusPDUWriteFileRecordRequestItem") - self.reference_type= read_simple_field("referenceType", read_unsigned_short) + reference_type: int = read_buffer.read_unsigned_short(logical_name="referenceType") - self.file_number= read_simple_field("fileNumber", read_unsigned_int) + file_number: int = read_buffer.read_unsigned_int(logical_name="fileNumber") - self.record_number= read_simple_field("recordNumber", read_unsigned_int) + record_number: int = read_buffer.read_unsigned_int(logical_name="recordNumber") - record_length: int = read_implicit_field("recordLength", read_unsigned_int) + record_length: int = read_buffer.read_unsigned_int(logical_name="recordLength") - record_data: List[int] = read_buffer.read_byte_array("recordData", int(record_length* int(2))) + record_data: List[Any] = read_buffer.read_array_field(logical_name="recordData", read_function=read_buffer.read_byte, count=record_length* int(2)) read_buffer.pop_context("ModbusPDUWriteFileRecordRequestItem") # Create the instance @@ -125,13 +125,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) - - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) + + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponse.py index 54cd49b92cc..c7ed6e3c49c 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -26,11 +28,12 @@ from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer from sys import getsizeof +from typing import Any from typing import List import math @dataclass -class ModbusPDUWriteFileRecordResponse(PlcMessage,ModbusPDU): +class ModbusPDUWriteFileRecordResponse(ModbusPDU): items: List[ModbusPDUWriteFileRecordResponseItem] # Accessors for discriminator values. error_flag: bool = False @@ -38,10 +41,6 @@ class ModbusPDUWriteFileRecordResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteFileRecordResponse") @@ -57,19 +56,19 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteFileRecordResponse = self # Implicit Field (byteCount) length_in_bits += 8 # Array field - if self.items != None: + if self.items is not None: for element in self.items: - length_in_bits += element.get_length_in_bits() + length_in_bits += element.length_in_bits() @@ -80,9 +79,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteFileRecordResponse") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - items: List[Any] = read_buffer.read_array_field("items", read_buffer.DataReaderComplexDefault(ModbusPDUWriteFileRecordResponseItem.static_parse(read_buffer), read_buffer), length=byte_count) + items: List[Any] = read_buffer.read_array_field(logical_name="items", read_function=ModbusPDUWriteFileRecordResponseItem.static_parse, length=byte_count) read_buffer.pop_context("ModbusPDUWriteFileRecordResponse") # Create the instance @@ -103,22 +102,20 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUWriteFileRecordResponseBuilder(ModbusPDUBuilder): items: List[ModbusPDUWriteFileRecordResponseItem] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteFileRecordResponse: modbus_pdu_write_file_record_response: ModbusPDUWriteFileRecordResponse = ModbusPDUWriteFileRecordResponse(self.items ) return modbus_pdu_write_file_record_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponseItem.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponseItem.py index 00aca97b37e..cf6ab313410 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponseItem.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteFileRecordResponseItem.py @@ -19,24 +19,23 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUWriteFileRecordResponseItem(PlcMessage): +class ModbusPDUWriteFileRecordResponseItem(): reference_type: int file_number: int record_number: int record_data: List[int] - def __post_init__(self): - super().__init__( ) - - def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteFileRecordResponseItem") @@ -61,9 +60,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: ModbusPDUWriteFileRecordResponseItem = self @@ -80,30 +79,31 @@ def get_length_in_bits(self) -> int: length_in_bits += 16 # Array field - if self.record_data != None: + if self.record_data is not None: length_in_bits += 8 * len(self.record_data) return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - return self.static_parse_context(read_buffer) + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + return ModbusPDUWriteFileRecordResponseItem.static_parse_context(read_buffer) @staticmethod def static_parse_context(read_buffer: ReadBuffer): read_buffer.push_context("ModbusPDUWriteFileRecordResponseItem") - self.reference_type= read_simple_field("referenceType", read_unsigned_short) + reference_type: int = read_buffer.read_unsigned_short(logical_name="referenceType") - self.file_number= read_simple_field("fileNumber", read_unsigned_int) + file_number: int = read_buffer.read_unsigned_int(logical_name="fileNumber") - self.record_number= read_simple_field("recordNumber", read_unsigned_int) + record_number: int = read_buffer.read_unsigned_int(logical_name="recordNumber") - record_length: int = read_implicit_field("recordLength", read_unsigned_int) + record_length: int = read_buffer.read_unsigned_int(logical_name="recordLength") - record_data: List[int] = read_buffer.read_byte_array("recordData", int(record_length)) + record_data: List[Any] = read_buffer.read_array_field(logical_name="recordData", read_function=read_buffer.read_byte, count=record_length) read_buffer.pop_context("ModbusPDUWriteFileRecordResponseItem") # Create the instance @@ -125,13 +125,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) - - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) + + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsRequest.py index e0e9a007296..71f5025d7df 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsRequest.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUWriteMultipleCoilsRequest(PlcMessage,ModbusPDU): +class ModbusPDUWriteMultipleCoilsRequest(ModbusPDU): starting_address: int quantity: int value: List[int] @@ -38,10 +41,6 @@ class ModbusPDUWriteMultipleCoilsRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteMultipleCoilsRequest") @@ -63,10 +62,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteMultipleCoilsRequest = self # Simple field (startingAddress) @@ -79,7 +78,7 @@ def get_length_in_bits(self) -> int: length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -90,13 +89,13 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteMultipleCoilsRequest") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUWriteMultipleCoilsRequest") # Create the instance @@ -117,24 +116,22 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUWriteMultipleCoilsRequestBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteMultipleCoilsRequest: modbus_pdu_write_multiple_coils_request: ModbusPDUWriteMultipleCoilsRequest = ModbusPDUWriteMultipleCoilsRequest(self.starting_address, self.quantity, self.value ) return modbus_pdu_write_multiple_coils_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsResponse.py index 0206cd8fe08..2e79e86818c 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleCoilsResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUWriteMultipleCoilsResponse(PlcMessage,ModbusPDU): +class ModbusPDUWriteMultipleCoilsResponse(ModbusPDU): starting_address: int quantity: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUWriteMultipleCoilsResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteMultipleCoilsResponse") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteMultipleCoilsResponse = self # Simple field (startingAddress) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteMultipleCoilsResponse") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") read_buffer.pop_context("ModbusPDUWriteMultipleCoilsResponse") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUWriteMultipleCoilsResponseBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteMultipleCoilsResponse: modbus_pdu_write_multiple_coils_response: ModbusPDUWriteMultipleCoilsResponse = ModbusPDUWriteMultipleCoilsResponse(self.starting_address, self.quantity ) return modbus_pdu_write_multiple_coils_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersRequest.py index 3024d1761f7..0321670019b 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersRequest.py @@ -19,16 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from typing import Any from typing import List import math @dataclass -class ModbusPDUWriteMultipleHoldingRegistersRequest(PlcMessage,ModbusPDU): +class ModbusPDUWriteMultipleHoldingRegistersRequest(ModbusPDU): starting_address: int quantity: int value: List[int] @@ -38,10 +41,6 @@ class ModbusPDUWriteMultipleHoldingRegistersRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteMultipleHoldingRegistersRequest") @@ -63,10 +62,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteMultipleHoldingRegistersRequest = self # Simple field (startingAddress) @@ -79,7 +78,7 @@ def get_length_in_bits(self) -> int: length_in_bits += 8 # Array field - if self.value != None: + if self.value is not None: length_in_bits += 8 * len(self.value) @@ -90,13 +89,13 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteMultipleHoldingRegistersRequest") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") - byte_count: int = read_implicit_field("byteCount", read_unsigned_short) + byte_count: int = read_buffer.read_unsigned_short(logical_name="byteCount") - value: List[int] = read_buffer.read_byte_array("value", int(byte_count)) + value: List[Any] = read_buffer.read_array_field(logical_name="value", read_function=read_buffer.read_byte, count=byte_count) read_buffer.pop_context("ModbusPDUWriteMultipleHoldingRegistersRequest") # Create the instance @@ -117,24 +116,22 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUWriteMultipleHoldingRegistersRequestBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int value: List[int] - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteMultipleHoldingRegistersRequest: modbus_pdu_write_multiple_holding_registers_request: ModbusPDUWriteMultipleHoldingRegistersRequest = ModbusPDUWriteMultipleHoldingRegistersRequest(self.starting_address, self.quantity, self.value ) return modbus_pdu_write_multiple_holding_registers_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersResponse.py index c877e114af2..7364fef7d9d 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteMultipleHoldingRegistersResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUWriteMultipleHoldingRegistersResponse(PlcMessage,ModbusPDU): +class ModbusPDUWriteMultipleHoldingRegistersResponse(ModbusPDU): starting_address: int quantity: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUWriteMultipleHoldingRegistersResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteMultipleHoldingRegistersResponse") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteMultipleHoldingRegistersResponse = self # Simple field (startingAddress) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteMultipleHoldingRegistersResponse") - self.starting_address= read_simple_field("startingAddress", read_unsigned_int) + starting_address: int = read_buffer.read_unsigned_int(logical_name="startingAddress") - self.quantity= read_simple_field("quantity", read_unsigned_int) + quantity: int = read_buffer.read_unsigned_int(logical_name="quantity") read_buffer.pop_context("ModbusPDUWriteMultipleHoldingRegistersResponse") # Create the instance @@ -96,23 +94,21 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusPDUWriteMultipleHoldingRegistersResponseBuilder(ModbusPDUBuilder): - startingAddress: int + starting_address: int quantity: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteMultipleHoldingRegistersResponse: modbus_pdu_write_multiple_holding_registers_response: ModbusPDUWriteMultipleHoldingRegistersResponse = ModbusPDUWriteMultipleHoldingRegistersResponse(self.starting_address, self.quantity ) return modbus_pdu_write_multiple_holding_registers_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilRequest.py index d2b59516643..3d7661e35be 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUWriteSingleCoilRequest(PlcMessage,ModbusPDU): +class ModbusPDUWriteSingleCoilRequest(ModbusPDU): address: int value: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUWriteSingleCoilRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteSingleCoilRequest") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteSingleCoilRequest = self # Simple field (address) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteSingleCoilRequest") - self.address= read_simple_field("address", read_unsigned_int) + address: int = read_buffer.read_unsigned_int(logical_name="address") - self.value= read_simple_field("value", read_unsigned_int) + value: int = read_buffer.read_unsigned_int(logical_name="value") read_buffer.pop_context("ModbusPDUWriteSingleCoilRequest") # Create the instance @@ -96,13 +94,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass @@ -110,9 +109,6 @@ class ModbusPDUWriteSingleCoilRequestBuilder(ModbusPDUBuilder): address: int value: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteSingleCoilRequest: modbus_pdu_write_single_coil_request: ModbusPDUWriteSingleCoilRequest = ModbusPDUWriteSingleCoilRequest(self.address, self.value ) return modbus_pdu_write_single_coil_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilResponse.py index f298f6e825d..3e3abad13d8 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleCoilResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUWriteSingleCoilResponse(PlcMessage,ModbusPDU): +class ModbusPDUWriteSingleCoilResponse(ModbusPDU): address: int value: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUWriteSingleCoilResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteSingleCoilResponse") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteSingleCoilResponse = self # Simple field (address) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteSingleCoilResponse") - self.address= read_simple_field("address", read_unsigned_int) + address: int = read_buffer.read_unsigned_int(logical_name="address") - self.value= read_simple_field("value", read_unsigned_int) + value: int = read_buffer.read_unsigned_int(logical_name="value") read_buffer.pop_context("ModbusPDUWriteSingleCoilResponse") # Create the instance @@ -96,13 +94,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass @@ -110,9 +109,6 @@ class ModbusPDUWriteSingleCoilResponseBuilder(ModbusPDUBuilder): address: int value: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteSingleCoilResponse: modbus_pdu_write_single_coil_response: ModbusPDUWriteSingleCoilResponse = ModbusPDUWriteSingleCoilResponse(self.address, self.value ) return modbus_pdu_write_single_coil_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterRequest.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterRequest.py index 39d93747d57..0c7c984ca97 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterRequest.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterRequest.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUWriteSingleRegisterRequest(PlcMessage,ModbusPDU): +class ModbusPDUWriteSingleRegisterRequest(ModbusPDU): address: int value: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUWriteSingleRegisterRequest(PlcMessage,ModbusPDU): response: bool = False - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteSingleRegisterRequest") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteSingleRegisterRequest = self # Simple field (address) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteSingleRegisterRequest") - self.address= read_simple_field("address", read_unsigned_int) + address: int = read_buffer.read_unsigned_int(logical_name="address") - self.value= read_simple_field("value", read_unsigned_int) + value: int = read_buffer.read_unsigned_int(logical_name="value") read_buffer.pop_context("ModbusPDUWriteSingleRegisterRequest") # Create the instance @@ -96,13 +94,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass @@ -110,9 +109,6 @@ class ModbusPDUWriteSingleRegisterRequestBuilder(ModbusPDUBuilder): address: int value: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteSingleRegisterRequest: modbus_pdu_write_single_register_request: ModbusPDUWriteSingleRegisterRequest = ModbusPDUWriteSingleRegisterRequest(self.address, self.value ) return modbus_pdu_write_single_register_request diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterResponse.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterResponse.py index 971edcf6cc7..c37f07ffdaf 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterResponse.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusPDUWriteSingleRegisterResponse.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDUBuilder @@ -27,7 +29,7 @@ import math @dataclass -class ModbusPDUWriteSingleRegisterResponse(PlcMessage,ModbusPDU): +class ModbusPDUWriteSingleRegisterResponse(ModbusPDU): address: int value: int # Accessors for discriminator values. @@ -36,10 +38,6 @@ class ModbusPDUWriteSingleRegisterResponse(PlcMessage,ModbusPDU): response: bool = True - def __post_init__(self): - super().__init__( ) - - def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusPDUWriteSingleRegisterResponse") @@ -54,10 +52,10 @@ def serialize_modbus_pdu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusPDUWriteSingleRegisterResponse = self # Simple field (address) @@ -73,9 +71,9 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, response: bool): read_buffer.push_context("ModbusPDUWriteSingleRegisterResponse") - self.address= read_simple_field("address", read_unsigned_int) + address: int = read_buffer.read_unsigned_int(logical_name="address") - self.value= read_simple_field("value", read_unsigned_int) + value: int = read_buffer.read_unsigned_int(logical_name="value") read_buffer.pop_context("ModbusPDUWriteSingleRegisterResponse") # Create the instance @@ -96,13 +94,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass @@ -110,9 +109,6 @@ class ModbusPDUWriteSingleRegisterResponseBuilder(ModbusPDUBuilder): address: int value: int - def __post_init__(self): - pass - def build(self,) -> ModbusPDUWriteSingleRegisterResponse: modbus_pdu_write_single_register_response: ModbusPDUWriteSingleRegisterResponse = ModbusPDUWriteSingleRegisterResponse(self.address, self.value ) return modbus_pdu_write_single_register_response diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusRtuADU.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusRtuADU.py index 9e3386ad2e5..b3b0e39d841 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusRtuADU.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusRtuADU.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus import StaticHelper from plc4py.protocols.modbus.readwrite.DriverType import DriverType @@ -27,10 +29,11 @@ from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from plc4py.utils.GenericTypes import ByteOrder import math @dataclass -class ModbusRtuADU(PlcMessage,ModbusADU): +class ModbusRtuADU(ModbusADU): address: int pdu: ModbusPDU # Arguments. @@ -39,10 +42,6 @@ class ModbusRtuADU(PlcMessage,ModbusADU): driver_type: DriverType = DriverType.MODBUS_RTU - def __post_init__(self): - super().__init__( self.response ) - - def serialize_modbus_adu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusRtuADU") @@ -54,23 +53,23 @@ def serialize_modbus_adu_child(self, write_buffer: WriteBuffer): write_buffer.write_serializable(self.pdu, logical_name="pdu") # Checksum Field (checksum) (Calculated) - write_buffer.write_unsigned_short(int(StaticHelper.rtu_crc_check(self.address, self.pdu)), logical_name="crc") + write_buffer.write_unsigned_short(int(StaticHelper.rtu_crc_check(address, pdu)), logical_name="crc") write_buffer.pop_context("ModbusRtuADU") def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusRtuADU = self # Simple field (address) length_in_bits += 8 # Simple field (pdu) - length_in_bits += self.pdu.get_length_in_bits() + length_in_bits += self.pdu.length_in_bits() # Checksum Field (checksum) length_in_bits += 16 @@ -82,11 +81,11 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, driver_type: DriverType, response: bool): read_buffer.push_context("ModbusRtuADU") - self.address= read_simple_field("address", read_unsigned_short, WithOption.WithByteOrder(get_bi_g__endian())) + address: int = read_buffer.read_unsigned_short(logical_name="address", byte_order=ByteOrder.BIG_ENDIAN) - self.pdu= read_simple_field("pdu", DataReaderComplexDefault(ModbusPDU.static_parse(read_buffer, bool(response)), read_buffer), WithOption.WithByteOrder(get_bi_g__endian())) + pdu: ModbusPDU = read_buffer.read_complex(read_function=ModbusPDU.static_parse, logical_name="pdu", byte_order=ByteOrder.BIG_ENDIAN) - crc: int = read_checksum_field("crc", read_unsigned_int, (int) (rtu_crc_check(self.address, self.pdu)), WithOption.WithByteOrder(get_bi_g__endian())) + crc: int = read_buffer.read_unsigned_int(logical_name="crc", byte_order=ByteOrder.BIG_ENDIAN) read_buffer.pop_context("ModbusRtuADU") # Create the instance @@ -107,26 +106,23 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusRtuADUBuilder(ModbusADUBuilder): address: int pdu: ModbusPDU - response: bool - - def __post_init__(self): - pass - def build(self,response: bool ) -> ModbusRtuADU: - modbus_rtu_adu: ModbusRtuADU = ModbusRtuADU(self.address, self.pdu , response ) + def build(self,response: bool , ) -> ModbusRtuADU: + modbus_rtu_adu: ModbusRtuADU = ModbusRtuADU(response , self.address, self.pdu ) return modbus_rtu_adu diff --git a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusTcpADU.py b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusTcpADU.py index 4ba09ebfe12..42050acdbfa 100644 --- a/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusTcpADU.py +++ b/sandbox/plc4py/plc4py/protocols/modbus/readwrite/ModbusTcpADU.py @@ -19,6 +19,8 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.protocols.modbus.readwrite.DriverType import DriverType from plc4py.protocols.modbus.readwrite.ModbusADU import ModbusADU @@ -26,24 +28,21 @@ from plc4py.protocols.modbus.readwrite.ModbusPDU import ModbusPDU from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from plc4py.utils.GenericTypes import ByteOrder import math @dataclass -class ModbusTcpADU(PlcMessage,ModbusADU): +class ModbusTcpADU(ModbusADU): transaction_identifier: int unit_identifier: int pdu: ModbusPDU # Arguments. response: bool - PROTOCOLIDENTIFIER: int = 0x0000 + PROTOCOL_IDENTIFIER: int = 0x0000 # Accessors for discriminator values. driver_type: DriverType = DriverType.MODBUS_TCP - def __post_init__(self): - super().__init__( self.response ) - - def serialize_modbus_adu_child(self, write_buffer: WriteBuffer): write_buffer.push_context("ModbusTcpADU") @@ -52,10 +51,10 @@ def serialize_modbus_adu_child(self, write_buffer: WriteBuffer): write_buffer.write_unsigned_short(self.transaction_identifier, logical_name="transactionIdentifier") # Const Field (protocolIdentifier) - write_buffer.write_unsigned_short(self.protocol_identifier.value, logical_name="protocolIdentifier") + write_buffer.write_unsigned_short(self.PROTOCOL_IDENTIFIER, logical_name="protocolIdentifier") # Implicit Field (length) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) - length: int = (self.pdu.getlength_in_bytes(ctx)+ int(1)) + length: int = (self.pdu.length_in_bytes()+ int(1)) write_buffer.write_unsigned_short(length, logical_name="length") # Simple Field (unitIdentifier) @@ -68,10 +67,10 @@ def serialize_modbus_adu_child(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: - length_in_bits: int = super().get_length_in_bits() + def length_in_bits(self) -> int: + length_in_bits: int = super().length_in_bits() _value: ModbusTcpADU = self # Simple field (transactionIdentifier) @@ -87,7 +86,7 @@ def get_length_in_bits(self) -> int: length_in_bits += 8 # Simple field (pdu) - length_in_bits += self.pdu.get_length_in_bits() + length_in_bits += self.pdu.length_in_bits() return length_in_bits @@ -96,15 +95,15 @@ def get_length_in_bits(self) -> int: def static_parse_builder(read_buffer: ReadBuffer, driver_type: DriverType, response: bool): read_buffer.push_context("ModbusTcpADU") - self.transaction_identifier= read_simple_field("transactionIdentifier", read_unsigned_int, WithOption.WithByteOrder(get_bi_g__endian())) + transaction_identifier: int = read_buffer.read_unsigned_int(logical_name="transactionIdentifier", byte_order=ByteOrder.BIG_ENDIAN) - self.protocol_identifier: int = read_const_field("protocolIdentifier", read_unsigned_int, ModbusTcpADU.PROTOCOLIDENTIFIER, WithOption.WithByteOrder(get_bi_g__endian())) + PROTOCOL_IDENTIFIER: int = read_buffer.read_unsigned_int(logical_name="protocolIdentifier", byte_order=ByteOrder.BIG_ENDIAN) - length: int = read_implicit_field("length", read_unsigned_int, WithOption.WithByteOrder(get_bi_g__endian())) + length: int = read_buffer.read_unsigned_int(logical_name="length", byte_order=ByteOrder.BIG_ENDIAN) - self.unit_identifier= read_simple_field("unitIdentifier", read_unsigned_short, WithOption.WithByteOrder(get_bi_g__endian())) + unit_identifier: int = read_buffer.read_unsigned_short(logical_name="unitIdentifier", byte_order=ByteOrder.BIG_ENDIAN) - self.pdu= read_simple_field("pdu", DataReaderComplexDefault(ModbusPDU.static_parse(read_buffer, bool(response)), read_buffer), WithOption.WithByteOrder(get_bi_g__endian())) + pdu: ModbusPDU = read_buffer.read_complex(read_function=ModbusPDU.static_parse, logical_name="pdu", byte_order=ByteOrder.BIG_ENDIAN) read_buffer.pop_context("ModbusTcpADU") # Create the instance @@ -125,27 +124,24 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + #return "\n" + str(write_buffer_box_based.get_box()) + "\n" @dataclass class ModbusTcpADUBuilder(ModbusADUBuilder): - transactionIdentifier: int - unitIdentifier: int + transaction_identifier: int + unit_identifier: int pdu: ModbusPDU - response: bool - - def __post_init__(self): - pass - def build(self,response: bool ) -> ModbusTcpADU: - modbus_tcp_adu: ModbusTcpADU = ModbusTcpADU(self.transaction_identifier, self.unit_identifier, self.pdu , response ) + def build(self,response: bool , ) -> ModbusTcpADU: + modbus_tcp_adu: ModbusTcpADU = ModbusTcpADU(response , self.transaction_identifier, self.unit_identifier, self.pdu ) return modbus_tcp_adu diff --git a/sandbox/plc4py/plc4py/protocols/simulated/readwrite/DataItem.py b/sandbox/plc4py/plc4py/protocols/simulated/readwrite/DataItem.py index 1bb91cef3d0..842183b7cb0 100644 --- a/sandbox/plc4py/plc4py/protocols/simulated/readwrite/DataItem.py +++ b/sandbox/plc4py/plc4py/protocols/simulated/readwrite/DataItem.py @@ -35,10 +35,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_bool" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcBOOL(bool(read_buffer.read_bit("")))) @@ -54,10 +54,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_byte" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcUINT(int(read_buffer.read_unsigned_short(8, logical_name="")))) @@ -73,10 +73,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_word" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcUDINT(int(read_buffer.read_unsigned_int(16, logical_name="")))) @@ -92,10 +92,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_dword" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcULINT(int(read_buffer.read_unsigned_long(32, logical_name="")))) @@ -111,10 +111,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_lword" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcLINT(int(read_buffer.read_unsigned_big_integer(64, logical_name="")))) @@ -130,10 +130,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_sint" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcSINT(int(read_buffer.read_signed_byte(8, logical_name="")))) @@ -149,10 +149,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_int" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcINT(int(read_buffer.read_short(16, logical_name="")))) @@ -168,10 +168,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_dint" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcDINT(int(read_buffer.read_int(32, logical_name="")))) @@ -187,10 +187,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_lint" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcLINT(int(read_buffer.read_long(64, logical_name="")))) @@ -206,10 +206,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_usint" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcUINT(int(read_buffer.read_unsigned_short(8, logical_name="")))) @@ -225,10 +225,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_uint" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcUDINT(int(read_buffer.read_unsigned_int(16, logical_name="")))) @@ -244,10 +244,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_udint" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcULINT(int(read_buffer.read_unsigned_long(32, logical_name="")))) @@ -263,10 +263,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_ulint" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcLINT(int(read_buffer.read_unsigned_big_integer(64, logical_name="")))) @@ -282,10 +282,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_real" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcREAL(float(read_buffer.read_float(32, logical_name="")))) @@ -301,10 +301,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_lreal" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcLREAL(float(read_buffer.read_double(64, logical_name="")))) @@ -320,10 +320,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_char" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcSTRING(str(read_buffer.read_string(8, logical_name="", encoding="")))) @@ -339,10 +339,10 @@ def static_parse(read_buffer: ReadBuffer, data_type: str, number_of_values: int) if EvaluationHelper.equals( data_type, "_wchar" ) : # List # Array field (value) # Count array - if numberOfValues > Integer.MAX_VALUE: - raise ParseException("Array count of " + (numberOfValues) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) + if number_of_values > Integer.MAX_VALUE: + raise ParseException("Array count of " + (number_of_values) + " exceeds the maximum allowed count of " + Integer.MAX_VALUE) - item_count: int = int(numberOfValues) + item_count: int = int(number_of_values) value: List[PlcValue] = [] for cur_item in range(item_count): value.append(PlcSTRING(str(read_buffer.read_string(16, logical_name="", encoding="")))) @@ -369,12 +369,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, @staticmethod def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, numberOfValues: int, byteOrder: ByteOrder) -> None: - if EvaluationHelper.equals( dataType, "BOOL" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # BOOL + if EvaluationHelper.equals( data_type, "BOOL" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # BOOL # Simple Field (value) value: bool = _value.getBool() writeBuffer.WriteBit("value", (value)) - if EvaluationHelper.equals( dataType, "BOOL" ) : # List + if EvaluationHelper.equals( data_type, "BOOL" ) : # List values: PlcList = _value @@ -382,12 +382,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: bool = val.getBool() writeBuffer.WriteBit("value", (value)) - if EvaluationHelper.equals( dataType, "BYTE" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # BYTE + if EvaluationHelper.equals( data_type, "BYTE" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # BYTE # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint8("value", 8, (value)) - if EvaluationHelper.equals( dataType, "BYTE" ) : # List + if EvaluationHelper.equals( data_type, "BYTE" ) : # List values: PlcList = _value @@ -395,12 +395,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint8("value", 8, (value)) - if EvaluationHelper.equals( dataType, "WORD" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # WORD + if EvaluationHelper.equals( data_type, "WORD" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # WORD # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint16("value", 16, (value)) - if EvaluationHelper.equals( dataType, "WORD" ) : # List + if EvaluationHelper.equals( data_type, "WORD" ) : # List values: PlcList = _value @@ -408,12 +408,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint16("value", 16, (value)) - if EvaluationHelper.equals( dataType, "DWORD" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # DWORD + if EvaluationHelper.equals( data_type, "DWORD" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # DWORD # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "DWORD" ) : # List + if EvaluationHelper.equals( data_type, "DWORD" ) : # List values: PlcList = _value @@ -421,12 +421,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "LWORD" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # LWORD + if EvaluationHelper.equals( data_type, "LWORD" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # LWORD # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "LWORD" ) : # List + if EvaluationHelper.equals( data_type, "LWORD" ) : # List values: PlcList = _value @@ -434,12 +434,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "SINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # SINT + if EvaluationHelper.equals( data_type, "SINT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # SINT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt8("value", 8, (value)) - if EvaluationHelper.equals( dataType, "SINT" ) : # List + if EvaluationHelper.equals( data_type, "SINT" ) : # List values: PlcList = _value @@ -447,12 +447,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteInt8("value", 8, (value)) - if EvaluationHelper.equals( dataType, "INT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # INT + if EvaluationHelper.equals( data_type, "INT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # INT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt16("value", 16, (value)) - if EvaluationHelper.equals( dataType, "INT" ) : # List + if EvaluationHelper.equals( data_type, "INT" ) : # List values: PlcList = _value @@ -460,12 +460,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteInt16("value", 16, (value)) - if EvaluationHelper.equals( dataType, "DINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # DINT + if EvaluationHelper.equals( data_type, "DINT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # DINT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "DINT" ) : # List + if EvaluationHelper.equals( data_type, "DINT" ) : # List values: PlcList = _value @@ -473,12 +473,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteInt32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "LINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # LINT + if EvaluationHelper.equals( data_type, "LINT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # LINT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteInt64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "LINT" ) : # List + if EvaluationHelper.equals( data_type, "LINT" ) : # List values: PlcList = _value @@ -486,12 +486,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteInt64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "USINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # USINT + if EvaluationHelper.equals( data_type, "USINT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # USINT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint8("value", 8, (value)) - if EvaluationHelper.equals( dataType, "USINT" ) : # List + if EvaluationHelper.equals( data_type, "USINT" ) : # List values: PlcList = _value @@ -499,12 +499,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint8("value", 8, (value)) - if EvaluationHelper.equals( dataType, "UINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # UINT + if EvaluationHelper.equals( data_type, "UINT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # UINT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint16("value", 16, (value)) - if EvaluationHelper.equals( dataType, "UINT" ) : # List + if EvaluationHelper.equals( data_type, "UINT" ) : # List values: PlcList = _value @@ -512,12 +512,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint16("value", 16, (value)) - if EvaluationHelper.equals( dataType, "UDINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # UDINT + if EvaluationHelper.equals( data_type, "UDINT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # UDINT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "UDINT" ) : # List + if EvaluationHelper.equals( data_type, "UDINT" ) : # List values: PlcList = _value @@ -525,12 +525,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "ULINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # ULINT + if EvaluationHelper.equals( data_type, "ULINT" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # ULINT # Simple Field (value) value: int = _value.getInt() writeBuffer.WriteUint64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "ULINT" ) : # List + if EvaluationHelper.equals( data_type, "ULINT" ) : # List values: PlcList = _value @@ -538,12 +538,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: int = val.getInt() writeBuffer.WriteUint64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "REAL" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # REAL + if EvaluationHelper.equals( data_type, "REAL" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # REAL # Simple Field (value) value: float = _value.getFloat() writeBuffer.WriteFloat32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "REAL" ) : # List + if EvaluationHelper.equals( data_type, "REAL" ) : # List values: PlcList = _value @@ -551,12 +551,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: float = val.getFloat() writeBuffer.WriteFloat32("value", 32, (value)) - if EvaluationHelper.equals( dataType, "LREAL" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # LREAL + if EvaluationHelper.equals( data_type, "LREAL" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # LREAL # Simple Field (value) value: float = _value.getFloat() writeBuffer.WriteFloat64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "LREAL" ) : # List + if EvaluationHelper.equals( data_type, "LREAL" ) : # List values: PlcList = _value @@ -564,12 +564,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: float = val.getFloat() writeBuffer.WriteFloat64("value", 64, (value)) - if EvaluationHelper.equals( dataType, "CHAR" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # CHAR + if EvaluationHelper.equals( data_type, "CHAR" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # CHAR # Simple Field (value) value: str = _value.getStr() writeBuffer.WriteString("value", uint32(8), "UTF-8", (value)) - if EvaluationHelper.equals( dataType, "CHAR" ) : # List + if EvaluationHelper.equals( data_type, "CHAR" ) : # List values: PlcList = _value @@ -577,12 +577,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: str = val.getStr() writeBuffer.WriteString("value", uint32(8), "UTF-8", (value)) - if EvaluationHelper.equals( dataType, "WCHAR" ) and EvaluationHelper.equals( numberOfValues, int(1) ) : # WCHAR + if EvaluationHelper.equals( data_type, "WCHAR" ) and EvaluationHelper.equals( number_of_values, int(1) ) : # WCHAR # Simple Field (value) value: str = _value.getStr() writeBuffer.WriteString("value", uint32(16), "UTF-16", (value)) - if EvaluationHelper.equals( dataType, "WCHAR" ) : # List + if EvaluationHelper.equals( data_type, "WCHAR" ) : # List values: PlcList = _value @@ -590,12 +590,12 @@ def static_serialize(writeBuffer: WriteBuffer, _value: PlcValue, dataType: str, value: str = val.getStr() writeBuffer.WriteString("value", uint32(16), "UTF-16", (value)) - if EvaluationHelper.equals( dataType, "STRING" ) : # STRING + if EvaluationHelper.equals( data_type, "STRING" ) : # STRING # Simple Field (value) value: str = _value.getStr() writeBuffer.WriteString("value", uint32(255), "UTF-8", (value)) - if EvaluationHelper.equals( dataType, "WSTRING" ) : # STRING + if EvaluationHelper.equals( data_type, "WSTRING" ) : # STRING # Simple Field (value) value: str = _value.getStr() @@ -609,112 +609,112 @@ def get_length_in_bytes(_value: PlcValue, dataType: str, numberOfValues: int) -> @staticmethod def get_length_in_bits(_value: PlcValue, dataType: str, numberOfValues: int) -> int: sizeInBits: int = 0 - if EvaluationHelper.equals( dataType, "BOOL" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # BOOL + if EvaluationHelper.equals( data_type, "BOOL" ) and EvaluationHelper.equals( number_of_values, int(1) ): # BOOL # Simple Field (value) sizeInBits += 1 - if EvaluationHelper.equals( dataType, "BOOL" ): # List + if EvaluationHelper.equals( data_type, "BOOL" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 1 - if EvaluationHelper.equals( dataType, "BYTE" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # BYTE + if EvaluationHelper.equals( data_type, "BYTE" ) and EvaluationHelper.equals( number_of_values, int(1) ): # BYTE # Simple Field (value) sizeInBits += 8 - if EvaluationHelper.equals( dataType, "BYTE" ): # List + if EvaluationHelper.equals( data_type, "BYTE" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 8 - if EvaluationHelper.equals( dataType, "WORD" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # WORD + if EvaluationHelper.equals( data_type, "WORD" ) and EvaluationHelper.equals( number_of_values, int(1) ): # WORD # Simple Field (value) sizeInBits += 16 - if EvaluationHelper.equals( dataType, "WORD" ): # List + if EvaluationHelper.equals( data_type, "WORD" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 16 - if EvaluationHelper.equals( dataType, "DWORD" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # DWORD + if EvaluationHelper.equals( data_type, "DWORD" ) and EvaluationHelper.equals( number_of_values, int(1) ): # DWORD # Simple Field (value) sizeInBits += 32 - if EvaluationHelper.equals( dataType, "DWORD" ): # List + if EvaluationHelper.equals( data_type, "DWORD" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 32 - if EvaluationHelper.equals( dataType, "LWORD" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # LWORD + if EvaluationHelper.equals( data_type, "LWORD" ) and EvaluationHelper.equals( number_of_values, int(1) ): # LWORD # Simple Field (value) sizeInBits += 64 - if EvaluationHelper.equals( dataType, "LWORD" ): # List + if EvaluationHelper.equals( data_type, "LWORD" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 64 - if EvaluationHelper.equals( dataType, "SINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # SINT + if EvaluationHelper.equals( data_type, "SINT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # SINT # Simple Field (value) sizeInBits += 8 - if EvaluationHelper.equals( dataType, "SINT" ): # List + if EvaluationHelper.equals( data_type, "SINT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 8 - if EvaluationHelper.equals( dataType, "INT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # INT + if EvaluationHelper.equals( data_type, "INT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # INT # Simple Field (value) sizeInBits += 16 - if EvaluationHelper.equals( dataType, "INT" ): # List + if EvaluationHelper.equals( data_type, "INT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 16 - if EvaluationHelper.equals( dataType, "DINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # DINT + if EvaluationHelper.equals( data_type, "DINT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # DINT # Simple Field (value) sizeInBits += 32 - if EvaluationHelper.equals( dataType, "DINT" ): # List + if EvaluationHelper.equals( data_type, "DINT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 32 - if EvaluationHelper.equals( dataType, "LINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # LINT + if EvaluationHelper.equals( data_type, "LINT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # LINT # Simple Field (value) sizeInBits += 64 - if EvaluationHelper.equals( dataType, "LINT" ): # List + if EvaluationHelper.equals( data_type, "LINT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 64 - if EvaluationHelper.equals( dataType, "USINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # USINT + if EvaluationHelper.equals( data_type, "USINT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # USINT # Simple Field (value) sizeInBits += 8 - if EvaluationHelper.equals( dataType, "USINT" ): # List + if EvaluationHelper.equals( data_type, "USINT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 8 - if EvaluationHelper.equals( dataType, "UINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # UINT + if EvaluationHelper.equals( data_type, "UINT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # UINT # Simple Field (value) sizeInBits += 16 - if EvaluationHelper.equals( dataType, "UINT" ): # List + if EvaluationHelper.equals( data_type, "UINT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 16 - if EvaluationHelper.equals( dataType, "UDINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # UDINT + if EvaluationHelper.equals( data_type, "UDINT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # UDINT # Simple Field (value) sizeInBits += 32 - if EvaluationHelper.equals( dataType, "UDINT" ): # List + if EvaluationHelper.equals( data_type, "UDINT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 32 - if EvaluationHelper.equals( dataType, "ULINT" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # ULINT + if EvaluationHelper.equals( data_type, "ULINT" ) and EvaluationHelper.equals( number_of_values, int(1) ): # ULINT # Simple Field (value) sizeInBits += 64 - if EvaluationHelper.equals( dataType, "ULINT" ): # List + if EvaluationHelper.equals( data_type, "ULINT" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 64 - if EvaluationHelper.equals( dataType, "REAL" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # REAL + if EvaluationHelper.equals( data_type, "REAL" ) and EvaluationHelper.equals( number_of_values, int(1) ): # REAL # Simple Field (value) sizeInBits += 32 - if EvaluationHelper.equals( dataType, "REAL" ): # List + if EvaluationHelper.equals( data_type, "REAL" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 32 - if EvaluationHelper.equals( dataType, "LREAL" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # LREAL + if EvaluationHelper.equals( data_type, "LREAL" ) and EvaluationHelper.equals( number_of_values, int(1) ): # LREAL # Simple Field (value) sizeInBits += 64 - if EvaluationHelper.equals( dataType, "LREAL" ): # List + if EvaluationHelper.equals( data_type, "LREAL" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 64 - if EvaluationHelper.equals( dataType, "CHAR" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # CHAR + if EvaluationHelper.equals( data_type, "CHAR" ) and EvaluationHelper.equals( number_of_values, int(1) ): # CHAR # Simple Field (value) sizeInBits += 8 - if EvaluationHelper.equals( dataType, "CHAR" ): # List + if EvaluationHelper.equals( data_type, "CHAR" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 8 - if EvaluationHelper.equals( dataType, "WCHAR" ) and EvaluationHelper.equals( numberOfValues, int(1) ): # WCHAR + if EvaluationHelper.equals( data_type, "WCHAR" ) and EvaluationHelper.equals( number_of_values, int(1) ): # WCHAR # Simple Field (value) sizeInBits += 16 - if EvaluationHelper.equals( dataType, "WCHAR" ): # List + if EvaluationHelper.equals( data_type, "WCHAR" ): # List values: PlcList = _value sizeInBits += values.getList().size() * 16 - if EvaluationHelper.equals( dataType, "STRING" ): # STRING + if EvaluationHelper.equals( data_type, "STRING" ): # STRING # Simple Field (value) sizeInBits += 255 - if EvaluationHelper.equals( dataType, "WSTRING" ): # STRING + if EvaluationHelper.equals( data_type, "WSTRING" ): # STRING # Simple Field (value) sizeInBits += 255 return sizeInBits diff --git a/sandbox/plc4py/plc4py/protocols/simulated/readwrite/Dummy.py b/sandbox/plc4py/plc4py/protocols/simulated/readwrite/Dummy.py index 3d67068ed3d..add66c898a9 100644 --- a/sandbox/plc4py/plc4py/protocols/simulated/readwrite/Dummy.py +++ b/sandbox/plc4py/plc4py/protocols/simulated/readwrite/Dummy.py @@ -19,20 +19,19 @@ from dataclasses import dataclass +from plc4py.api.exceptions.exceptions import PlcRuntimeException +from plc4py.api.exceptions.exceptions import SerializationException from plc4py.api.messages.PlcMessage import PlcMessage from plc4py.spi.generation.ReadBuffer import ReadBuffer from plc4py.spi.generation.WriteBuffer import WriteBuffer +from plc4py.utils.GenericTypes import ByteOrder import math @dataclass -class Dummy(PlcMessage): +class Dummy(): dummy: int - def __post_init__(self): - super().__init__( ) - - def serialize(self, write_buffer: WriteBuffer): write_buffer.push_context("Dummy") @@ -44,9 +43,9 @@ def serialize(self, write_buffer: WriteBuffer): def length_in_bytes(self) -> int: - return int(math.ceil(float(self.get_length_in_bits() / 8.0))) + return int(math.ceil(float(self.length_in_bits() / 8.0))) - def get_length_in_bits(self) -> int: + def length_in_bits(self) -> int: length_in_bits: int = 0 _value: Dummy = self @@ -56,15 +55,16 @@ def get_length_in_bits(self) -> int: return length_in_bits - def static_parse(self, read_buffer: ReadBuffer , args): - return self.static_parse_context(read_buffer) + @staticmethod + def static_parse(read_buffer: ReadBuffer, **kwargs): + return Dummy.static_parse_context(read_buffer) @staticmethod def static_parse_context(read_buffer: ReadBuffer): read_buffer.push_context("Dummy") - self.dummy= read_simple_field("dummy", read_unsigned_int, WithOption.WithByteOrder(get_bi_g__endian())) + dummy: int = read_buffer.read_unsigned_int(logical_name="dummy", byte_order=ByteOrder.BIG_ENDIAN) read_buffer.pop_context("Dummy") # Create the instance @@ -86,13 +86,14 @@ def hash_code(self) -> int: return hash(self) def __str__(self) -> str: - write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) - try: - write_buffer_box_based.writeSerializable(self) - except SerializationException as e: - raise RuntimeException(e) - - return "\n" + str(write_buffer_box_based.get_box()) + "\n" + pass + #write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) + #try: + # write_buffer_box_based.writeSerializable(self) + #except SerializationException as e: + # raise PlcRuntimeException(e) + + #return "\n" + str(write_buffer_box_based.get_box()) + "\n"