Wiki source code of 1 Communication
Version 13.1 by Ben on 2022/07/14 14:37
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | = **1 General communication with PLC** = | ||
2 | |||
3 | == **Modbus RTU** == | ||
4 | |||
5 | === **V-BOX as master** === | ||
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" %) | ||
12 | [[image:1624342015914-382.png||height="486" width="800" class="img-thumbnail"]] | ||
13 | |||
14 | === **V-BOX as slave** === | ||
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" %) | ||
21 | [[image:1624348709622-711.png||queryString="width=809&height=493" height="488" width="800" class="img-thumbnail"]] | ||
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 | |||
50 | == **WECON LX3V PLC** == | ||
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" %) | ||
59 | [[image:1624348978863-771.png||queryString="width=812&height=494" height="487" width="800" class="img-thumbnail"]] | ||
60 | |||
61 | == **2 Communication with Allen-Bradley CompactLogix L1769** == | ||
62 | |||
63 | === **Overview** === | ||
64 | |||
65 | ((( | ||
66 | 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. | ||
67 | ))) | ||
68 | |||
69 | ((( | ||
70 | |||
71 | ))) | ||
72 | |||
73 | ((( | ||
74 | == **Software configuration of PLC** == | ||
75 | |||
76 | === **PLC programming software** === | ||
77 | |||
78 | [[image:image-20220714113935-3.png]] | ||
79 | |||
80 | === **New PLC project** === | ||
81 | |||
82 | ((( | ||
83 | Click New Project and select the PLC model. | ||
84 | ))) | ||
85 | |||
86 | ((( | ||
87 | [[image:image-20220714114247-4.png]] | ||
88 | ))) | ||
89 | |||
90 | ((( | ||
91 | [[image:image-20220714114257-5.png]] | ||
92 | ))) | ||
93 | |||
94 | ((( | ||
95 | |||
96 | ))) | ||
97 | |||
98 | ((( | ||
99 | === **Set Ethernet parameters** === | ||
100 | |||
101 | ((( | ||
102 | Follow the steps below to configure Ethernet parameters | ||
103 | ))) | ||
104 | |||
105 | ((( | ||
106 | PLC IP address:192.168.40.101 | ||
107 | ))) | ||
108 | |||
109 | ((( | ||
110 | default gateway:192.168.40.1 | ||
111 | ))) | ||
112 | |||
113 | ((( | ||
114 | subnet mask:255.255.255.0 | ||
115 | ))) | ||
116 | |||
117 | ((( | ||
118 | [[image:image-20220714115012-6.png]] | ||
119 | ))) | ||
120 | |||
121 | ((( | ||
122 | |||
123 | ))) | ||
124 | |||
125 | ((( | ||
126 | == **V-box software configuration** == | ||
127 | |||
128 | === **V-box programming software** === | ||
129 | |||
130 | [[image:image-20220714115214-7.png]] | ||
131 | |||
132 | |||
133 | === **Configure device network** === | ||
134 | |||
135 | ((( | ||
136 | 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. | ||
137 | ))) | ||
138 | |||
139 | ((( | ||
140 | In the example below, the IP address of V-Box is configured as 192.168.40.66, and the networking method is 4G connection. | ||
141 | ))) | ||
142 | |||
143 | [[image:image-20220714115440-9.png||height="425" width="791"]] | ||
144 | ))) | ||
145 | ))) | ||
146 | |||
147 | == **V-net add device** == | ||
148 | ))) | ||
149 | |||
150 | ((( | ||
151 | 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. | ||
152 | ))) | ||
153 | |||
154 | ((( | ||
155 | [[image:image-20220714115640-10.png||height="430" width="797"]] | ||
156 | ))) | ||
157 | |||
158 | ((( | ||
159 | |||
160 | ))) | ||
161 | |||
162 | ((( | ||
163 | === **Set communication port parameters** === | ||
164 | |||
165 | 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. | ||
166 | |||
167 | [[image:image-20220714115848-11.png||height="432" width="802"]] | ||
168 | ))) | ||
169 | |||
170 | |||
171 | 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. | ||
172 | |||
173 | |||
174 | |||
175 | == **Siemens S7-1200** == | ||
176 | |||
177 | [[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]] | ||
178 | |||
179 | == **Allen-Bradley Ethernet DF1** == | ||
180 | |||
181 | [[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]] | ||
182 | |||
183 | == **Communication with S7-200 Smart** == | ||
184 | |||
185 | [[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]] | ||
186 | |||
187 | == **Delta DVP Ethernet** == | ||
188 | |||
189 | [[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]] | ||
190 | |||
191 | == **Delta DVP Serial Protocol** == | ||
192 | |||
193 | [[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]] | ||
194 | |||
195 | == **Communicate with Mitsubishi FX Series** == | ||
196 | |||
197 | [[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]] | ||
198 | |||
199 | == **Communicate with VB inverter** == | ||
200 | |||
201 | [[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]] | ||
202 | |||
203 | == **Omron CP1 Series** == | ||
204 | |||
205 | [[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]] | ||
206 | |||
207 | == **Omron CJ2M** == | ||
208 | |||
209 | [[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]] | ||
210 | |||
211 | = **2 User define protocol** = | ||
212 | |||
213 | 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]] | ||
214 | |||
215 | == **Read the temperature sensor.** == | ||
216 | |||
217 | the commond format is as beliow: | ||
218 | |||
219 | Send commond:01 03 02 00 00 03 04 73 | ||
220 | |||
221 | Feedback commond:01 03 06 07 F7 0E 7E B7 35 | ||
222 | |||
223 | Temperature data:07 F7,desimal = 2039,it means temperature is 20.39℃. | ||
224 | |||
225 | Humidity data:0E 7E,desimal = 3710, it mean humidity is 37.10%RH. | ||
226 | |||
227 | Script Demo: | ||
228 | |||
229 | ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-- | ||
230 | |||
231 | function com.main() | ||
232 | ~-~-dosomething | ||
233 | openPlc() | ||
234 | end | ||
235 | function openPlc() | ||
236 | if obj then | ||
237 | ~-~- If the serial port opened,then read/write data by timing | ||
238 | |||
239 | local wri = string.pack(">HHHH",0X0103,0X0200,0X0003,0X0473) | ||
240 | local arr = reading(wri) | ||
241 | ~-~- if arr ~~=nil then | ||
242 | ~-~- if arr[1] ==33 and arr[2] ==v[2][2] and arr[3] ==v[2][3] then | ||
243 | ~-~- local A = arr[4]*256 | ||
244 | ~-~- local B = A+arr[5] | ||
245 | ~-~- addr_setword(v[1],B) | ||
246 | ~-~- end | ||
247 | ~-~- end | ||
248 | |||
249 | else | ||
250 | ~-~-judge if there is a serial object, then initialize and open the serial port | ||
251 | local configs = { | ||
252 | name = 'COM1', ~-~-Select serial port COM1 | ||
253 | mode = 485, ~-~-Communication mode RS485 | ||
254 | baud_rate = 9600, ~-~-Baud rate 9600 | ||
255 | stop_bit = 1, ~-~-stop bit 1 | ||
256 | data_len = 8, ~-~-data length 8 | ||
257 | check_bit = 'NONE', ~-~-no parity | ||
258 | |||
259 | } | ||
260 | obj,err = serial.open(configs) ~-~-Open serial port | ||
261 | if not obj then | ||
262 | print("serial open :failed", err) ~-~- Open serial port failed | ||
263 | end | ||
264 | end | ||
265 | end | ||
266 | |||
267 | function reading(wri) | ||
268 | obj:flush() ~-~- Clear serial port | ||
269 | obj:write(wri) ~-~- Write serial port | ||
270 | print(string.byte(wri,1,#wri)) | ||
271 | obj:flush() ~-~- Clear serial port | ||
272 | local readed =obj:read(9,1000) ~-~- Read 9 bytes, timeout 1 second | ||
273 | if readed and readed ~~= "" then | ||
274 | ~-~- judge that a non-empty string is read | ||
275 | print(string.byte(readed,1,#readed)) | ||
276 | a={string.byte(readed, 1, #readed)} | ||
277 | if nil ~~= a[4] and nil ~~= a[5] and nil ~~= a[6] and nil ~~= a[7] then | ||
278 | a1=a[4]*256+a[5] | ||
279 | a2=a[6]*256+a[7] | ||
280 | addr_setword("@HDW0",a1) | ||
281 | addr_setword("@HDW1",a2) | ||
282 | end | ||
283 | return {string.byte(readed, 1, #readed)} | ||
284 | elseif readed == nil then | ||
285 | print("serial read err:", err or "") | ||
286 | return nil | ||
287 | end | ||
288 | return nil | ||
289 | end | ||
290 | |||
291 | ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- |