I have been successful using modbus-tk with an off the shelf modbus master simulator. However, when the real master is wired in (an Automation Direct PLC), the master does not get any response from the slave.
So I'm looking at using another modbus library (pymodbus). I try to run a very simple bit of code below but get the output as errors. I've checked serial port settings, use, etc..
Code:
client = ModbusClient(method='rtu', port='/dev/ttyS0', timeout=1,
baudrate=9600, stopbits=1, bytesize=8, parity='N')
client.connect()
log.debug("Reading Coils")
rr = client.read_coils(10001, 8, unit=UNIT)
log.debug(rr)
output:
2019-06-24 08:21:49,262 MainThread DEBUG PyModbusTest :85 Reading Coils
2019-06-24 08:21:49,284 MainThread DEBUG transaction :111 Current transaction state - IDLE
2019-06-24 08:21:49,295 MainThread DEBUG transaction :116 Running transaction 1
2019-06-24 08:21:49,307 MainThread DEBUG transaction :215 SEND: 0x2 0x1 0x27 0x11 0x0 0x8 0x67 0x4e
2019-06-24 08:21:49,318 MainThread DEBUG sync :73 New Transaction state 'SENDING'
2019-06-24 08:21:49,331 MainThread DEBUG transaction :224 Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2019-06-24 08:21:50,344 MainThread DEBUG transaction :234 Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received))
2019-06-24 08:21:50,382 MainThread DEBUG rtu_framer :235 Frame - [b''] not ready
2019-06-24 08:21:50,413 MainThread DEBUG transaction :390 Getting transaction 2
2019-06-24 08:21:50,433 MainThread DEBUG transaction :189 Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
2019-06-24 08:21:50,453 MainThread DEBUG PyModbusTest :87 Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received)
UNIT
, this should be the modbus address of your PLC. Is it correct?