Wiki source code of Modbus

Last modified by Leo Wei on 2023/08/24 14:11

Hide last authors
Leo Wei 2.1 1 = {{id name="HModbus"/}}**Modbus ** =
2
3 == {{id name="HMODBUSRTUSlave28Allfunction29"/}}**MODBUS RTU Slave (All function)** ==
4
5 Select the protocol "Modbus RTU Slave (All Fuction)",
6
7 Then set baud rate, port, stop bits, data bits, parity.
8
9 {{id name="I1624342015914-382.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_9962725fe6d96551.png||alt="1624342015914-382.png" height="486" width="800"]]
10
11 == {{id name="HModbusMeter"/}}**Modbus Meter** ==
12
13 The following example is using the Linfee meter LNF96EY to demonstrate how to set up the Modbus communication.
14
15 ~1. Wiring the RS485 cable first. Because the pin 58 is A, the pin 59 is B for meter. Here we use the COM1 to connect. So the diagram like follows:
16
17 {{id name="ILinfeeTerminalDiagram.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_9dc7d30cb849e2d9.png||alt="LinfeeTerminalDiagram.png" height="247" width="400"]]
18
19 2. Check the specific Modbus parameter in the communication menu from LED display.
20
21 So from the following pictures, we can know the Meter Address is 85, Baud rate is 9600, CRC None.
22
23 **✎Note: **Meter address usually corresponding to the Modbus Slave Station No. on the Modbus communication.
24
25 {{id name="IMeterModbusAllView.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_66bbb0491f1f5d41.png||alt="MeterModbusAllView.png" height="563" width="1559"]]
26
27 3. Set up the communication in the Configuration tab.
28
29 Select the protocol as **ModBus RTU Slave (All Function)**. And set the communication parameters like below.
30
31 {{id name="IVNETCommunicationtabmeter.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_2eba156c5e1396f6.png||alt="VNETCommunicationtabmeter.png" height="521" width="1115"]]
32
33 4. Create new real-time monitoring tag accroding to Modbus manual
34
35 Enter the address we want to read from the meter. The following table is intercept part of the manual for Linfee Modbus manual.
36
37 **0x03/0x04 command data register address**:
38
39 | |=(% colspan="2" %)Address |=Description|=Data Format|=Data Length(Word)|=Remark
40 | HEX|DEC| | | | |
41 |0x00|0|Reserved| | | |
42 |0x02|2|Reserved| | | |
43 |0x04|4|Reserved| | | |
44 |0x06|6|Ua|float|2|Phase Voltage data, Unit V|
45 |0x08|8|Ub|float|2|Phase Voltage data, Unit V|
46 |0x0A|10|Uc|float|2|Phase Voltage data, Unit V|
47 |0x0C|12|Uab|float|2|Line Voltage data, Unit V|
48 |0x0E|14|Ubc|float|2|Line Voltage data, Unit V|
49 |0x10|16|Uca|float|2|Line Voltage data, Unit V|
50 |0x12|18|Ia|float|2|Phase Current data, Unit A|
51 |0x14|20|Ib|float|2|Phase Current data, Unit A|
52 |0x16|22|Ic|float|2|Phase Current data, Unit A|
53
54 **✎Note: **We usually use the Data Type 4 for read the Modbus registers(Function Code 03)
55
56 For example, here we want to read the Phase Voltage Ua (Modbus offset 0006), the Modbus register main No. requires input decimal number, and check whether the actual address has one address offset, so the tag configured like the following screenshot:
57
58 {{id name="IVNETModbusTagSettings.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_7877526885655e80.png||alt="VNETModbusTagSettings.png" height="506" width="1089"]]
59
60 {{id name="IVNETModbusTagByteSettings.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_201210d2a833f243.png||alt="VNETModbusTagByteSettings.png" height="515" width="1086"]]
61
62 **✎Note: **If the read value is incorrect, please check whether need to change the Byte order.
63
64 Set the Modbus Slave Station No.
65
66 {{id name="IModbusStationSettings.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_320a4cc3a9c5bc60.png||alt="ModbusStationSettings.png" height="509" width="1090"]]
67
68 If the communication is setup successfully, the tag will show green light.
69
70 {{id name="IMonitoringtaggreenlight.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_50f469bd5c5ad6b5.png||alt="Monitoringtaggreenlight.png" height="87" width="1089"]]
71
72 == {{id name="HMODBUSRTUMaster"/}}**MODBUS RTU Master** ==
73
74 Select the protocol "Modbus RTU Master",
75
76 Then set baud rate, port, stop bits, data bits, parity
77
78 {{id name="I1624348709622-711.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_9e7b9fa10822e419.png||alt="1624348709622-711.png" height="488" width="800"]]
79
80 **address list**
81
82 |=**Type**|=**Data Type**|=**Function code and description**
83 |(% rowspan="11" %)Word|(% rowspan="3" %)3|04 (Read Input Registers: Read the current binary value in one or more input registers)
84 |06 (write single register: write a binary value to a holding register)
85 |10 (write values to multiple addresses )
86 |(% rowspan="3" %)4|03 (read holding register: read current binary value in one or more holding registers)
87 |06 (write single register: write a binary value to a holding register)
88 |10 (write values to multiple addresses )
89 |(% rowspan="3" %)W6|03 (read holding register: read current binary value in one or more holding registers)
90 |06 (write single register: write a binary value to a holding register)
91 |10 (write values to multiple addresses )
92 |(% rowspan="2" %)W16|03 (read holding register: read current binary value in one or more holding registers)
93 |10 (write values to multiple addresses )
94 |(% rowspan="11" %)Bit|(% rowspan="3" %)0|01 (Read coil state)
95 |05 (Force a single coil to force the on/off state of a logic coil)
96 |0F (Write multiple bits, ie write continuously)
97 |(% rowspan="3" %)1|02 (Read the input state)
98 |05 (Force a single coil to force the on/off state of a logic coil)
99 |0F (Write multiple bits)
100 |(% rowspan="3" %)W5|01 (Read coil state to obtain the current state of a set of logic coils)
101 |05 (Force a single coil to force the on/off state of a logic coil)
102 |0F (Write multiple bits)
103 |(% rowspan="2" %)W15|01 (Read coil state to obtain the current state of a set of logic coils)
104 |0F (Write multiple bits)
105
106 == {{id name="HMODBUSTCPSlave28Allfunction29"/}}**MODBUS TCP Slave (All function)** ==
107
108 Supported series: MODBUS TCP controller
109
110 V-B0X works as MODBUS TCP MASTER connecting with TCP SLAVE
111
112 **1)V-BOX Setting**
113
114 |**Items**|**Settings**|**Note**
115 |Protocol|MODBUS TCP Slave (All function)|
116 |Connection|Ethernet|
117 |Port No.|502|
118 |PLC station No.|1|
119
120 **2)Address List**
121
122 |=**Type**|=**Data Type**|=**Function code & Description**
123 |(% rowspan="11" %)Word|(% rowspan="3" %)3|04 (read input register: read current binary value in one or more input registers)
124 |06 (write single register: write a binary value to a holding register)
125 |10 (write values to multiple addresses )
126 |(% rowspan="3" %)4|03 (read holding register: read current binary value in one or more holding registers)
127 |06 (write single register: write a binary value to a holding register)
128 |10 (write values to multiple addresses )
129 |(% rowspan="3" %)W6|03 (read holding register: read current binary value in one or more holding registers)
130 |06 (write single register: write a binary value to a holding register)
131 |10 (write values to multiple addresses )
132 |(% rowspan="2" %)W16|03 (read holding register: read current binary value in one or more holding registers)
133 |10 (write values to multiple addresses )
134 |(% rowspan="11" %)Bit|(% rowspan="3" %)0|01 (Read coil state)
135 |05 (Force a single coil to force the on/off state of a logic coil)
136 |0F (Write multiple bits, ie write continuously)
137 |(% rowspan="3" %)1|02 (Read the input state)
138 |05 (Force a single coil to force the on/off state of a logic coil)
139 |0F (Write multiple bits)
140 |(% rowspan="3" %)W5|01 (Read coil state to obtain the current state of a set of logic coils)
141 |05 (Force a single coil to force the on/off state of a logic coil)
142 |0F (Write multiple bits)
143 |(% rowspan="2" %)W15|01 (Read coil state to obtain the current state of a set of logic coils)
144 |0F (Write multiple bits)
145
146 **3)Communication Settings**
147
148 Configure V-BOX Ethernet IP in Networking Settings
149
150 {{id name="Iimage-20220902111833-3.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_548ec5c2e6a33a72.png||alt="image-20220902111833-3.png" height="639" width="1245"]]
151
152 Configure PLC Ethernet IP in Communication;
153
154 {{id name="Iimage-20220902111121-1.png"/}}[[image:xwiki_V-BOX_V-Net_Training_1+Communication_WebHome_6dfdd297f35c9501.png||alt="image-20220902111121-1.png" height="706" width="1674"]]
155
156 **4)Cable Wiring**
157
158 {{id name="Ihttps:2F2Fdocs.we-con.com.cn2Fbin2Fdownload2FPIStudio2F12.PLC2520protocols2FWebHome2F12.PLC2520Protocol_html_2297240b57346b2a.png3Fwidth3D40126height3D17026rev3D1.1-4"/}}[[image:https://docs.we-con.com.cn/bin/download/PIStudio/12.PLC%20protocols/WebHome/12.PLC%20Protocol_html_2297240b57346b2a.png?width=401&height=170&rev=1.1||alt="12.PLC Protocol_html_2297240b57346b2a.png" height="170" width="401"]]
159
160 == {{id name="HcommunicatewithVBinverter"/}}**communicate with VB inverter** ==
161
162 [[download link>>url:https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/%E9%80%9A%E8%AE%AF%E6%A1%88%E4%BE%8B/Communicate%20with%20VB%20inverter.zip]]