Modbus RTU over TCP Master Example

408 views
Skip to first unread message

Ken Boyd

unread,
Mar 19, 2021, 1:09:41 PM3/19/21
to modbus-tk
Good Day All,

Does anyone have an example how to setup .py for RTUoverTCPMaster Server?


import sys
import modbus_tk
import modbus_tk.defines as cst
from modbus_tk import modbus_tcp
from modus_tk import modbus_rtu_over_tcp

def main():
"""main"""
logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s")
try:

#Create the server
server = ????????


logger.info("running...")
logger.info("enter 'quit' for closing the server")

Júnior Ferraz

unread,
Apr 1, 2021, 1:21:49 AM4/1/21
to modbus-tk
Here is an example:

from modbus_tk import modbus_rtu_over_tcp
import modbus_tk.defines as cst # cst = constants

unit = 1
port = 1234

#it read data of registrator 64000 until 64008
client = modbus_rtu_over_tcp.RtuOverTcpMaster(host=host,port=port,timeout_in_sec=10)
read_input_data = client.execute(slave=unit, function_code=cst.READ_INPUT_REGISTERS, starting_address=64000, quantity_of_x=9) 


#it write the values 77,88,99 (its in a list because you can write multiple values) on register 64001,64002 and read the informarion at 64100 until 64108.
read_write_data = client.execute(slave=unit, function_code=cst.READ_WRITE_MULTIPLE_REGISTERS, starting_address=64100, quantity_of_x=9, output_value=[77,88,99], write_starting_address_FC23=64000) 


Ken Boyd

unread,
Apr 1, 2021, 7:55:54 AM4/1/21
to modb...@googlegroups.com
Thank You!

Ken B

--
You received this message because you are subscribed to the Google Groups "modbus-tk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modbus-tk+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modbus-tk/a41210da-75f7-4be5-901b-558c015573bcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages