from pymodbus import factory, transactionfrom pymodbus.client import asyncdecoder = factory.ClientDecoder()framer = transaction.ModbusRtuFramer(decoder)client_protocol = async.ModbusClientProtocol(framer)
If you prefer to use the sync client, youcould create a subclass of ModbusTcpClient and override its __init__method. Try to replace
BaseModbusClient.__init__(self, ModbusSocketFramer(ClientDecoder()))
with
BaseModbusClient.__init__(self, ModbusRtuFramer(ClientDecoder()))
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.transaction import ModbusRtuFramer
client = ModbusClient(’localhost’, port=5020, framer=ModbusRtuFramer)
client.read_holding_registers(7,20,unit=1)
client = ModbusClient(’x.x.x.x', port=5020, framer=ModbusRtuFramer)
gives me this error
Exception AttributeError: "'ModbusTcpClient' object has no attribute 'socket'" in <bound method ModbusTcpClient.__del__ of <pymodbus.client.sync.ModbusTcpClient object at 0x7f0e54f9a250>> ignored Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() got an unexpected keyword argument 'framer'
If I do this instead
>>>client = ModbusClient()
>>> client.framer
<pymodbus.transaction.ModbusSocketFramer object at 0x2064610>
>>> client.framer = ModbusRtuFramer
>>> client.host = 'x.x.x.x'
>>> client.port = 20002
>>> client.connect()
True
--
You received this message because you are subscribed to the Google Groups "pymodbus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymodbus+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.