I'm trying to test read file functionality of python pymodbus client library. However, after a write operation, a read operation to exact address returns empty fields:
async def test_file_record(client):
records = [
FileRecord(
record_data=b"\x00\x01\x02\x03",
reference_type = 0x06, file_number = 0x01, record_number = 0x01, record_length = 0x02
),
]
resp = await client.write_file_record(records, slave=SLAVE)
if resp.isError():
raise Exception(f"ERROR: modbus returned an error: {resp}")
print(resp.__dict__)
resp = await client.read_file_record([
FileRecord(
reference_type = 0x06, file_number = 0x01, record_number = 0x01, record_length = 0x02
),
], slave=SLAVE)
if resp.isError():
raise Exception(f"ERROR: modbus returned an error: {resp}")
print(resp.__dict__)
{'transaction_id': 1, 'protocol_id': 0, 'slave_id': 1, 'skip_encode': False, 'check': 0, 'bits': [], 'registers': [], 'records': [FileRecord(file=1, record=1, length=2)]}
{'transaction_id': 2, 'protocol_id': 0, 'slave_id': 1, 'skip_encode': False, 'check': 0, 'bits': [], 'registers': [], 'records': []}
When I reviewed the library code, strangely it just uses empty list to create a response:
from file_message.py file:
def execute(self, _context):
"""Run a read exception status request against the store.
:returns: The populated response
"""
# TODO do some new context operation here # pylint: disable=fixme
# if file number, record number, or address + length
# is too big, return an error.
files = []
return ReadFileRecordResponse(files)