AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 81 forks source link

Modbus RTU over TCP #91

Closed azat385 closed 3 years ago

azat385 commented 4 years ago

Hello!

Is it possible to use rtu frame over TCP connection? Slave rtu device is connected to pc via moxa nport 5150 through the ethernet. (Nport is changing just interface but not the messages)

Thanks a lot!

tiagocoutinho commented 3 years ago

@azat385 ,

You can create a Serial object which talks to moxa via raw socket or even RFC 2217 (I think moxa supports both in all models). I recommend you use raw socket unless you need to change the serial line settings frequently (like using different baudrate)

Here is an example:

import serial
from umodbus.client.serial import rtu

serial_port = serial.serial_for_url("socket://moxa.acme.org:6610")
message = rtu.write_multiple_coils(slave_id=1, address=1, values=[1, 0, 1, 1])
response = rtu.send_message(message, serial_port)

serial_port.close()

Hope it helps.

azat385 commented 3 years ago

@tiagocoutinho thanks a lot !