Wiki source code of MODBUS

Version 10.1 by Hunter on 2023/08/24 18:11

Show last authors
1 = {{id name="HMODBUS"/}}**MODBUS** =
2
3 == {{id name="HMODBUSRTUMaster"/}}**MODBUS RTU Master** ==
4
5 Supported Series: MODBUS RTU CONTROLLER
6
7 HMI works as MODBUS SLAVE connecting with MASTER
8
9 {{id name="I12.PLCProtocol_html_44425b313b0a6b96.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_3645c5ba4c05a452.png||alt="12.PLC Protocol_html_44425b313b0a6b96.png" height="571" width="544"]]
10
11 {{id name="I12.PLCProtocol_html_b56b9da32c3caaa.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_85ccbb313f48855e.png||alt="12.PLC Protocol_html_b56b9da32c3caaa.png" height="462" width="600"]]
12
13 {{id name="I12.PLCProtocol_html_67cd25458b9c72a6.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_bfd94293ad8a77a.png||alt="12.PLC Protocol_html_67cd25458b9c72a6.png" height="462" width="600"]]
14
15 **HMI Settings**
16
17 |**Items**|**Settings**|**Note**
18 |Protocol|MODBUS RTU Master|
19 |Connection|RS485/RS232|
20 |Baud rate|2400~~187500|
21 |Data bit|8|
22 |Parity|Even/ Odd/ None|
23 |Stop bit|1/2|
24 |Station No.|0~~255|
25
26 **Address List**
27
28 |**Type**|**HMI address**|**MODBUS code**|**Range**
29 |Bit|HDX3000.0~~HDX3499.15|0|0~~7999
30 |Word|HDW3500~~HDW7999|4|0~~4499
31
32 **Cable Wiring**
33
34 * **RS485**
35
36 {{id name="I12.PLCProtocol_html_68dfb6d383f0edd9.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_f7a20d394715b397.png||alt="12.PLC Protocol_html_68dfb6d383f0edd9.png" height="244" width="394"]]
37
38 {{id name="I12.PLCProtocol_html_cbeb90cb4faaa8bc.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_91c5a13aa75c9f40.png||alt="12.PLC Protocol_html_cbeb90cb4faaa8bc.png" height="244" width="394"]]
39
40 * **RS232**
41
42 {{id name="I12.PLCProtocol_html_9030ba679545793b.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_11602f9c716ff03c.png||alt="12.PLC Protocol_html_9030ba679545793b.png" height="241" width="387"]]
43
44 **✎Note:** COM3 only available in PI8000/PI9000 series.
45
46 == {{id name="HMODBUSRTUSlave28Allfunction292F28AllfunctionOneBaseAddress29"/}}**MODBUS RTU Slave (All function)/(All function OneBaseAddress)** ==
47
48 Supported Series: MODBUS RTU CONTROLLER
49
50 HMI works as MODBUS MASTER connecting with SLAVE.
51
52 The addresses in [All function] start from 0, while the addresses in [All function OneBaseAddress] start from 1 (offset 1).
53
54 {{id name="I12.PLCProtocol_html_7236139c887defad.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_c29b1655c7d0be6f.png||alt="12.PLC Protocol_html_7236139c887defad.png" height="571" width="544"]]
55
56 {{id name="I12.PLCProtocol_html_de80207f2b495c17.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_3b29445434f6fd5e.png||alt="12.PLC Protocol_html_de80207f2b495c17.png" height="462" width="600"]]
57
58 {{id name="I12.PLCProtocol_html_4e9e8eff81c7ff8b.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_d3708a3b4fedb1af.png||alt="12.PLC Protocol_html_4e9e8eff81c7ff8b.png" height="462" width="600"]]
59
60 **HMI Settings**
61
62 |**Items**|**Settings**|**Note**
63 |Protocol|MODBUS RTU Slave (All function)/( All function OneBaseAddress)|
64 |Connection|RS485/RS232|
65 |Baud rate|2400~~187500|
66 |Data bit|8|
67 |Parity|Even/ Odd/ None|
68 |Stop bit|1/2|
69 |PLC station No.|0~~255|
70
71 **Address List**
72
73 |**Type**|**Address Type**|**Function code & Description**
74 |(% rowspan="11" %)Word|(% rowspan="3" %)3|04 (read input register: read current binary value in one or more input registers)
75 |06 (write single register: write a binary value to a holding register)
76 |10 (write values to multiple addresses )
77 |(% rowspan="3" %)4|03 (read holding register: read current binary value in one or more holding registers)
78 |06 (write single register: write a binary value to a holding register)
79 |10 (write values to multiple addresses )
80 |(% rowspan="3" %)W6|03 (read holding register: read current binary value in one or more holding registers)
81 |06 (write single register: write a binary value to a holding register)
82 |10 (write values to multiple addresses )
83 |(% rowspan="2" %)W16|03 (read holding register: read current binary value in one or more holding registers)
84 |10 (write values to multiple addresses )
85 |(% rowspan="11" %)Bit|(% rowspan="3" %)0|01 (Read coil state)
86 |05 (Force a single coil to force the on/off state of a logic coil)
87 |0F (Write multiple bits, ie write continuously)
88 |(% rowspan="3" %)1|02 (Read the input state)
89 |05 (Force a single coil to force the on/off state of a logic coil)
90 |0F (Write multiple bits)
91 |(% rowspan="3" %)W5|01 (Read coil state to obtain the current state of a set of logic coils)
92 |05 (Force a single coil to force the on/off state of a logic coil)
93 |0F (Write multiple bits)
94 |(% rowspan="2" %)W15|01 (Read coil state to obtain the current state of a set of logic coils)
95 |0F (Write multiple bits)
96
97 **✎Note:**
98
99 * Modbus can also support getting bit from the word, which could access the address such as 100.1 and other formats.
100 * The function codes sent out are the same as those that read and write words.
101
102 **Station number for more than one slaves**
103
104 If there are more than one slaves connected to HMI, please set slave station number during editing address, as below shows.
105
106 {{id name="I12.PLCProtocol_html_31f028c6d80be344.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_fc449dbfe22ad042.png||alt="12.PLC Protocol_html_31f028c6d80be344.png" height="515" width="485"]]
107
108 **Cable Wiring**
109
110 * **RS485**
111
112 {{id name="I12.PLCProtocol_html_68dfb6d383f0edd9.png-1"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_f7a20d394715b397.png||alt="12.PLC Protocol_html_68dfb6d383f0edd9.png" height="244" width="394"]]
113
114 {{id name="I12.PLCProtocol_html_cbeb90cb4faaa8bc.png-1"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_91c5a13aa75c9f40.png||alt="12.PLC Protocol_html_cbeb90cb4faaa8bc.png" height="244" width="394"]]
115
116 * **RS232**
117
118 {{id name="I12.PLCProtocol_html_9030ba679545793b.png-1"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_11602f9c716ff03c.png||alt="12.PLC Protocol_html_9030ba679545793b.png" height="241" width="387"]]
119
120 **✎Note:** COM3 only available in PI8000/PI9000 series.
121
122 == {{id name="HModbusMeter"/}}**Modbus Meter** ==
123
124 The following example is using the Linfee meter LNF96EY to demonstrate how to set up the Modbus communication.
125
126 ~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:
127
128 {{id name="ILinfeeDiagram.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_f3d8fbc620ea29ad.png||alt="LinfeeDiagram.png" height="247" width="400"]]
129
130 2. Check the specific Modbus parameter in the communication menu from LED display.
131
132 So from the following pictures, we can know the Meter Address is 85, Baud rate is 9600, CRC None.
133
134 **✎Note: **Meter address usually corresponding to the Device No. in the PIStudio Communication settings.
135
136 {{id name="IMeterModbusAllView.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_66bbb0491f1f5d41.png||alt="MeterModbusAllView.png" height="563" width="1559"]]
137
138 3. Create new project and change the Communication settings.
139
140 Set the protocol as MODBUS RTU Slave (All Function), set Device No. as 85. And COM port setting as 9600, 1, 8, NONE.
141
142 {{id name="IPIStudioSetupMeterModbusPara.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_96a9aa900e56dda0.png||alt="PIStudioSetupMeterModbusPara.png" height="713" width="923"]]
143
144 4. Drag the numeric input into screen, and fill in the Modbus Address we want to read according to manual
145
146 The following table is intercept part of the manual for Linfee Modbus manual.
147
148 **0x03/0x04 command data register address**:
149
150 |=(% colspan="2" %)Address|=Description|=Data Format|=Data Length(Word)|=Remark
151 | HEX|DEC| | | |
152 |0x00|0|Reserved| | |
153 |0x02|2|Reserved| | |
154 |0x04|4|Reserved| | |
155 |0x06|6|Ua|float|2|Phase Voltage data, Unit V
156 |0x08|8|Ub|float|2|Phase Voltage data, Unit V
157 |0x0A|10|Uc|float|2|Phase Voltage data, Unit V
158 |0x0C|12|Uab|float|2|Line Voltage data, Unit V
159 |0x0E|14|Ubc|float|2|Line Voltage data, Unit V
160 |0x10|16|Uca|float|2|Line Voltage data, Unit V
161 |0x12|18|Ia|float|2|Phase Current data, Unit A
162 |0x14|20|Ib|float|2|Phase Current data, Unit A
163 |0x16|22|Ic|float|2|Phase Current data, Unit A
164
165 **✎Note: **We usually use the Address Type 4 for read the Modbus registers(Function Code 03)
166
167 For example, here we want to read the Phase Voltage Ua (Modbus offset 0006), the Address No. requires input decimal number, and check whether the actual address has one address offset, so the address set like the following screenshot:
168
169 {{id name="IMeterModbusPInumericSet.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_8f21315cf980dac4.png||alt="MeterModbusPInumericSet.png" height="668" width="498"]]
170
171 Set the Read-Write type for address, because meter only to measuring the data, so set it as read-only, and floating data format.
172
173 {{id name="IMeterModbusNumericInputFormat.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_c9487f2bc1a0fcbd.png||alt="MeterModbusNumericInputFormat.png" height="668" width="498"]]
174
175 Then download into HMI, if the HMI COM led is blinking and no timeout message show, which means the communication is setup successfully.
176
177 {{id name="IActualHMIModbusResult.jpg"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_9acd93defd987700.jpg||alt="ActualHMIModbusResult.jpg" height="1269" width="2068"]]
178
179 == {{id name="HMODBUSTCPSlave28Allfunction29"/}}**MODBUS TCP Slave (All function)** ==
180
181 Supported series: MODBUS TCP controller
182
183 Note: Although the protocol selected for the HMI is MODBUS TCP Slave, the HMI is working as a MODBUS TCP Master connected to TCP SLAVE.
184
185 {{id name="I12.PLCProtocol_html_8877cb7f39c2b607.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_f60f9949a273d61c.png||alt="12.PLC Protocol_html_8877cb7f39c2b607.png" height="571" width="544"]]
186
187 {{id name="I12.PLCProtocol_html_e7e1f06f127a9175.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_cab69662ac9743b6.png||alt="12.PLC Protocol_html_e7e1f06f127a9175.png" height="426" width="553"]]
188
189 {{id name="I12.PLCProtocol_html_60bbfe5de79417a6.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_9901791194910670.png||alt="12.PLC Protocol_html_60bbfe5de79417a6.png" height="163" width="553"]]
190
191 **HMI Setting**
192
193 |**Items**|**Settings**|**Note**
194 |Protocol|MODBUS TCP Slave (All function)|
195 |Connection|Ethernet|
196 |Port No.|502|
197 |PLC station No.|1|
198
199 **Address List**
200
201 |**Type**|**Register**|**Function code & Description**
202 |(% rowspan="11" %)Word|(% rowspan="3" %)3|04 (read input register: read current binary value in one or more input registers)
203 |06 (write single register: write a binary value to a holding register)
204 |10 (write values to multiple addresses )
205 |(% rowspan="3" %)4|03 (read holding register: read current binary value in one or more holding registers)
206 |06 (write single register: write a binary value to a holding register)
207 |10 (write values to multiple addresses )
208 |(% rowspan="3" %)W6|03 (read holding register: read current binary value in one or more holding registers)
209 |06 (write single register: write a binary value to a holding register)
210 |10 (write values to multiple addresses )
211 |(% rowspan="2" %)W16|03 (read holding register: read current binary value in one or more holding registers)
212 |10 (write values to multiple addresses )
213 |(% rowspan="11" %)Bit|(% rowspan="3" %)0|01 (Read coil state)
214 |05 (Force a single coil to force the on/off state of a logic coil)
215 |0F (Write multiple bits, ie write continuously)
216 |(% rowspan="3" %)1|02 (Read the input state)
217 |05 (Force a single coil to force the on/off state of a logic coil)
218 |0F (Write multiple bits)
219 |(% rowspan="3" %)W5|01 (Read coil state to obtain the current state of a set of logic coils)
220 |05 (Force a single coil to force the on/off state of a logic coil)
221 |0F (Write multiple bits)
222 |(% rowspan="2" %)W15|01 (Read coil state to obtain the current state of a set of logic coils)
223 |0F (Write multiple bits)
224
225 **Communication Settings**
226
227 Enable HMI Ethernet in [Project Settings];
228
229 {{id name="I12.PLCProtocol_html_43b671f18153910d.png-3"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_a98ee09dac36eba3.png||alt="12.PLC Protocol_html_43b671f18153910d.png" height="107" width="405"]]
230
231 Set PLC IP in [Device IP] settings;
232
233 {{id name="I12.PLCProtocol_html_4bd3cc8348adecf8.png"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_fe148ed3657d30a.png||alt="12.PLC Protocol_html_4bd3cc8348adecf8.png" height="190" width="554"]]
234
235 **Cable Wiring**
236
237 {{id name="I12.PLCProtocol_html_2297240b57346b2a.png-2"/}}[[image:xwiki_PIStudio_12.PLC+protocols_WebHome_ac8ece9a26719fda.png||alt="12.PLC Protocol_html_2297240b57346b2a.png" height="170" width="401"]]