On Fri, Jul 22, 2011 at 07:21:07AM -0700, StephenL wrote:
> Hi, all. For a particular type of Modbus device we need to support,
> rather than supporting Modbus TCP directly it supports Modbus RTU over
> TCP. For some Modbus GUI clients (such as the SimplyModbus client),
> this is an option.
The kind of frames handled by a client are defined at initialization time with
the "framer" parameter. Here is a code fragment that initializes a Modbus TCP
client with an RTU framer:
from pymodbus import factory, transaction
from pymodbus.client import async
decoder = factory.ClientDecoder()
framer = transaction.ModbusRtuFramer(decoder)
client_protocol = async.ModbusClientProtocol(framer)
I haven't been able to test if this actually works - please use it as basis for
your own experiments ;-). If it does work, please report back to the list; it would
be good to know that the flexibility of the framework allows to handle such
"exotic" cases, too.
Best regards,
Albert
--
Albert Brandl
Weiermayer Solutions GmbH | Abteistra�e 12, A-4813 Altm�nster
phone: +43 (0) 720 70 30 14 | fax: +43 (0) 7612 20 3 56
web: http://www.weiermayer.com
On Mon, Jul 25, 2011 at 06:13:09AM -0700, StephenL wrote:
Sorry for the delay - the last weeks were quite stressful, and this is
not likely to change soon :-(
> from pymodbus.client.sync import ModbusTcpClient as ModbusClient
> client = ModbusClient('127.0.0.1')
>
> Given your code above, does one then need to set the ModbusTcpClient
> with this client_protocol variable you've established?
No, my example used the asynchronous client. In the synchronous version,
the framer to be used is hardcoded (see the __init__ method of the class
ModbusTcpClient in sync.py). If you prefer to use the sync client, you
could create a subclass of ModbusTcpClient and override its __init__
method. Try to replace
BaseModbusClient.__init__(self, ModbusSocketFramer(ClientDecoder()))
with
BaseModbusClient.__init__(self, ModbusRtuFramer(ClientDecoder()))
> Also, SimplyModbus says (http://www.simplymodbus.ca/TCP.htm):
> ***
> Modbus RTU over TCP
> Simply put, this is a Modbus RTU message transmitted with a TCP/IP
> wrapper and sent over a network instead of serial lines. The Server
> does not have a SlaveID since it uses an IP Address instead.
> ***
>
> Does that correspond with what you were saying about the Modbus TCP
> client with the RTU framer in pymodbus?
I think so. But YMMV ;-)
> Thanks again for your help,
> Stephen
You're welcome.
Best regards,
This is certainly better than using a not widely used (and untested)
feature. Nevertheless it was interesting to see that the framework is
extensible enough to support RTU frames sent over TCP...
>... pymodbus is working very well reading it.
Cool. If any questions or problems arise, please ask them on the mailing
list. Just out of curiosity: do you still use the synchronous client, or
the async version?
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-2-1ee1f1a2e5c3> in <module>() 7 rtu_framer = transaction.ModbusRtuFramer(decoder) 8 ----> 9 client = ModbusClient(host="192.168.0.104", port=502, framer=rtu_framer) C:\Users\Dell\Anaconda\lib\site-packages\pymodbus\client\sync.pyc in __init__(self, host, port, framer) 126 self.port = port 127 self.socket = None --> 128 BaseModbusClient.__init__(self, framer(ClientDecoder())) 129 130 def connect(self): TypeError: 'ModbusRtuFramer' object is not callable
Do you know maybe what I did wrong?
Best Regards,
Michał