eterey / pymodbus3

A full Modbus protocol written in Python 3.
http://uzumaxy.github.io/pymodbus3/
BSD 3-Clause "New" or "Revised" License
39 stars 11 forks source link

ModbusSerialClient with RTU mothod doesn't read register #11

Open zxpatric opened 6 years ago

zxpatric commented 6 years ago

Using Code: import pymodbus3.client.sync as pcs

client = pcs.ModbusSerialClient(method='rtu', port='COM15', parity='E', )
logging.debug(client.connect());
result = client.read_holding_registers(5302, unit=1)
logging.debug(result);

Got the console result:

DEBUG:root:True DEBUG:pymodbus3.transaction:Running transaction 1 DEBUG:pymodbus3.transaction:getting transaction 1 DEBUG:root:None

Using the pyserial library directly and I got the register reading well.

    self.ser.baudrate = 19200
    self.ser.parity = serial.PARITY_EVEN
    self.ser.stopbits = serial.STOPBITS_ONE
    self.ser.xonxoff = 0
    self.ser.rtscts = 0
    self.ser.dsrdtr = 0

The result we received is:

DEBUG:root:b'\x01\x03\x02x\4B\x00\x8e\xb4'

Debug further into the function handle_message_framing,

when ReadingHeader, the framer only receive 1 bit since size = self.framer.header_size - len(self.framer.buffer). size equals to 1 with empty self.framer.buffer and self.framer.header_size equaling to 1. The check_frame() function afterwards actually failed to populate the header.

When ReadingContent, since it didn't read the header right, it also only reads 1 bit.

When FramerState.CompleteFrame, there is no data to add to the frame and failed out.

So, I am just wondering if it is because I missed some settings so the communication to the register appears to be right but the response parsing turns out to be wrong?

Thanks.