Wiki source code of 1 Communication

Version 16.1 by Ben on 2022/07/14 16:16

Hide last authors
Leo Wei 1.1 1 = **1 General communication with PLC** =
2
Stone Wu 10.1 3 == **Modbus RTU** ==
Leo Wei 1.1 4
Stone Wu 10.1 5 === **V-BOX as master** ===
Leo Wei 1.1 6
7 Select the protocol “(% class="mark" %)Modbus RTU Slave(All Fuction)”,
8
9 (% class="mark" %)then set BaudRate,Port,Stop Bit,Data Bit,Parity
10
11 (% style="text-align:center" %)
Jim(Forgotten) 6.1 12 [[image:1624342015914-382.png||height="486" width="800" class="img-thumbnail"]]
Leo Wei 1.1 13
Stone Wu 10.1 14 === **V-BOX as slave** ===
Leo Wei 1.1 15
16 Select the protocol “(% class="mark" %)**Modbus RTU Master”**,
17
18 (% class="mark" %)then set BaudRate,Port,Stop Bit,Data Bit,Parity
19
20 (% style="text-align:center" %)
Jim(Forgotten) 6.1 21 [[image:1624348709622-711.png||queryString="width=809&height=493" height="488" width="800" class="img-thumbnail"]]
Leo Wei 1.1 22
23 **Address List**
24
25 (% class="table-bordered" %)
26 |**Type**|**Register**|**Function code & Description**
27 |(% rowspan="11" %)Word|(% rowspan="3" %)3|04 (read input register: read current binary value in one or more input registers)
28 |06 (write single register: write a binary value to a holding register)
29 |10 (write values to multiple addresses )
30 |(% rowspan="3" %)4|03 (read holding register: read current binary value in one or more holding registers)
31 |06 (write single register: write a binary value to a holding register)
32 |10 (write values to multiple addresses )
33 |(% rowspan="3" %)W6|03 (read holding register: read current binary value in one or more holding registers)
34 |06 (write single register: write a binary value to a holding register)
35 |10 (write values to multiple addresses )
36 |(% rowspan="2" %)W16|03 (read holding register: read current binary value in one or more holding registers)
37 |10 (write values to multiple addresses )
38 |(% rowspan="11" %)Bit|(% rowspan="3" %)0|01 (Read coil state)
39 |05 (Force a single coil to force the on/off state of a logic coil)
40 |0F (Write multiple bits, ie write continuously)
41 |(% rowspan="3" %)1|02 (Read the input state)
42 |05 (Force a single coil to force the on/off state of a logic coil)
43 |0F (Write multiple bits)
44 |(% rowspan="3" %)W5|01 (Read coil state to obtain the current state of a set of logic coils)
45 |05 (Force a single coil to force the on/off state of a logic coil)
46 |0F (Write multiple bits)
47 |(% rowspan="2" %)W15|01 (Read coil state to obtain the current state of a set of logic coils)
48 |0F (Write multiple bits)
49
Stone Wu 10.1 50 == **WECON LX3V PLC** ==
Leo Wei 1.1 51
52 Select the protocol (% class="mark" %)"WECON LX3V"
53
54 (% class="mark" %)then set BaudRate,Port,Stop Bit,Data Bit,Parity same with PLC.
55
56 (% class="mark" %)WECON PLC RS422 port,default communication parameters is 9600,1,7,ZEVEN
57
58 (% style="text-align:center" %)
Jim(Forgotten) 6.1 59 [[image:1624348978863-771.png||queryString="width=812&height=494" height="487" width="800" class="img-thumbnail"]]
Leo Wei 1.1 60
Ben 12.1 61 == **2 Communication with Allen-Bradley CompactLogix L1769** ==
Ben 11.1 62
63 (((
Ben 16.1 64 (((
Ben 11.1 65 This example introduces the establishment of Ethernet communication between Wecon V-box and Allen-Bradley L1769. It is introduced through three parts: PLC software configuration, V-box software configuration, and hardware wiring.
Ben 16.1 66 )))
Ben 15.1 67
68
Ben 11.1 69 )))
70
71 (((
Ben 15.1 72 (% class="wikigeneratedid" id="HSoftwareconfigurationofPLC" %)
73 (((
74 **Software configuration of PLC**
Ben 11.1 75 )))
76
Ben 15.1 77 (% class="wikigeneratedid" id="HPLCprogrammingsoftware" %)
Ben 11.1 78 (((
Ben 15.1 79 **1)PLC programming software**
80 )))
Ben 11.1 81
Ben 16.1 82 [[image:image-20220714160120-3.png||height="308" width="255"]]
Ben 11.1 83
Ben 15.1 84 (% class="wikigeneratedid" id="HNewPLCproject" %)
Ben 11.1 85 (((
Ben 15.1 86 **2)New PLC project**
Ben 11.1 87 )))
88
89 (((
Ben 16.1 90 (((
Ben 15.1 91 Click New Project and select the PLC model.
Ben 11.1 92 )))
Ben 16.1 93 )))
Ben 11.1 94
95 (((
Ben 16.1 96
Ben 11.1 97 )))
98
99 (((
Ben 16.1 100 [[image:image-20220714160335-4.png||height="215" width="398"]]
101
102 [[image:image-20220714160412-5.png||height="319" width="395"]]
Ben 11.1 103 )))
104
105 (((
Ben 15.1 106 (% class="wikigeneratedid" id="HSetEthernetparameters" %)
107 (((
108 **3)Set Ethernet parameters**
109 )))
Ben 11.1 110
111 (((
Ben 15.1 112 (((
Ben 16.1 113 (((
Ben 11.1 114 Follow the steps below to configure Ethernet parameters
115 )))
Ben 15.1 116 )))
Ben 16.1 117 )))
Ben 11.1 118
119 (((
Ben 15.1 120 (((
Ben 16.1 121 (((
Ben 11.1 122 PLC IP address:192.168.40.101
123 )))
Ben 15.1 124 )))
Ben 16.1 125 )))
Ben 11.1 126
127 (((
Ben 15.1 128 (((
Ben 16.1 129 (((
Ben 11.1 130 default gateway:192.168.40.1
131 )))
Ben 15.1 132 )))
Ben 16.1 133 )))
Ben 11.1 134
135 (((
Ben 15.1 136 (((
Ben 16.1 137 (((
Ben 11.1 138 subnet mask:255.255.255.0
139 )))
Ben 15.1 140 )))
Ben 16.1 141 )))
Ben 11.1 142
143 (((
Ben 16.1 144 [[image:image-20220714160439-6.png||height="325" width="717"]]
Ben 11.1 145 )))
146
147 (((
148
149 )))
150
151 (((
Ben 15.1 152 (% class="wikigeneratedid" id="HV-boxsoftwareconfiguration" %)
153 (((
154 **V-box software configuration**
155 )))
Ben 11.1 156
Ben 15.1 157 (% class="wikigeneratedid" id="HV-boxprogrammingsoftware" %)
158 (((
159 **1)V-box programming software**
160 )))
Ben 11.1 161
Ben 15.1 162 (% class="wikigeneratedid" %)
163 (((
Ben 16.1 164 [[image:image-20220714160541-7.png||height="189" width="314"]]
Ben 15.1 165 )))
Ben 11.1 166
Ben 15.1 167 (% class="wikigeneratedid" id="HConfiguredevicenetwork" %)
168 (((
169 **2)Configure device network**
170 )))
Ben 11.1 171
172 (((
Ben 15.1 173 (((
Ben 16.1 174 (((
Ben 11.1 175 Click the Configuration Download button[[image:image-20220714115308-8.png||height="22" width="15"]], It is used to configure the device network, update the device time, obtain the device machine code, check the device network, etc.
176 )))
Ben 16.1 177
178 (((
179 In the example below, the IP address of V-Box is configured as 192.168.40.66, and the networking method is 4G connection
Ben 15.1 180 )))
Ben 16.1 181 )))
182 )))
Ben 11.1 183
184 (((
Ben 15.1 185 (((
Ben 16.1 186 [[image:image-20220714160651-8.png||height="389" width="724"]]
187
188
Ben 11.1 189 )))
190 )))
191 )))
192 )))
193
Ben 15.1 194 (% class="wikigeneratedid" id="HV-netadddevice" %)
Ben 11.1 195 (((
Ben 15.1 196 **3)V-net add device**
Ben 11.1 197 )))
Ben 15.1 198 )))
Ben 11.1 199
200 (((
Ben 16.1 201 (((
202 Open VNET client software → add device. As shown in the figure below, click "+" in the order of steps, and the Add Device window will pop up, enter the device machine code/product code, device password, and device alias to add the device.   [[image:image-20220714160034-2.png||height="394" width="731"]]
Ben 11.1 203 )))
204
205
206 )))
207
208 (((
Ben 15.1 209 (% class="wikigeneratedid" id="HSetcommunicationportparameters" %)
210 (((
211 **4)Set communication port parameters**
212 )))
Ben 11.1 213
Ben 16.1 214 (((
215 In the device list on the left, find the Vbox that communicates with the L1769, click it and select configuration,communication port configuration in the main interface to add a communication protocol.
Ben 11.1 216 )))
217
Ben 16.1 218 [[image:image-20220714160843-9.png||height="395" width="733"]]
219 )))
220
221 (((
Ben 11.1 222 The communication port is selected as Ethernet, the device type is selected as Allen-Bradley, the protocol is Allen-BradleyMicro850_FreeTag EthemetIP, and the IP is the internal IP address of the L1769 PLC. The port number is 44818.
Ben 16.1 223 )))
Ben 11.1 224
Ben 16.1 225 [[image:image-20220714160943-10.png||height="300" width="487"]]
Ben 11.1 226
227
Ben 16.1 228 (((
229 After adding the protocol Allen-BradleyMicro850_FreeTag, click[[image:image-20220714143838-2.png]]icon add label.[[image:image-20220714161120-12.png||height="403" width="740"]]
230 )))
Ben 14.1 231
Ben 16.1 232 (% class="wikigeneratedid" id="HEngineeringproduction" %)
233 (((
234 **5)Engineering production**
235 )))
Ben 14.1 236
Ben 16.1 237 (% class="wikigeneratedid" %)
238 (((
239 (((
240 According to your own needs, use the V-NET client software to edit the required data monitoring points.
241 )))
Ben 14.1 242
Ben 16.1 243 [[image:image-20220714161229-13.png||height="217" width="732"]]
Ben 14.1 244
Ben 16.1 245
246 (((
247 **hardware connection**
248 )))
249 )))
250
251 (((
252 **1)Hardware wiring diagram**
253 )))
254
255 (((
256 (((
257 This example introduces Wecon V-box with Allen-Bradley L1769 PLC to establish communication through Ethernet. The connection diagram is as follows:
258 )))
259
260 [[image:image-20220714161445-14.png]]
261
262 (((
263 The above are all the steps for establishing Ethernet communication between Wecon V-box with Allen-Bradley L1769 PLC.
264 )))
265 )))
266
Stone Wu 10.1 267 == **Siemens S7-1200** ==
Leo Wei 1.1 268
269 [[download link>>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%20S7-1200%20via%20Ehernet.zip]]
270
Stone Wu 10.1 271 == **Allen-Bradley Ethernet DF1** ==
Leo Wei 1.1 272
273 [[download link>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/%E9%80%9A%E8%AE%AF%E6%A1%88%E4%BE%8B/Allen-Bradley%20Ethernet%20DF1.zip]]
274
Stone Wu 10.1 275 == **Communication with S7-200 Smart** ==
Leo Wei 1.1 276
277 [[download link>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/%E9%80%9A%E8%AE%AF%E6%A1%88%E4%BE%8B/Communication%20with%20S7-200%20Smart.zip]]
278
Stone Wu 10.1 279 == **Delta DVP Ethernet** ==
Leo Wei 1.1 280
281 [[download link>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/%E9%80%9A%E8%AE%AF%E6%A1%88%E4%BE%8B/Delta%20DVP%20Ethernet.zip]]
282
Stone Wu 10.1 283 == **Delta DVP Serial Protocol** ==
Leo Wei 1.1 284
285 [[download link>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/%E9%80%9A%E8%AE%AF%E6%A1%88%E4%BE%8B/Delta%20DVP%20Ethernet.zip]]
286
Stone Wu 10.1 287 == **Communicate with Mitsubishi FX Series** ==
Jim(Forgotten) 6.1 288
289 [[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%20Mitsubishi%20FX%20Series.zip]]
290
Stone Wu 10.1 291 == **Communicate with VB inverter** ==
Jim(Forgotten) 6.1 292
293 [[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]]
294
Stone Wu 10.1 295 == **Omron CP1 Series** ==
Jim(Forgotten) 7.1 296
Jim(Forgotten) 8.1 297 [[download link>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/%E9%80%9A%E8%AE%AF%E6%A1%88%E4%BE%8B/Communication%20with%20ORMON%20CP1%20Series.zip]]
Jim(Forgotten) 7.1 298
Stone Wu 10.1 299 == **Omron CJ2M** ==
Jim(Forgotten) 7.1 300
Jim(Forgotten) 8.1 301 [[download link>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/%E9%80%9A%E8%AE%AF%E6%A1%88%E4%BE%8B/Communication%20with%20ORMON%20CJ2M.zip]]
Jim(Forgotten) 7.1 302
Leo Wei 1.1 303 = **2 User define protocol** =
304
Leo 4.1 305 More serial port script instruction,please refer manual:[[Lua script function>>doc:V-BOX.V-Net.1\.User Manual.04 Lua Script.01 Lua Functions.WebHome]]~-~-->[[3.Serial port operation>>url:http://docs.we-con.com.cn/wiki/vbox/view/HMI/04.Lua%20script%20%20function%20and%20operation/01.Lua%20script%20function/#H3.Serialportoperation]]
Leo Wei 1.1 306
Stone Wu 10.1 307 == **Read the temperature sensor.** ==
Leo Wei 1.1 308
309 the commond format is as beliow:
310
311 Send commond:01 03 02 00 00 03 04 73
312
313 Feedback commond:01 03 06 07 F7 0E 7E B7 35
314
315 Temperature data:07 F7,desimal = 2039,it means temperature is 20.39℃.
316
317 Humidity data:0E 7E,desimal = 3710, it mean humidity is 37.10%RH.
318
319 Script Demo:
320
321 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--
322
323 function com.main()
324 ~-~-dosomething
325 openPlc()
326 end
327 function openPlc()
328 if obj then
329 ~-~- If the serial port opened,then read/write data by timing
330
331 local wri = string.pack(">HHHH",0X0103,0X0200,0X0003,0X0473)
332 local arr = reading(wri)
333 ~-~- if arr ~~=nil then
334 ~-~- if arr[1] ==33 and arr[2] ==v[2][2] and arr[3] ==v[2][3] then
335 ~-~- local A = arr[4]*256
336 ~-~- local B = A+arr[5]
337 ~-~- addr_setword(v[1],B)
338 ~-~- end
339 ~-~- end
340
341 else
342 ~-~-judge if there is a serial object, then initialize and open the serial port
343 local configs = {
344 name = 'COM1', ~-~-Select serial port COM1
345 mode = 485, ~-~-Communication mode RS485
346 baud_rate = 9600, ~-~-Baud rate 9600
347 stop_bit = 1, ~-~-stop bit 1
348 data_len = 8, ~-~-data length 8
349 check_bit = 'NONE', ~-~-no parity
350
351 }
352 obj,err = serial.open(configs) ~-~-Open serial port
353 if not obj then
354 print("serial open :failed", err) ~-~- Open serial port failed
355 end
356 end
357 end
358
359 function reading(wri)
360 obj:flush() ~-~- Clear serial port
361 obj:write(wri) ~-~- Write serial port
362 print(string.byte(wri,1,#wri))
363 obj:flush() ~-~- Clear serial port 
364 local readed =obj:read(9,1000) ~-~- Read 9 bytes, timeout 1 second
365 if readed and readed ~~= "" then 
366 ~-~- judge that a non-empty string is read
367 print(string.byte(readed,1,#readed))
368 a={string.byte(readed, 1, #readed)}
369 if nil ~~= a[4] and nil ~~= a[5] and nil ~~= a[6] and nil ~~= a[7] then
370 a1=a[4]*256+a[5]
371 a2=a[6]*256+a[7]
372 addr_setword("@HDW0",a1)
373 addr_setword("@HDW1",a2)
374 end
375 return {string.byte(readed, 1, #readed)}
376 elseif readed == nil then
377 print("serial read err:", err or "")
378 return nil
379 end
380 return nil
381 end
382
383 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-