def test_read_write_array(self): write_value = tuple(range(5)) ads.read_write( self.endpoint, index_group=constants.INDEXGROUP_DATA, index_offset=1, plc_read_datatype=constants.PLCTYPE_UDINT, value=write_value, plc_write_datatype=constants.PLCTYPE_UDINT * 5 ) # Retrieve list of received requests from server requests = self.test_server.request_history # Check the value received by the server received_value = struct.unpack('<IIIII', requests[0].ams_header.data[16:]) self.assertEqual(write_value, received_value)
def test_read_write(self): write_value = 100 read_value = ads.read_write(self.endpoint, index_group=constants.INDEXGROUP_DATA, index_offset=1, plc_read_datatype=constants.PLCTYPE_UDINT, value=write_value, plc_write_datatype=constants.PLCTYPE_UDINT) # Retrieve list of received requests from server requests = self.test_server.request_history # Assert that the server received a request self.assertEqual(len(requests), 1) # Assert that the server received the correct command self.assert_command_id(requests[0], constants.ADSCOMMAND_READWRITE) # Check the value received by the server received_value = struct.unpack('<I', requests[0].ams_header.data[16:])[0] self.assertEqual(write_value, received_value) # Check read value returned by server: # Test server just returns repeated bytes of 0x0F terminated with 0x00 expected_result = struct.unpack('<I', '\x0F\x0F\x0F\x00'.encode('utf-8'))[0] self.assertEqual(read_value, expected_result)
def test_read_write(self): write_value = 100 read_value = ads.read_write( self.endpoint, index_group=constants.INDEXGROUP_DATA, index_offset=1, plc_read_datatype=constants.PLCTYPE_UDINT, value=write_value, plc_write_datatype=constants.PLCTYPE_UDINT ) # Retrieve list of received requests from server requests = self.test_server.request_history # Assert that the server received a request self.assertEqual(len(requests), 1) # Assert that the server received the correct command self.assert_command_id(requests[0], constants.ADSCOMMAND_READWRITE) # Check the value received by the server received_value = struct.unpack('<I', requests[0].ams_header.data[16:])[0] self.assertEqual(write_value, received_value) # Check read value returned by server: # Test server just returns repeated bytes of 0x0F terminated with 0x00 expected_result = struct.unpack('<I', '\x0F\x0F\x0F\x00'.encode('utf-8'))[0] self.assertEqual(read_value, expected_result)
def test_read_write_array(self): write_value = tuple(range(5)) ads.read_write(self.endpoint, index_group=constants.INDEXGROUP_DATA, index_offset=1, plc_read_datatype=constants.PLCTYPE_UDINT, value=write_value, plc_write_datatype=constants.PLCTYPE_UDINT * 5) # Retrieve list of received requests from server requests = self.test_server.request_history # Check the value received by the server received_value = struct.unpack('<IIIII', requests[0].ams_header.data[16:]) self.assertEqual(write_value, received_value)
def test_read_write_struct(self): write_value = _Struct(-123, 456) ads.read_write( self.endpoint, index_group=constants.INDEXGROUP_DATA, index_offset=1, plc_read_datatype=_Struct, value=write_value, plc_write_datatype=_Struct, ) # Retrieve list of received requests from server requests = self.test_server.request_history # Check the value received by the server received_value = _Struct.from_buffer_copy(requests[0].ams_header.data[16:]) self.assertEqual(write_value.x, received_value.x) self.assertEqual(write_value.y, received_value.y)