Wiki source code of 1 Communication

Version 15.1 by Ben on 2022/07/14 14:50

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 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 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 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 15.1 61 (% class="wikigeneratedid" %)
62 == ==
63
Ben 12.1 64 == **2 Communication with Allen-Bradley CompactLogix L1769** ==
Ben 11.1 65
66 (((
67 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 15.1 68
69
Ben 11.1 70 )))
71
72 (((
Ben 15.1 73 (% class="wikigeneratedid" id="HSoftwareconfigurationofPLC" %)
74 (((
75 **Software configuration of PLC**
Ben 11.1 76 )))
77
Ben 15.1 78 (% class="wikigeneratedid" id="HPLCprogrammingsoftware" %)
Ben 11.1 79 (((
Ben 15.1 80 **1)PLC programming software**
81 )))
Ben 11.1 82
Ben 15.1 83 [[image:image-20220714113935-3.png||height="324" width="270"]]
Ben 11.1 84
Ben 15.1 85 (% class="wikigeneratedid" id="HNewPLCproject" %)
Ben 11.1 86 (((
Ben 15.1 87 **2)New PLC project**
Ben 11.1 88 )))
89
90 (((
Ben 15.1 91 Click New Project and select the PLC model.
Ben 11.1 92 )))
93
94 (((
Ben 15.1 95 [[image:image-20220714114247-4.png||height="298" width="552"]] [[image:image-20220714114257-5.png||height="445" width="551"]]
Ben 11.1 96 )))
97
98 (((
99
100 )))
101
102 (((
Ben 15.1 103 (% class="wikigeneratedid" id="HSetEthernetparameters" %)
104 (((
105 **3)Set Ethernet parameters**
106 )))
Ben 11.1 107
108 (((
Ben 15.1 109 (((
Ben 11.1 110 Follow the steps below to configure Ethernet parameters
111 )))
Ben 15.1 112 )))
Ben 11.1 113
114 (((
Ben 15.1 115 (((
Ben 11.1 116 PLC IP address:192.168.40.101
117 )))
Ben 15.1 118 )))
Ben 11.1 119
120 (((
Ben 15.1 121 (((
Ben 11.1 122 default gateway:192.168.40.1
123 )))
Ben 15.1 124 )))
Ben 11.1 125
126 (((
Ben 15.1 127 (((
Ben 11.1 128 subnet mask:255.255.255.0
129 )))
Ben 15.1 130 )))
Ben 11.1 131
132 (((
Ben 15.1 133 [[image:image-20220714115012-6.png]]
Ben 11.1 134 )))
135
136 (((
137
138 )))
139
140 (((
Ben 15.1 141 (% class="wikigeneratedid" id="HV-boxsoftwareconfiguration" %)
142 (((
143 **V-box software configuration**
144 )))
Ben 11.1 145
Ben 15.1 146 (% class="wikigeneratedid" id="HV-boxprogrammingsoftware" %)
147 (((
148 **1)V-box programming software**
149 )))
Ben 11.1 150
Ben 15.1 151 (% class="wikigeneratedid" %)
152 (((
153 [[image:image-20220714115214-7.png||height="276" width="456"]]
154 )))
Ben 11.1 155
Ben 15.1 156 (% class="wikigeneratedid" id="HConfiguredevicenetwork" %)
157 (((
158 **2)Configure device network**
159 )))
Ben 11.1 160
161 (((
Ben 15.1 162 (((
Ben 11.1 163 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.
164 )))
Ben 15.1 165 )))
Ben 11.1 166
167 (((
Ben 15.1 168 (((
169 In the example below, the IP address of V-Box is configured as 192.168.40.66, and the networking method is 4G connection [[image:image-20220714115440-9.png||height="425" width="791"]]
Ben 11.1 170 )))
171 )))
172 )))
173 )))
174
Ben 15.1 175 (% class="wikigeneratedid" id="HV-netadddevice" %)
Ben 11.1 176 (((
Ben 15.1 177 **3)V-net add device**
Ben 11.1 178 )))
Ben 15.1 179 )))
Ben 11.1 180
181 (((
Ben 15.1 182 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-20220714115640-10.png||height="430" width="797"]]
Ben 11.1 183 )))
184
185 (((
186
187 )))
188
189 (((
Ben 15.1 190 (% class="wikigeneratedid" id="HSetcommunicationportparameters" %)
191 (((
192 **4)Set communication port parameters**
193 )))
Ben 11.1 194
Ben 15.1 195 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. [[image:image-20220714115848-11.png||height="432" width="802"]]
Ben 11.1 196 )))
197
198 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.
199
Ben 14.1 200 [[image:image-20220714143820-1.png]]
Ben 11.1 201
Ben 14.1 202 After adding the protocol Allen-BradleyMicro850_FreeTag, click[[image:image-20220714143838-2.png]]icon add label.
Ben 11.1 203
Ben 14.1 204 [[image:image-20220714143849-3.png]]
205
206
207 == Engineering production ==
208
209
Stone Wu 10.1 210 == **Siemens S7-1200** ==
Leo Wei 1.1 211
212 [[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]]
213
Stone Wu 10.1 214 == **Allen-Bradley Ethernet DF1** ==
Leo Wei 1.1 215
216 [[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]]
217
Stone Wu 10.1 218 == **Communication with S7-200 Smart** ==
Leo Wei 1.1 219
220 [[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]]
221
Stone Wu 10.1 222 == **Delta DVP Ethernet** ==
Leo Wei 1.1 223
224 [[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]]
225
Stone Wu 10.1 226 == **Delta DVP Serial Protocol** ==
Leo Wei 1.1 227
228 [[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]]
229
Stone Wu 10.1 230 == **Communicate with Mitsubishi FX Series** ==
Jim 6.1 231
232 [[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]]
233
Stone Wu 10.1 234 == **Communicate with VB inverter** ==
Jim 6.1 235
236 [[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]]
237
Stone Wu 10.1 238 == **Omron CP1 Series** ==
Jim 7.1 239
Jim 8.1 240 [[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 7.1 241
Stone Wu 10.1 242 == **Omron CJ2M** ==
Jim 7.1 243
Jim 8.1 244 [[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 7.1 245
Leo Wei 1.1 246 = **2 User define protocol** =
247
Leo 4.1 248 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 249
Stone Wu 10.1 250 == **Read the temperature sensor.** ==
Leo Wei 1.1 251
252 the commond format is as beliow:
253
254 Send commond:01 03 02 00 00 03 04 73
255
256 Feedback commond:01 03 06 07 F7 0E 7E B7 35
257
258 Temperature data:07 F7,desimal = 2039,it means temperature is 20.39℃.
259
260 Humidity data:0E 7E,desimal = 3710, it mean humidity is 37.10%RH.
261
262 Script Demo:
263
264 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--
265
266 function com.main()
267 ~-~-dosomething
268 openPlc()
269 end
270 function openPlc()
271 if obj then
272 ~-~- If the serial port opened,then read/write data by timing
273
274 local wri = string.pack(">HHHH",0X0103,0X0200,0X0003,0X0473)
275 local arr = reading(wri)
276 ~-~- if arr ~~=nil then
277 ~-~- if arr[1] ==33 and arr[2] ==v[2][2] and arr[3] ==v[2][3] then
278 ~-~- local A = arr[4]*256
279 ~-~- local B = A+arr[5]
280 ~-~- addr_setword(v[1],B)
281 ~-~- end
282 ~-~- end
283
284 else
285 ~-~-judge if there is a serial object, then initialize and open the serial port
286 local configs = {
287 name = 'COM1', ~-~-Select serial port COM1
288 mode = 485, ~-~-Communication mode RS485
289 baud_rate = 9600, ~-~-Baud rate 9600
290 stop_bit = 1, ~-~-stop bit 1
291 data_len = 8, ~-~-data length 8
292 check_bit = 'NONE', ~-~-no parity
293
294 }
295 obj,err = serial.open(configs) ~-~-Open serial port
296 if not obj then
297 print("serial open :failed", err) ~-~- Open serial port failed
298 end
299 end
300 end
301
302 function reading(wri)
303 obj:flush() ~-~- Clear serial port
304 obj:write(wri) ~-~- Write serial port
305 print(string.byte(wri,1,#wri))
306 obj:flush() ~-~- Clear serial port 
307 local readed =obj:read(9,1000) ~-~- Read 9 bytes, timeout 1 second
308 if readed and readed ~~= "" then 
309 ~-~- judge that a non-empty string is read
310 print(string.byte(readed,1,#readed))
311 a={string.byte(readed, 1, #readed)}
312 if nil ~~= a[4] and nil ~~= a[5] and nil ~~= a[6] and nil ~~= a[7] then
313 a1=a[4]*256+a[5]
314 a2=a[6]*256+a[7]
315 addr_setword("@HDW0",a1)
316 addr_setword("@HDW1",a2)
317 end
318 return {string.byte(readed, 1, #readed)}
319 elseif readed == nil then
320 print("serial read err:", err or "")
321 return nil
322 end
323 return nil
324 end
325
326 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-