The ModbusServer project integrates a Modbus TCP server with a Flask-based HTTP API, enabling users to read from and write to Modbus registers via HTTP requests. This solution is designed to facilitate interaction with Modbus devices over the network, making it suitable for various applications in automation, IoT, and industrial control systems.
- Modbus TCP Server: Hosts a Modbus server for interaction with Modbus clients and devices.
- Flask HTTP API: Provides HTTP endpoints to read and write Modbus register values.
- Concurrent Operation: Runs both Modbus and HTTP servers concurrently, allowing simultaneous Modbus and web interactions.
- Python 3.6 or higher
- pip for Python 3
-
Clone the Repository
git clone https://example.com/ModbusServer.git cd ModbusServer
-
Setup a Virtual Environment (Optional but recommended)
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies
pip install -r requirements.txt
-
Start the Server
python server.py
This command starts both the Modbus TCP server on port 5020 and the Flask HTTP server on port 5000.
Connect to the Modbus TCP server using any Modbus TCP client on port 5020.
-
Read Modbus Registers
Send a GET request to
http://localhost:5000/modbus
to read values from predefined Modbus registers. -
Write to Modbus Registers
Send a POST request to
http://localhost:5000/modbus
with a JSON payload specifying the register values to write, e.g.,{ "1": 100, "2": 50, "3": 25 }
Contributions to the ModbusServer project are welcome. Please follow the standard fork-pull request workflow on GitHub to submit your changes.