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..


client = ModbusClient(method='rtu', port='/dev/ttyS0', timeout=1,
                       baudrate=9600, stopbits=1, bytesize=8, parity='N')
log.debug("Reading Coils")
rr = client.read_coils(10001, 8, unit=UNIT)


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)

  • Hello. I can't see from your code where you define the value of UNIT, this should be the modbus address of your PLC. Is it correct? Jun 24, 2019 at 12:52
  • Sorry, I will try to format the code. UNIT is defined UNIT = 0x2
    – mspath
    Jun 24, 2019 at 13:05
  • Right now I'm using Simply Modbus as the simulation master. It does not give me the ability to set the address but I will check. 2 is the slave address
    – mspath
    Jun 24, 2019 at 13:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.