1 Communication
1 General communication with PLC
Modbus RTU
V-BOX as master
Select the protocol “Modbus RTU Slave(All Fuction)”,
then set BaudRate,Port,Stop Bit,Data Bit,Parity
V-BOX as slave
Select the protocol “Modbus RTU Master”,
then set BaudRate,Port,Stop Bit,Data Bit,Parity
Address List
Type | Register | Function code & Description |
Word | 3 | 04 (read input register: read current binary value in one or more input registers) |
06 (write single register: write a binary value to a holding register) | ||
10 (write values to multiple addresses ) | ||
4 | 03 (read holding register: read current binary value in one or more holding registers) | |
06 (write single register: write a binary value to a holding register) | ||
10 (write values to multiple addresses ) | ||
W6 | 03 (read holding register: read current binary value in one or more holding registers) | |
06 (write single register: write a binary value to a holding register) | ||
10 (write values to multiple addresses ) | ||
W16 | 03 (read holding register: read current binary value in one or more holding registers) | |
10 (write values to multiple addresses ) | ||
Bit | 0 | 01 (Read coil state) |
05 (Force a single coil to force the on/off state of a logic coil) | ||
0F (Write multiple bits, ie write continuously) | ||
1 | 02 (Read the input state) | |
05 (Force a single coil to force the on/off state of a logic coil) | ||
0F (Write multiple bits) | ||
W5 | 01 (Read coil state to obtain the current state of a set of logic coils) | |
05 (Force a single coil to force the on/off state of a logic coil) | ||
0F (Write multiple bits) | ||
W15 | 01 (Read coil state to obtain the current state of a set of logic coils) | |
0F (Write multiple bits) |
WECON LX3V PLC
Select the protocol "WECON LX3V"
then set BaudRate,Port,Stop Bit,Data Bit,Parity same with PLC.
WECON PLC RS422 port,default communication parameters is 9600,1,7,ZEVEN
2 Communication with Allen-Bradley CompactLogix L1769
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.
Software configuration of PLC
1)PLC programming software
2)New PLC project
Click New Project and select the PLC model.
3)Set Ethernet parameters
Follow the steps below to configure Ethernet parameters
PLC IP address:192.168.40.101
default gateway:192.168.40.1
subnet mask:255.255.255.0
V-box software configuration
1)V-box programming software
2)Configure device network
Click the Configuration Download button, It is used to configure the device network, update the device time, obtain the device machine code, check the device network, etc.
In the example below, the IP address of V-Box is configured as 192.168.40.66, and the networking method is 4G connection
3)V-net add device
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.
4)Set communication port parameters
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.
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.
After adding the protocol Allen-BradleyMicro850_FreeTag, clickicon add label.
Engineering production
Siemens S7-1200
Allen-Bradley Ethernet DF1
Communication with S7-200 Smart
Delta DVP Ethernet
Delta DVP Serial Protocol
Communicate with Mitsubishi FX Series
Communicate with VB inverter
Omron CP1 Series
Omron CJ2M
2 User define protocol
More serial port script instruction,please refer manual:Lua script function--->3.Serial port operation
Read the temperature sensor.
the commond format is as beliow:
Send commond:01 03 02 00 00 03 04 73
Feedback commond:01 03 06 07 F7 0E 7E B7 35
Temperature data:07 F7,desimal = 2039,it means temperature is 20.39℃.
Humidity data:0E 7E,desimal = 3710, it mean humidity is 37.10%RH.
Script Demo:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
function com.main()
--dosomething
openPlc()
end
function openPlc()
if obj then
-- If the serial port opened,then read/write data by timing
local wri = string.pack(">HHHH",0X0103,0X0200,0X0003,0X0473)
local arr = reading(wri)
-- if arr ~=nil then
-- if arr[1] ==33 and arr[2] ==v[2][2] and arr[3] ==v[2][3] then
-- local A = arr[4]*256
-- local B = A+arr[5]
-- addr_setword(v[1],B)
-- end
-- end
else
--judge if there is a serial object, then initialize and open the serial port
local configs = {
name = 'COM1', --Select serial port COM1
mode = 485, --Communication mode RS485
baud_rate = 9600, --Baud rate 9600
stop_bit = 1, --stop bit 1
data_len = 8, --data length 8
check_bit = 'NONE', --no parity
}
obj,err = serial.open(configs) --Open serial port
if not obj then
print("serial open :failed", err) -- Open serial port failed
end
end
end
function reading(wri)
obj:flush() -- Clear serial port
obj:write(wri) -- Write serial port
print(string.byte(wri,1,#wri))
obj:flush() -- Clear serial port
local readed =obj:read(9,1000) -- Read 9 bytes, timeout 1 second
if readed and readed ~= "" then
-- judge that a non-empty string is read
print(string.byte(readed,1,#readed))
a={string.byte(readed, 1, #readed)}
if nil ~= a[4] and nil ~= a[5] and nil ~= a[6] and nil ~= a[7] then
a1=a[4]*256+a[5]
a2=a[6]*256+a[7]
addr_setword("@HDW0",a1)
addr_setword("@HDW1",a2)
end
return {string.byte(readed, 1, #readed)}
elseif readed == nil then
print("serial read err:", err or "")
return nil
end
return nil
end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------