1

I have python3 program that acts as a Modbus Master. I start a ModbusSerialClient and then proceed to read register from the slave. This is working fine on Windows. The issue is that on Ubuntu I am seeing that the ModbusSerialClient keeps changing the baudrate which makes the communication inconsistent.

I start the communication with:

from pymodbus.client.sync import ModbusSerialClient as ModbusClient
...
try:
            self.client = ModbusClient(
                method = 'rtu'
                ,port= self.port
                ,baudrate=int(115200)
                ,parity = 'N'
                ,stopbits=1
                ,bytesize=8
                ,timeout=3
                ,RetryOnEmpty = True
                ,RetryOnInvalid = True
            )
            self.connection = self.client.connect()
            # Some delay may be necessary between connect and first transmission
            time.sleep(2)

Where self.port = "COM_X" in Windows and self.port = "/dev/ttyS1" in Linux

And then I read the registers using:

rr = self.client.read_holding_registers(register_addr,register_block,unit=MODBUS_CONFIG_ID)
if(rr.isError()):
   logger.debug(rr)
else:
   # Proceed with the processing

The error I log in some ocasions is:

Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)

I have verified the baudrate change physically measuring the signals. I have verified that with a command line tools like cu the baudrate remains consistent.

The verions I am using are:

  • pymodbus 3.1.0 (error also present with 2.5.3)
  • pyserial 3.5
  • python 3.8.10
  • kubuntu 22.04 (same behaviour with ubuntu)
Ricard Molins
  • 408
  • 1
  • 6
  • 20
  • Hello Ricard, where are you running your client? Is it a Raspberry Pi or similar? – Marcos G. Jan 16 '23 at 15:30
  • It is an industriual grade touch panel PC with an intel J1900 CPU – Ricard Molins Jan 17 '23 at 06:40
  • just in case, check if the serial port you are trying to use is spiting kernel messages from time to time. I think the server images of Ubuntu and/or Kubuntu have the console set up by default. – Marcos G. Jan 17 '23 at 17:31
  • I have checked with 'dmesg' and there are no error messages – Ricard Molins Jan 18 '23 at 07:03
  • Sorry I was not clear, I don't mean you are getting any error messages but some Linux systems sometimes are set up to write kernel debug messages and other info to a serial port. If that's your case you might see very strange things happening like the port working perfectly fine and suddenly printing weird stuff. You might want to take a look at your [kernel parameters](https://tldp.org/HOWTO/Remote-Serial-Console-HOWTO/configure-kernel.html). Just do a `dmesg | grep command` and see if you can find something like `console=ttyS1` or whereabouts. – Marcos G. Jan 18 '23 at 18:09
  • What hardware are you using for the serial port. Motherboard? PCI card? Virtual? – david Jan 22 '23 at 03:56
  • Seems like a SSD failure was causing high CPU usage which may have caused the serial communication to misbehave. Waiting for a new hw to verify – Ricard Molins Jan 27 '23 at 13:56
  • The issue was confirmed to be caused by spike in the CPU caused by the dead SSD – Ricard Molins Mar 01 '23 at 16:17

1 Answers1

0

The issue was confirmed to be caused by spike in the CPU caused by the dead SSD.

Ricard Molins
  • 408
  • 1
  • 6
  • 20