This repository contains two Python files for communicating with Modbus devices using different protocols: Modbus TCP/IP and Modbus RTU.
This file provides a Python class ModbusTCPClient
for communicating with Modbus devices over TCP/IP protocol.
-
Ensure you have the required Python packages installed:
pymodbus
. -
Modify the
MODBUS_IP
variable in the usage example to match the IP address of your Modbus device. -
Run the script to send data to the Modbus TCP/IP device.
This file provides a Python class ModbusRTUClient
for communicating with Modbus devices over RTU (Remote Terminal Unit) protocol.
-
Ensure you have the required Python packages installed:
pymodbus
. -
Modify the
port
variable in the usage example to match the serial port connected to your Modbus RTU device. -
If your Modbus RTU device requires a specific slave address, you need to set it in the
slave_address
parameter of theModbusRTUClient
class initialization. This address corresponds to the Modbus device's address on the RS-485 network. For example:# Create an instance of the ModbusRTUClient class modbus_client = ModbusRTUClient(port='COM2', slave_address=1)
-
Run the script to read and write data to the Modbus RTU device.
This file provides a Python class ModbusRTUOVERTCPClient
for communicating with Modbus devices over RTU (Remote Terminal Unit) protocol via TCP/IP.
-
Ensure you have the required Python packages installed using the provided
requirements.txt
file.pip install -r requirements.txt
-
Modify the server_ip variable in the usage example to match the IP address of your Modbus TCP server.
-
Run the script to read and write data to the Modbus RTU device over TCP/IP.
This file provides a Python class ModbusConnection
for communicating with Modbus devices over RTU with minimalmodbus.
-
Ensure you have the required Python packages installed using the provided
requirements.txt
file.pip install -r requirements.txt
-
Modify the necessary parameters like port,slave_id and baud_rate and run.
Feel free to update the scripts and usage examples as needed for your specific Modbus devices and configurations.