Modbus TCP v1

This commit is contained in:
2026-06-11 15:44:27 -05:00
parent 70cd36c934
commit b18ac04bf8
48 changed files with 14508 additions and 16204 deletions

View File

@@ -1,42 +1,98 @@
This is a simplified version of Modbus TCP that allows PICS to simulate the equipment:
Modbus TCP (CSV Configuartion):
- All you need to do to get this running is going into the spiffs folder and open Objects.csv
- You wil create your Modbus Register Map, this will based on the equipment or UDTs
- For Input Coil & Input Registers, you will need to create a Output Coil & Holding Register to edit the value
- Once you modify the Objects.csv file, build and flash the program into the ESP32 board
- Go to TOP Server and add the Modbus TCP/IP device
For PICS:
- Create an I/O Connection, Set it as OPC Client, choose TOPServer
- To add the Modbus Device (ESP32), create an I/O Variable, Name the I/O
1. Start Here!
a. Go into the "spiffs" folder and open "device_config.ini"
- Under Address, you will follow how Ignition UDT works.
- Device Channel . Device . Tag Name (Address)
- EX: DFW2_DC3_COD_A11_CH.DFW2_DC3_COD_A11.30001
b. Under [wifi] you will enter the SSID (Name) of your wifi router
and password.
- You will be able to view the data or edit the value
c. Setup the "static_ip" of the device, "gateway" of the network (router)
and leave "netmask" as default (255.255.255.0).
d. Under [modbus] leave port as default (502), leave max_clients as default (10)
and modify "device_count" to the max amount of devices you want to simulate
- Note: This will be based on the size of the modbus mapping you will use, the larger
the larger the mapping the more memory, the less devices you can simulate.
e. Under [device 1], use this as a template to add devices, leave "enabled" as default (1),
modify "unit_id", do not have duplicate IDs, "name" has to follow Deivce_x, "csv" will match the
csv file mapping you created or copied over.
2. Creating CSV Files for Modbus TCP devices
a. In the "spiffs" folder, there is a csv file called "Tempalte.csv"
- Use this as reference on how to create your devices
type,address,name,data_type,control_address,pics_address,pics_data_type,notes
Objects.csv Template / Example:
type: Can be an Input Coil (Input), Output Coil (Output), Input Holding Register (Input_Holding), or Output Holding Register (Holding_Reg)
address: Modbus Register, Inputs: 1 - 9999, Outputs: 10000 - 19999, Input_Holding: 30000 - 39999, Holding_Reg: 40000 - 49999 (They can be 6 digits long as well)
name: Name of Modbus Register
data_type: bool, uint16, float, uint32, double
control_address: Address of Ouput or Holding_Reg that will control this Input; if it's an output leave it blank
notes: Any text that will help you identify it
b. For Column "type" this will be the Modbus Register type
- Coil
- Discrete_Input
- Input_Register
- Holding_Register
c. For Column "address", you will enter the modbus register , can be 5 digits or 6 digits
- Coil: 00001 -> 09999 or 000001 -> 099999
- Discrete_Input: 10001 -> 19999 or 100001 -> 199999
- Input_Register: 30001 -> 39999 or 300001 -> 399999
- Holding_Register: 40001 -> 49999 or 400001 -> 499999
type,address,name,data_type,control_address,notes
Coil,1,DI1,bool,10005,Digital Input 1
Discrete_Input,10005,DO1,bool,,Digital Output 2
Input_Register,320315,AI1,uint16,465921,Analog Input 1
Holding_Register,465921,AO1,uint16,,Analog Output 1
d. For Column "name", enter the name of that point, can be whatever you want
e. For Column "data_type", this will be the type of data the point represents
- Coil: bool only
- Discrete_Input: bool only
- Input_Register: uint16, uint32, or float
- Holding_Register: uint16, uint32, or float
f. For Column "control_address", this is only for registers that are read only (inputs)
- Create a counterpart of that input and type in the "address" of that point into "control_address"
- For Example: Discrete_Input,10001,DI_1,bool,00001,,,,
Coil,00001,DI_1_Ovr,bool,,,,,
Input_Register,30001,AI_1,uint16,40001,,,,
Holding_Register,40001,AI_1_Ovr,uint16,,,,
g. For Column "pics_address", this will be the address PICS uses to modify the data
- You cannot use the modbus register (address) as PICS write the data in this fashion
- Recommended default start is 410001
- Also you do not need to add this address on Coil data types as it's 1 for 1
- This is primarly needed for Holding_Register
- PICS Data:
- Boolean = sends data in 1 register
- Integer = sends data in 2 registers
- Float = sends data in 4 registers
h. For Column "pics_data_type", the type of data pics is sending to that modbus register
- Look at g. for the PICS Data.
i. For Column "notes", enter notes to help you understand the purpose of that modbus register
3. Increasing Modbus MAX Points
a. Once you complete your device csv file, head to "main" -> "modbus_points.h"
b. At the very top of the file, find "#define MODBUS_MAX_POINTS"
- Modify this value based on the maximum registers needed for your device
4. Starting Modbus TCP Device
a. Once you complete setting up the device, you are ready to flash the device
b. Download ESP32 IDF from Espressif Systems
Link: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/windows-setup.html
Install the EIM, follow the easy installation
c. Once in the dashboard, click on open IDF terminal
d. Run these commands:
- cd "Location the program is stored at"
- idf.py fullclean
- idf.py build
- idf.py -p COM# flash monitor (COM# is the COM port number, look in Device Manager -> Ports)
5. Verify with Modscan32