RTU sync timeout problem

1,069 views
Skip to first unread message

abramjs

unread,
Jun 27, 2012, 11:55:53 AM6/27/12
to pymo...@googlegroups.com
Good morning guys and thank you for this library.

I'm trying to control a machine using Modbus RTU protocol. Now I only need to read multiple holding registers. So I tried sync version of PyModbus Client and it worked. 
BUT I've a problem caused by the timeout of the client. It seems that the client waits for a response that some time doesn't arrived from the machine and it returns an error. 

This is my code:

from pymodbus.client.sync import ModbusSerialClient as ModbusClient

def biomasseQuery(COMport, regIndex, numRegisters, slaveUnit):

    client = ModbusClient(port=COMport,stopbits=1,bytesize=8,parity='N',baudrate=9600, method='rtu')
    client.connect() 
    result = client.read_holding_registers(regIndex, numRegisters, unit=slaveUnit)
    return result


And I recall it in the main:

...
   query = biomasseQuery(COMport, reg_index, reg_numbers, SLAVEaddress)
   value = query.registers[i]
...

my questions are: 
1. The time elapsed between a request of the client and the next one is too long. How can I shorten this time? 
2. How can I implement a check on missing responses of the machine (the execution has to go on)?
3. Could the async implementation be the solution? I could implement it? (example pleazz)

thx in advance

Bashwork

unread,
Jun 29, 2012, 2:28:44 PM6/29/12
to pymo...@googlegroups.com
So there are a number of parameters to the serial client (I apparently don't have completely documented) that are actually just forwarded to the python Serial library.  The one you are looking for is "timeout" which is set by default to 3 seconds.

So what do you mean on missing responses.  If there was an error an exception will be raised.  If the library was not able to get a response the the allotted amount of time or gave up sending the request, None should be returned.

You can use the async version if you are doing a polling kind of action (read server, send result to another system and repeat).  Here is an example of an async client: https://groups.google.com/d/msg/pymodbus/40wbM-AL-fQ/Ihqzf4zYDbkJ

J. Archer

unread,
Jul 9, 2012, 4:50:41 AM7/9/12
to pymo...@googlegroups.com
Hi everybody!

I'm working on the same project together with abramjs.

I would like to know how to implement the async version of the Modbus RTU serial client. The provided documentation lacks information about it (it only explains how to setup a modbus over TCP client).

I've tried to use the functional example asynchronous-rtu-client.py under examples/functional folder, but it cannot find the module called ModbusSerialClient (it actually seems to be inexistent within async.py code, only ModbusClientProtocol exists).

The documentation tells about a client factory, but I cannot understand how to make it work in order to obtain a RTU serial client with custom parameters set up (e.g. number of COM port,  baud rate, slave address etc.).

Anyone could help, please?

Thank you.

Bashwork

unread,
Jul 12, 2012, 5:26:56 PM7/12/12
to pymo...@googlegroups.com
J. Archer,

Sorry about that, those are actually functional test placeholders (I haven't gotten around to filling them all in yet).  The example at the following URI should be a pretty complete example for your usage:

Reply all
Reply to author
Forward
0 new messages