def test_create_from_request_pdu_raising_illegal_data_value_error(self): function_code = ReadCoils.function_code address = 100 quantity = ReadCoils.max_quantity + 1 pdu = struct.pack('>BHH', function_code, address, quantity) with pytest.raises(IllegalDataValueError): ReadCoils.create_from_request_pdu(pdu)
def test_create_function_from_response_pdu(): read_coils = ReadCoils() read_coils.starting_address = 1 read_coils.quantity = 9 req_pdu = read_coils.request_pdu resp_pdu = struct.pack('>BBB', 1, 1, 3) assert isinstance(create_function_from_response_pdu(resp_pdu, req_pdu), ReadCoils)
def read_coils(slave_id, starting_address, quantity): """ Return ADU for Modbus function code 01: Read Coils. :param slave_id: Number of slave. :return: Byte array with ADU. """ function = ReadCoils() function.starting_address = starting_address function.quantity = quantity return _create_request_adu(slave_id, function.request_pdu)
def read_coils(): function_code = 1 starting_address = 100 quantity = 3 pdu = struct.pack('>BHH', function_code, starting_address, quantity) return ReadCoils.create_from_request_pdu(pdu)
def test_create_from_request_pdu(self): """ Call should return instance with correct attributes and vaules. """ function_code = 1 starting_address = 100 quantity = 3 pdu = struct.pack('>BHH', function_code, starting_address, quantity) function = ReadCoils.create_from_request_pdu(pdu) assert function.starting_address == starting_address assert function.quantity == quantity
def read_coils(): instance = ReadCoils() instance.starting_address = 100 instance.quantity = 3 return instance
def test_read_coils_response_pdu(read_coils): response_pdu = read_coils.create_response_pdu([0, 1, 1]) instance = ReadCoils.create_from_response_pdu( response_pdu, read_coils.request_pdu) # NOQA assert instance.data == [0, 1, 1]
def test_read_coils_request_pdu(read_coils): instance = ReadCoils.create_from_request_pdu(read_coils.request_pdu) assert instance.starting_address == 100 assert instance.quantity == 3
def test_read_coils_response_pdu(read_coils): response_pdu = read_coils.create_response_pdu([0, 1, 1]) instance = ReadCoils.create_from_response_pdu(response_pdu, read_coils.request_pdu) # NOQA assert instance.data == [0, 1, 1]