I've been having decoding errors on my Raspberry Pi 3B using pymodbus. Designed a board using MAX14854G as the RS-485 transceiver that is connected to the RPI3's UART pins (8 & 10). Currently testing it by using an RS-485 cable and a modbus simulator (Modbus Simulator --> RS485 cable --> RS-485 HAT board UART --> Raspberry Pi 3B).
Block Diagram:
Additional info: I'm using the full functionality of the UART (ttyAMA0) by swapping the ttyS0 and ttyAMA0 and by disabling the serial consoles and Bluetooth:
$ sudo systemctl disable serial-getty@ttyAMA0.service
$ sudo systemctl disable serial-getty@ttyS0.service
$ sudo systemctl disable serial-getty@serial0.service
$ sudo systemctl disable serial-getty@serial1.service
Here's my code + errors + log:
In [1]: import pymodbus
...: import serial
...: import serial.rs485
...: from pymodbus.pdu import ModbusRequest
...: from pymodbus.client.sync import ModbusSerialClient as ModbusClient
...: from pymodbus.transaction import ModbusRtuFramer
...: from pymodbus.register_read_message import ReadInputRegistersResponse
...:
...: import logging
...: logging.basicConfig()
...: log = logging.getLogger()
...: log.setLevel(logging.DEBUG)
In [2]: msys = ModbusClient(method='rtu',port='/dev/ttyAMA0',stopbits=1,bytesize=8,parity='O',baudrate=9600,timeout=2)
In [3]: msys.inter_char_timeout = 0.05
In [4]: HR2 = msys.read_holding_registers(0,1,unit=1)
DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0x1 0x3 0x0 0x0 0x0 0x1 0x84
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
In [5]: HR2
Out[5]:
pymodbus.exceptions.ModbusIOException('No Response received from the remote unit/Unable to decode response',
3)
In [6]: print(HR2)
Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response
In [7]: print(HR2.registers)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-02134bc1ab17> in <module>()
----> 1 print(HR2.registers)
AttributeError: 'ModbusIOException' object has no attribute 'registers'
Is this a decoding problem or is the Raspberry Pi 3B's UART not properly set? Before disabling the serial consoles, I couldn't even connect to the device. Based on the Modbus simulator, there's data traffic.