I have started the modbus rtu server using the following code.
server=StartSerialServer(context, framer=ModbusRtuFramer, identity=identity,
port='/dev/ttyUSB0',
timeout=1,
baudrate=9600,
parity='N',
bytesize=8,
stopbits=1)`
and reading the registers using the following code:
def read_all_data(slave_id,context,type,address,no_of_reg):
while True:
print("Slave_id ",slave_id,"type ",type,"Address ",address,"No of Reg ",no_of_reg)
data = context[slave_id].getValues(type, address, no_of_reg)
print("data recv",data,context[slave_id].ModbusRtuFramer)
time.sleep(1)
Is there any way where i can capture the raw bytes beforit is being processed . Any help would be highly appreciated
In order to to see change currently i am fetching all the register values and then appending it in the the list then i am comparing the value from the previous version of list and check the change to get the value of register type and address which have been changed. This requires an infinit loop. In order to avoid that loop I want to get raw bytes which it receives so that i can straight away decode it and extract register address and register type in order to order to fetch it from the context using above context.I have tried intializing custom handlers but none of them could help me out . Tried accessing the funtion of the ModbusRtuFramer class getRawbytes where he is unable to access the buffer which was never intialized becase class was passed as the parameter in StartSerialServer not an object of the class.