1

For a project I have 4 modbus devices connected on a RS485 serial line. The devices are working fine and now that I'm writing a controller I'm quite unhappy with the performance of pymodbus.

I found this thread Python modbus library and it seems to me that there may be better python modbus libraries out there. pymodbus is easy to use and I'd rather like to continue using it if possible.

However I've found out that the time any read/write routine takes to return is equal to the timeout. This doesn't seem right to me so I wrote a quick test:

from pymodbus.client.sync import  ModbusSerialClient
import time

for t in xrange(1, 11):
    client = ModbusSerialClient("rtu", port="/dev/ttyUSB0", baudrate=9600, timeout=t)

    start = time.time()
    data = client.read_holding_registers(0x9000, count=7, unit=2)
    stop = time.time()

    if data:
        succ = "was successful"
    else:
        succ = "failed"

    print "timeout: %ss, read %s, time spent reading: %fs" % (t, succ, stop-start)

and this is the output I got

timeout: 1s, read was successful, time spent reading: 1.039731s
timeout: 2s, read was successful, time spent reading: 2.038965s
timeout: 3s, read was successful, time spent reading: 3.041441s
timeout: 4s, read was successful, time spent reading: 4.040762s
timeout: 5s, read was successful, time spent reading: 5.043523s
timeout: 6s, read was successful, time spent reading: 6.040139s
timeout: 7s, read was successful, time spent reading: 7.042159s
timeout: 8s, read was successful, time spent reading: 8.045216s
timeout: 9s, read was successful, time spent reading: 9.047682s
timeout: 10s, read was successful, time spent reading: 10.048799s

I've tested it with different RS845<->USB converters and I always get similar results.

Can anyboby else confirm this? Or am I missing some not-documented argument there that would increase ModbusSerialClient's performance?

Community
  • 1
  • 1
Pablo
  • 13,271
  • 4
  • 39
  • 59
  • hmmm that is weird, is it on a full or half duplex? Also sometimes the electrical stack exchange has some good info about this, since sometimes it may be setup and not software related. – jgr208 Jul 23 '15 at 12:55
  • I use only 2 wires, so I believe this is half duplex, right? Anyway I don't think it has anything to the serial line itself. I added another RS845<->USB converter to the line and wrote a modbus sniffer. I could see that the devices already sent the answers but `pymodbus` read function was still waiting until the timeout. – Pablo Jul 23 '15 at 13:00
  • maybe have a look at the source code https://github.com/bashwork/pymodbus i would do it and try to see if there is anything that is like wait until time out then print response or whatever. but am at work now – jgr208 Jul 23 '15 at 13:23
  • yeah, I'll take a look later at the code – Pablo Jul 23 '15 at 14:56

1 Answers1

2

I can confirm that - pymodbus always waits for the timeout(1-3 seconds) even if it receives response from slave immediately(in my case 14ms). So I tested with minimalmodbus and received the response immediately.In my case up to 35 times per second when I tested it with a loop.

Edit: I found the reason - pymodbus waits for over 1000 bytes or timeout when using RTU protocol. They need to calculate expected bytes, and they have a fix for this, but this is not yet in the main branch(AFAIK). Check this post https://github.com/bashwork/pymodbus/issues/76 So if you really need to use pymodbus you could try the patches.

Milen
  • 21
  • 4