Wiki source code of 07 Communication

Version 16.1 by Devin Chen on 2024/03/22 10:03

Hide last authors
Mora Zhou 11.1 1 = **PLC COM2 Modbus RTU** =
Leo Wei 1.1 2
Stone Wu 5.1 3 == **Protocol Setting (D8126)** ==
Leo Wei 1.1 4
Leo Wei 2.1 5 |=(% scope="row" %)**Protocol**|=**Description**|=**Value of D8126**
6 |=WECON PLC Protocol|Using WECON PLC Protocol|01H
7 |=MODBUS RTU Master|PLC is slave device|02H
8 |=MODBUS ASCII Master|PLC is slave device|03H
Devin Chen 12.1 9 |=User-defined Protocol|Using User-defined Protocol|10H
Leo Wei 2.1 10 |=MODBUS RTU Slave|PLC is master device|20H
11 |=MODBUS ASCII Slave|PLC is master device|30H
Leo Wei 1.1 12
Stone Wu 5.1 13 == **Communication format (D8120)** ==
Leo Wei 1.1 14
15 (% border="1" %)
16 |(% rowspan="2" %)**Item**|(% rowspan="2" %)**parameter**|(% colspan="8" %)**Bit value of D8120**
17 |**b7**|**b6**|**b5**|**b4**|**b3**|**b2**|**b1**|**b0**
18 |(% rowspan="6" %)(((
19
20
21
22 Baud rate
23
24 (Bps)
25 )))|115200|1|1|0|0|-|-|-|-
26 |57600|1|0|1|1|-|-|-|-
27 |38400|1|0|1|0|-|-|-|-
28 |19200|1|0|0|1|-|-|-|-
29 |9600|1|0|0|0|-|-|-|-
30 |4800|0|1|1|1|-|-|-|-
31 |(% rowspan="2" %)Stop bit|1 bit|-|-|-|-|0|-|-|-
32 |2 bit|-|-|-|-|1|-|-|-
33 |(% rowspan="3" %)(((
34
35
36 Parity
37 )))|None|-|-|-|-|-|0|0|-
38 |Odd|-|-|-|-|-|0|1|-
39 |Even|-|-|-|-|-|1|1|-
40 |(% rowspan="2" %)Data bit|7 bit|-|-|-|-|-|-|-|0
41 |8 bit|-|-|-|-|-|-|-|1
Stone Wu 4.1 42 |(% colspan="10" %)Example: the communication format is 9600.1.8.None, b7b6b5b4=1000, b3=0, b2b1=00, b 0=1. D8120=81H ( (10000001),,2,,=81H, 81H means hexadecimal number)
Leo Wei 1.1 43
Stone Wu 5.1 44 (% class="box infomessage" %)
45 (((
Leo Wei 1.1 46 **✎Note:** If use Data bit=7.Parity can not choose None.
Stone Wu 5.1 47 )))
Leo Wei 1.1 48
Stone Wu 5.1 49 == **WECON PLC - MODBUS (Slave) addresses rules** ==
Leo Wei 1.1 50
51 (% border="1" %)
52 |(% colspan="3" %)** PLC Bit Address**
53 |(% rowspan="2" %)PLC Address|(% colspan="2" %)MODBUS Address
54 |Hex|Decimal
55 |M0 ~~ M3071|0 ~~ 0xBFF|0 ~~ 3071
56 |M8000 ~~ M8256|0x1F40 ~~ 0x2040|8000 ~~ 8256
57 |S0 ~~ S999|0xE000 ~~ 0xE3E7|57344 ~~ 58343
58 |T0 ~~ T256|0xF000 ~~ 0xF100|61440 ~~ 61696
59 |C0 ~~ C255|0xF400 ~~ 0xF4FF|62464 ~~ 62719
Jim 9.1 60 |X0 ~~ X377|0xF800 ~~ 0xF8FF|63488 ~~ 63743
Jim 10.1 61 |Y0 ~~ Y377|0xFC00 ~~ 0xFCFF|64512 ~~ 64767
Stone Wu 6.1 62 |(% colspan="3" %)** PLC Word Address**
Leo Wei 1.1 63 |(% rowspan="2" %)PLC Address|(% colspan="2" %)MODBUS Address
64 |Hex|Decimal
65 |D0 ~~ D8255|0 ~~ 0x203F|0 ~~ 8255
66 |T0 ~~ T255|0xF000 ~~ 0xF0FF|61440 ~~ 61695
67 |C0 ~~ C199|0xF400 ~~ 0xF4C7|62464 ~~ 62663
68 |C200 ~~ C255|0xF700 ~~ 0xF7FF|63232 ~~ 63487
69
Stone Wu 8.1 70 == **MODBUS function code introduction** ==
Leo Wei 1.1 71
Stone Wu 5.1 72 **Function code 0x01(01): read coil (bit address)**
Leo Wei 1.1 73
74 Frame format: Station number of slave&0x01 + start address + number of coils + CRC
75
76 (% border="1" %)
77 |No.|(% style="width:352px" %)Data|(% style="width:252px" %)Number of byte|Instruction
78 |1|(% style="width:352px" %)Station number of slave|(% style="width:252px" %)1 byte|Value range 1~~247, set by D8121
79 |2|(% style="width:352px" %)0x01(function code)|(% style="width:252px" %)1 byte|Read coil
80 |3|(% style="width:352px" %)Start address|(% style="width:252px" %)2 bytes|
81 |4|(% style="width:352px" %)Number of coils|(% style="width:252px" %)2 bytes|
82 |5|(% style="width:352px" %)CRC|(% style="width:252px" %)2 bytes|
83
Stone Wu 5.1 84 **Function code 0x03(03): read register (word address)**
Leo Wei 1.1 85
86 Frame format: Station number of slave&0x03 + start address+ number of registers + CRC
87
88 (% border="1" %)
89 |No.|Data|Number of byte|Instruction
90 |1|Station number of slave|1 byte|Value range 1~~247, set by D8121
91 |2|0x03 (function code)|1 byte|Read register
92 |3|Start address|2 bytes|
93 |4|Number of registers|2 bytes|
94 |5|CRC|2 bytes|
95
Stone Wu 5.1 96 **Function code 0x05(05): write single coil**
Leo Wei 1.1 97
98 Frame format: Station number of slave&0x05 + address + state of coil + CRC
99
100 (% border="1" %)
101 |No.|Data|Number of byte|Instruction
102 |1|Station number of slave|1 byte|Value range 1~~247, set by D8121
103 |2|0x05 (function code)|1 byte|Write single coil
104 |3|address|2 bytes|
105 |4|State of coil|2 bytes|
106 |5|CRC|2 bytes|
107
Stone Wu 5.1 108 **Function code 0x06 (06): Write single register**
Leo Wei 1.1 109
110 Frame format: Station number of slave&0x06 + address + value + CRC
111
112 (% border="1" %)
113 |No.|Data|Number of byte|Instruction
114 |1|Station number of slave|1 byte|Value range 1~~247, set by D8121
115 |2|0x06 (function code)|1 byte|Write single register
116 |3|address|2 bytes|
117 |4|Value of register|2 bytes|
118 |5|CRC|2 bytes|
119
Stone Wu 5.1 120 **Function code 0x0f(15): Write continuous coils**
Leo Wei 1.1 121
122 Frame format: Station number of slave&0x0f + start address + number of coils + length + state of coil + CRC
123
124 (% border="1" %)
125 |No.|Data|Number of byte|Instruction
126 |1|Station number of slave|1 byte|Value range 1~~247, set by D8121
127 |2|0x0f (function code)|1 byte|Write contunuous coils
128 |3|Start address|2 bytes|
129 |4|Number of coil|2 bytes|
130 |5|Length|1 bytes|
131 |6|State of coils|[(N+7)/8] bytes|
132 |7|CRC|2 bytes|
133
Stone Wu 5.1 134 **Function code 0x10 (10): Write continuous registers**
Leo Wei 1.1 135
136 Frame format: Station number of slave&0x10 + start address + number of registers + length + value of register + CRC
137
138 (% border="1" %)
139 |No.|Data|Number of byte|Instruction
140 |1|Station number of slave|1 byte|Value range 1~~247, set by D8121
141 |2|0x10 (function code)|1 byte|Write contunuous registers
142 |3|Start address|2 bytes|
143 |4|Number of registers|2 bytes|
144 |5|Length|1 bytes|
145 |6|Value of register|N*2 bytes|
146 |7|CRC|2 bytes|
147
Stone Wu 5.1 148 == **Example** ==
Leo Wei 1.1 149
Stone Wu 5.1 150 **Read bit address from device**
Leo Wei 1.1 151
Stone Wu 5.1 152 (When reading the bit address, the return value of 256 means that the coil is turned ON, and the return value of 0 means that the coil is turned OFF.)
Leo Wei 1.1 153
154 (% style="text-align:center" %)
Stone Wu 5.1 155 [[image:1641781999957-637.png||height="390" width="750" class="img-thumbnail"]]
Leo Wei 1.1 156
Stone Wu 5.1 157 **Read word address from device**
Leo Wei 1.1 158
159 (% style="text-align:center" %)
Stone Wu 5.1 160 [[image:1641782024282-424.png||height="439" width="750" class="img-thumbnail"]]
Leo Wei 1.1 161
Stone Wu 5.1 162 **Write single coil**
Leo Wei 1.1 163
164 (% style="text-align:center" %)
Stone Wu 5.1 165 [[image:1641782057319-761.png||height="440" width="750" class="img-thumbnail"]]
Leo Wei 1.1 166
Stone Wu 5.1 167 Tip: (When writing a single coil or a continuous coil, write HFF00 to turn the coil on, and write H0000 to turn off the coil.)
Leo Wei 1.1 168
Stone Wu 5.1 169 **Write single register**
Leo Wei 1.1 170
171 (% style="text-align:center" %)
Stone Wu 5.1 172 [[image:1641782078927-432.png||height="442" width="750" class="img-thumbnail"]]
Leo Wei 1.1 173
Stone Wu 5.1 174 **Write continuous coils**
Leo Wei 1.1 175
176 (% style="text-align:center" %)
Stone Wu 5.1 177 [[image:1641782101687-540.png||height="452" width="750" class="img-thumbnail"]]
Leo Wei 1.1 178
Stone Wu 5.1 179 **Write continuous registers**
Leo Wei 1.1 180
181 (% style="text-align:center" %)
Stone Wu 5.1 182 [[image:1641782118748-978.png||height="448" width="750" class="img-thumbnail"]]
Leo Wei 1.1 183
Stone Wu 5.1 184 **PLC is slave devic**
Leo Wei 1.1 185
186 [[image:1641782203514-616.png||height="230" width="746"]]
187
188
Stone Wu 6.1 189 **WECON PLC Protocol (COM2)**
Leo Wei 1.1 190
191 [[image:1641782240401-942.png||height="161" width="754"]]
192
Mora Zhou 11.1 193 = (% style="color:inherit; font-family:inherit" %)**N:N network**(%%) =
Leo Wei 1.1 194
195 **LX3VP COM2 N:N Application**
196
Stone Wu 5.1 197 == **LX3VP COM2 N:N Connection** ==
Leo Wei 1.1 198
Devin Chen 13.1 199 PLC built-in N:N connection protocol provides an effective way to exchange data among multiple PLC (Max. 8 devices). Technically, it only requires the twisted pair RS485 cable to connect with each PLC COM2 (in parallel).
Leo Wei 1.1 200
201 (% style="text-align:center" %)
Stone Wu 5.1 202 [[image:9.Communication example_html_8c43baa1ae891689.jpg||height="142" width="500" class="img-thumbnail"]]
Leo Wei 1.1 203
Stone Wu 6.1 204 == **COM2 N:N Instructions  ** ==
Leo Wei 1.1 205
206 User should put data to specified register unit. Exchanging the data among PLCs, This function only requires putting data in preset register block, all the data in this register block would share with other PLCs. There are five modes for choice, according to data volume and communication speed. See the preset register block from table below.
207
208 (% border="1" %)
209 |(% colspan="2" rowspan="3" %)**Station Number**|(% colspan="2" %)**Mode 0**|(% colspan="2" %)**Mode 1**|(% colspan="2" %)**Mode 2**
210 |**Bit (M)**|**Word(D)**|**Bit (M)**|**Word(D)**|**Bit (M)**|**Word(D)**
211 |**0**|**4**|**32**|**4**|**64**|**8**
212 |Master|NO. 0|~-~-|0-3|1000-1031|0-3|1000-1063|0-7
213 |(% rowspan="7" %)Slave|NO. 1|~-~-|32-35|1064-1095|32-35|1064-1127|32-39
214 |NO. 2|~-~-|64-67|1128-1159|64-67|1128-1191|64-71
215 |NO. 3|~-~-|96-99|1192-1223|96-99|1192-1255|96-103
216 |NO. 4|~-~-|128-131|1256-1287|128-131|1256-1319|128-135
217 |NO. 5|~-~-|160-163|1320-1351|160-163|1320-1383|160-167
218 |NO. 6|~-~-|192-195|1384-1415|192-195|1384-1447|192-199
219 |NO. 7|~-~-|224-227|1448-1479|224-227|1448-1511|224-231
220 |(% colspan="2" rowspan="3" %)**Station Number**|(% colspan="2" %)**Mode 3**|(% colspan="2" %)**Mode 4**| |
221 |**Bit (M)**|**Word(D)**|**Bit (M)**|**Word(D)**| |
222 |**64**|**16**|**64**|**32**| |
223 |Master|NO. 0|1000-1063|0-15|1000-1063|0-31| |
224 |(% rowspan="7" %)Slave|NO. 1|1064-1127|32-47|1064-1127|32-63| |
225 |NO. 2|1128-1191|64-79|1128-1191|64-95| |
226 |NO. 3|1192-1255|96-111|1192-1255|96-127| |
227 |NO. 4|1256-1319|128-143|1256-1319|128-159| |
228 |NO. 5|1320-1383|160-175|1320-1383|160-191| |
229 |NO. 6|1384-1447|192-207|1384-1447|192-223| |
230 |NO. 7|1448-1511|224-239|1448-1511|224-255| |
231
232 Communication between each PLC (up to 8 PLC), please see the connection construction below (For 3 PLC interconnection).
233
234 (% style="text-align:center" %)
Stone Wu 5.1 235 [[image:9.Communication example_html_b805bca9e1166337.jpg||height="93" width="600" class="img-thumbnail"]]
Leo Wei 1.1 236
Stone Wu 6.1 237 == **Special devices in N: N network** ==
Leo Wei 1.1 238
239 (% border="1" %)
Stone Wu 5.1 240 |=**Register**|=**Description**
Leo Wei 1.1 241 |D8120|Communication format settings
242 |D8126|COM2 communication protocol settings, 40h means N:N Master Device, 04h means N:N Slave device
243 |D8176|Station number, from 0 to 7, 0 means master device
244 |D8177|Total station number, from 1 to 7, only required for master device.
245 |D8178|Register block setting, from 0 to 5, only required for master device.
246 |D8179|Retry count settings, only required for master device.
247 |D8180|Timeout setting, unit: 10ms,only required for master device.
248 |D8201|Current connection scould time
249 |D8202|Maximum connection scould time
250 |D8203|Master error counter
251 |D8204~~D8210|Slave error counter
252 |D8211|Master N:N error code
253 |D8212~~D8218|Slave N:N error code
254 |M8183|Master data transfer sequence error
255 |M8183~~M8190|(((
256 Communication error flag:
257
258 M8183 - No.0 (Master);
259
260 M8184 - No. 1 (Slave 1)
261
262 ......
263 )))
264 |M8191|Processing sending data
265
Devin Chen 15.1 266 == **Communications format** ==
Leo Wei 1.1 267
268 (% border="1" %)
Stone Wu 5.1 269 |=**Item**|=(% style="width: 115px;" %)**Parameters**|=(% style="width: 239px;" %)**b15(RS2)**|=**b14-b8**|=**b7**|=**b6**|=**b5**|=**b4**|=**b3**|=**b2**|=**b1**|=**b0**
Leo Wei 1.1 270 |(% rowspan="2" %)**Bit mode**|(% style="width:115px" %)8 bit|(% style="width:239px" %)0|(% rowspan="15" %)Retention|-|-|-|-|-|-|-|-
271 |(% style="width:115px" %)16-bit|(% style="width:239px" %)1|-|-|-|-|-|-|-|-
272 |(% rowspan="6" %)**Baud rate (Bps)**|(% style="width:115px" %)115200|(% style="width:239px" %)-|1|1|0|0|-|-|-|-
273 |(% style="width:115px" %)57600|(% style="width:239px" %)-|1|0|1|1|-|-|-|-
274 |(% style="width:115px" %)38400|(% style="width:239px" %)-|1|0|1|0|-|-|-|-
275 |(% style="width:115px" %)19200|(% style="width:239px" %)-|1|0|0|1|-|-|-|-
276 |(% style="width:115px" %)9600|(% style="width:239px" %)-|1|0|0|0|-|-|-|-
277 |(% style="width:115px" %)4800|(% style="width:239px" %)-|0|1|1|1|-|-|-|-
278 |(% rowspan="2" %)**Stop bit**|(% style="width:115px" %)1 bit|(% style="width:239px" %)-|-|-|-|-|0|-|-|-
279 |(% style="width:115px" %)2 bit|(% style="width:239px" %)-|-|-|-|-|1|-|-|-
280 |(% rowspan="3" %)**Parity**|(% style="width:115px" %)None|(% style="width:239px" %)-|-|-|-|-|-|0|0|-
281 |(% style="width:115px" %)Odd|(% style="width:239px" %)-|-|-|-|-|-|0|1|-
282 |(% style="width:115px" %)Even|(% style="width:239px" %)-|-|-|-|-|-|1|1|-
283 |(% rowspan="2" %)**Data bit**|(% style="width:115px" %)7 bit|(% style="width:239px" %)-|-|-|-|-|-|-|-|0
284 |(% style="width:115px" %)8 bit|(% style="width:239px" %)-|-|-|-|-|-|-|-|1
285
Devin Chen 14.1 286 == **Communication error code (D8211~~D8218)** ==
287
288 |=(% style="width: 195px;" %)**Error code**|=(% style="width: 881px;" %)**Description**
Devin Chen 16.1 289 |(% style="width:195px" %)1|(% style="width:881px" %)The monitoring period has elapsed, and the slave station has not responded to requests from the master station yet.
Devin Chen 14.1 290 |(% style="width:195px" %)2|(% style="width:881px" %)The other slave stations have responded to requests sent by the master station.
291 |(% style="width:195px" %)3|(% style="width:881px" %)The count values in the parameter data do not match those responded by the slave stations.
292 |(% style="width:195px" %)4|(% style="width:881px" %)The response messages from the slave stations are incorrect.
293 |(% style="width:195px" %)17|(% style="width:881px" %)The monitoring period has elapsed,the master station has not sent a request to the next slave station yet.
294 |(% style="width:195px" %)20|(% style="width:881px" %)The messages from the master station are incorrect.
295 |(% style="width:195px" %)33|(% style="width:881px" %)The slave station is unresponsive.
296 |(% style="width:195px" %)34|(% style="width:881px" %)The other slave stations have responded to requests sent by the master station.
297 |(% style="width:195px" %)35|(% style="width:881px" %)The count values in the parameter data do not match those responded by the slave stations.
298 |(% style="width:195px" %)49|(% style="width:881px" %)The slave station received requests from the master station before receiving the parameters.
299
Stone Wu 6.1 300 == **Program example** ==
Leo Wei 1.1 301
302 LX3VP COM2 port communication parameters: 9600, 1, 8, NONE. Register block mode: 3
303
304 **PLC as master**
305
306 (% style="text-align:center" %)
Stone Wu 5.1 307 [[image:9.Communication example_html_a3fdef81ab69639.jpg||height="448" width="750" class="img-thumbnail"]]
Leo Wei 1.1 308
Stone Wu 5.1 309 **PLC as slave**
Leo Wei 1.1 310
311 (% style="text-align:center" %)
Stone Wu 5.1 312 [[image:9.Communication example_html_cc8af72b56d9c539.jpg||height="236" width="750" class="img-thumbnail"]]
Leo Wei 1.1 313
Stone Wu 5.1 314 (% class="box infomessage" %)
315 (((
316 ✎**Note:**
Leo Wei 1.1 317
318 * There are two modes of N:N protocol configuration. one is LX3VP built-in N:N protocol, the other one is LX3V N:N protocol (LX3V-2RS485-BD required).
319 * In LX3VP series PLC, only one kind of N:N configuration available. Second mode would be disabled when LX3VP built-in N:N protocol configured.
Stone Wu 5.1 320 )))
Leo Wei 1.1 321
Mora Zhou 11.1 322 = (% style="color:inherit; font-family:inherit" %)**RS485-BD and ETH-BD communiaction**(%%) =
Leo Wei 1.1 323
324 Please kindly check the link as below.
325
Stone Wu 3.1 326 (% class="box infomessage" %)
Leo Wei 1.1 327 (((
Stone Wu 3.1 328 ✎**Note:** at present 5V PLC can not support RS485-BD and ETH-BD
Leo Wei 1.1 329 )))
330
331 [[http:~~/~~/docs.we-con.com.cn/wiki/bdmodule/view/Main/Communication/2RS485-BD-3V/>>http://docs.we-con.com.cn/wiki/bdmodule/view/Main/Communication/2RS485-BD-3V/]]
332
333 [[http:~~/~~/docs.we-con.com.cn/wiki/bdmodule/view/Main/Communication/LX3VP-ETH-BD/>>http://docs.we-con.com.cn/wiki/bdmodule/view/Main/Communication/LX3VP-ETH-BD/]]