I have a problem with communication via Modbus RTU. First of all sorry for my English ;):
- I'm using RS485 Pi SN65HVD72 to connect with MultiCONT PRD-28-2. I made everything like is in this instruction: https://www.abelectronics.co.uk/kb/article/1035/raspberry-pi-3-serial-port-usage
config.txt changes:
- toverlay=pi3-miniuart-bt
- enable_uart=1
After this steps the config of my /dev looks like this:
- lrwxrwxrwx 1 root root 7 gru 30 15:03 serial0 -> ttyAMA0
- lrwxrwxrwx 1 root root 5 gru 30 15:03 serial1 -> ttyS0
- In MultiCONT PRD-28-2 I change RS485 options to:
- Protocol: Modbus
- Parity: ODD
- Stop bit: 1 bit
- Python code:
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
import logging
FORMAT = ('%(asctime)-15s %(threadName)-15s'
' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)
#multicont = ModbusClient(method='rtu',port='/dev/serial0',stopbits=1,bytsize=8,parity='N',baudrate=9600,timeout=1,strict=False)
multicont = ModbusClient(method='rtu',port='/dev/serial0',stopbits=1,bytsize=8,parity='O',baudrate=9600,timeout=1,strict=False)
connection = multicont.connect()
print(connection)
value = multicont.read_coils(1,15,unit=1)
log.debug(value)
- Error message:
Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received)
- Logs:
2020-12-30 16:24:51,992 MainThread DEBUG transaction :118
Current transaction state - IDLE
2020-12-30 16:24:51,992 MainThread DEBUG transaction :123 Running transaction 1
2020-12-30 16:24:51,992 MainThread DEBUG transaction
:230 SEND: 0x1 0x1 0x0 0x1 0x0 0xf 0x2d 0xce
2020-12-30 16:24:51,993 MainThread DEBUG sync :75 New Transaction state 'SENDING'
2020-12-30 16:24:51,993 MainThread
DEBUG transaction :239 Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2020-12-30 16:24:52,995 MainThread DEBUG transaction :253 Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received))
2020-12-30 16:24:52,995 MainThread DEBUG rtu_framer :241 Frame - [b''] not ready
2020-12-30 16:24:52,996 MainThread DEBUG
transaction :409 Getting transaction 1
2020-12-30 16:24:52,996 MainThread DEBUG transaction :204
Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
2020-12-30 16:24:52,996 MainThread
DEBUG communication :20 Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received)