1 Communication

Version 122.1 by Ben on 2022/08/25 14:58

维控公司

LX3V 串行协议

支持系列:维控 LX2V/ LX2E/ LX3V/LX3VP/LX3VE/LX3VM

1)可编程逻辑控制器设置

项目设置注意
协议维控 LX2V/ LX2E/ LX3V/LX3VP/LX3VE/LX3VM 
连接RS422/RS485 
波特率9600 
数据位7 
平价甚至 
停止位1 
PLC站号1 

2)可编程逻辑控制器地址列表

类型设备寄存器人机界面寄存器格式范围注意
XX断续器0~303237 
YYY o0~303237 
MMM d0~99999 
TTS C0~99999 
CC断续器0~99999 
SS断续器0~99999 
XX断续器0~303237 
YYY o0~303237 
MMM d0~99999 
TTS C0~99999 
CC断续器0~199 
DDC C0~7999 
SS断续器0~99999 
标清标清标清 d8000~9999 

3)配置通信协议

图片-20220824152217-1.png

4)硬件连接

  • RS422

                                                                         image-20220824120614-5.png

  • RS485

                                                                   image-20220824120524-3.png

LX5V Serial Protocol

This example introduces the establishment of serial port communication between V-BOX and LX5V. It is introduced through three parts: PLC software configuration, V-BOX software configuration, and hardware wiring.

Software configuration of PLC

1)PLC programming software

image-20220824142722-1.png

2)New PLC project

Click New Project and select the PLC model.

image-20220822172623-2.png

3)Set Serial port parameters

Follow the steps below to configure Serial port parameters

Baud rate:115200

Data bit:8

Stop bit:1

Parity:No verification

image-20220822172657-3.png

4)Registers list

image-20220822172730-4.png

V-BOX software configuration

1)V-BOX programming software

 image-20220824104124-1.png

2)V-NET add device

Open V-NET 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 access key, password and remark, to add the device.

image-20220824104909-2.png

3)Set communication port parameters

Click the communication configuration button on the left to find the communication protocol with LX5V. After selecting the protocol, configure the communication parameters of the COM port.

Baud rate:115200

Data bit:8

Stop bit:1

Parity:No verification

image-20220824142130-1.png

hardware connection

1)Hardware wiring diagram

image-20220824142546-2.png

image-20220824142643-3.png

The above are all the steps for establishing serial port communication between V-BOX with LX5V PLC.

LX5V-N Ethernet protocol

This example introduces the establishment of Ethernet communication between V-BOX and LX5V-N. It is introduced through three parts: PLC software configuration, V-BOX software configuration, and hardware wiring.

Software configuration of PLC

1)PLC programming software

image-20220824142722-1.png

2)New PLC project

Click New Project and select the PLC model.

image-20220824143613-1.png

3)Set Ethernet port parameters

Follow the steps below to configure Ethernet parameters

PLC IP address:192.168.39.200

default gateway:192.168.39.1

subnet mask:255.255.255.0

image-20220824143744-2.png

4)Registers list

image-20220822172730-4.png

V-BOX software configuration

1)V-BOX programming software

 image-20220824104124-1.png

2)V-NET add device

Open V-NET 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 access key, password and remark, to add the device.

image-20220824104909-2.png

3)Set communication Protocol

Click Communication to configure the LX5V plc protocol and IP address.

image-20220824144619-1.png

hardware connection

1)Hardware wiring diagram

image-20220824151127-2.png

The above are all the steps for establishing ethernet communication between V-BOX with LX5V PLC.

Rockwell PLC

MicroLogix Protocol

MicroLogix 1000/1100/1200/1400/1500; SLC 5/03 5/04 5/05 PLC-5

1)PLC Settings

ItemSettingsNote
ProtocolAllen-Bradlley DF1 Advanced 
ConnectionRS232 
Baud rate19200 
Data bit8 
ParityNone 
Stop bit1 
PLC station No.1 

2)Address List

TypeDevice registersFormatRangeNote
BitII d.d0.0~255.15 
OO d.d0.0~255.15 
BB nnhh.dd0.0~ffff.15nn: block number (hex)
SS d.d0.0~255.15 
NN nnhh.dd0.0~ffff.15nn: block number (hex)
WordSS d0~255 
TSTS nnhh0~ffffnn: block number (hex)
TPTP nnhh0~ffff
CSCS nnhh0~ffff
CPCP nnhh0~ffff
NN nnhh0~ffff
CC nnhh0~ffff
TT nnhh0~ffff
RR nnhh0~ffff

3)Configure the communication protocolimage-20220824152928-1.png

4)Configure the communication protocol

image-20220824110724-1.png

Micro850_FreeTag

This example introduces the establishment of Ethernet communication between Wecon V-box and CompactLogix 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

image-20220714162600-1.png

2)New PLC project

Click New Project and select the PLC model.

image-20220714162617-2.png

 

image-20220714162652-4.png

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

image-20220714162713-5.png

 

V-box software configuration

1)V-box programming software

 image-20220714162725-6.png

2)Configure device network

Click the Configuration Download buttonimage-20220714115308-8.png, 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 

image-20220714162737-7.png

 

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.   image-20220714162752-8.png

 

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. 

image-20220714162805-9.png

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.

image-20220824164346-1.png

After adding the protocol Allen-BradleyMicro850_FreeTag, clickimage-20220714143838-2.pngicon add label.image-20220714162827-11.png

5)Engineering production

According to your own needs, use the V-NET client software to edit the required data monitoring points.

image-20220714162841-12.png

hardware connection

1)Hardware wiring diagram

This example introduces Wecon V-box with Allen-Bradley L1769 PLC to establish communication through Ethernet. The connection diagram is as follows:

image-20220714162856-13.png

The above are all the steps for establishing Ethernet communication between Wecon V-box with CompactLogix L1769 PLC.

Allen-Bradley Ethernet DF1

download link

Siemens PLC

S7-200 Smart Ethernet Protocol

download link

S7-300 Ethernet Protocol

Supported Series: Siemens S7-300 series PLC

1)PLC Setting

ItemsSettingsNote
ProtocolSimens S7-300 Ethernet 
ConnectionEthernet 
Port No.102 
PLC station No.2Need to be same as the PLC setting

2)Address List

TypeDevice registerHMI registerFormatRangeNote
BitIII ddddd.o0.0~99999.7 
QQQ ddddd.o0.0~99999.7 
MMM ddddd.o0.0~99999.7 
DB0.DB~DB99.DBDBxDBDDBxDB nndddd.o0.0~99999999.7

nn: block number;

dddd: address;

WordIIWIW ddddd0~99999 
QQWQW ddddd0~99999 
MMBMB ddddd0~99999 
MWMW ddddd0~99999

MW0=MB(0~1)

MW2=MB(2~3)

Address value is a multiple of 2

MDMD ddddd0~99999

MD0=MB(0~3)

MD4=MB(4~7)

Address value is a multiple of 4

DB0.DB~DB99.DBDBxDBBDBxDBB nndddd0~99999999

nn: block number;

dddd: address

DBxDBWDBxDBW nndddd0~99999999
DBxDBDDBxDBD nndddd0~99999999

3)Configure the communication protocol

image-20220824161345-1.png

4)Cable Wiring

image-20220824161450-2.png

S7-1200 Ethernet Protocol

download link

S7-XXX Ethernet Protocol

Supported Series: Siemens S7-400, S7-1200 and S7-1500

1)PLC Setting

ItemsSettingsNote
ProtocolSiemens S7-XXX 
ConnectionEthernet 
Port No.102 
Device No.Slot (Default 1 for S7-1500/ 2 for S7-1200/ 3 for S7-400) 
HMI No.Rack (Default as 0) 

Slot from TIA Portal is equal to Device No. of V-net

Rack from TIA Portal is equal to HMI No. of V-net

image-20220824162459-3.png

image-20220824163305-2.png

2)Address List

TypeDevice registerHMI registerFormatRangeNote
BitIIM d.o

d:0--9999

o:0-7

 
QQQ d.o

d:0--9999

o:0-7

 
MMM d.o

d:0--9999

o:0-7

 
DB0.DB-DB99.DBDBxDBDBxDBnndddd.o

nn:0-9999,

dddd:0-9999,

o:0-7

nn:DB No.

dddd:address value

o: digit address

WordMMBMB dd:0-99999 
MMWMW dd:0-99999

MW0=MB(0~1)

MW2=MB(2~3)

Address value is a multiple of 2

MMDMD dd:0-99999

MD0=MB(0~3)

MD4=MB(4~7)

Address value is a multiple of 4

IIWIW dd:0-99999 
QQWQW dd:0-99999 
DB0.DB-DB99.DBDBxDBBDBxDBBnndddd

nn:0-9999

dddd:0-9999

nn:DB No.

dddd:address value

DB0.DB-DB99.DBDBxDBWDBxDBWnndddd

nn:0-9999

dddd:0-9999

nn:DB No.

dddd:address value

Address value is a multiple of 2

DB0.DB-DB99.DBDBxDBDDBxDBDnndddd

nn:0-9999

dddd:0-9999

nn:DB No.

dddd:address value

Address value is a multiple of 4

3)Configure the communication protocol

image-20220824163448-3.png

✎Note:

  • The S7-1200 supports simultaneous connection of three devices, so the driver supports simultaneous access to PLC by three V-BOX.
  • V-BOX access PLC, use S7 protocol, access PLC TSAP 02.01 (s7-1200 PROFINET interface only supports three connections, the default support), detailed reference to the system manual of S7-1200.

4)Cable Wiring

image-20220824162342-2.png

Mitsubishi PLC

FX1S,1N,2N Serial Protocol

Supported Series: Mitsubishi FX1S, FX1N, FX2N series

1)V-BOX Settings

ItemSettingsNote
ProtocolMitsubishi FX1S/FX1N/FX2N 
ConnectionRS422/RS485/RS232 
Baud rate9600~115200 
Data bit7/8 
ParityEVEN/Odd/None 
Stop bit1/2 
PLC station No.1~255 

2)Address List

TypeDevice registersHMI registersFormatRangeNote
BitXXXo0~303237 
YYY o0~303237 
MMM d0~99999 
TTT d0~99999 
CCC d0~99999 
SSS d0~99999 
SMSMSM d8000~9999 
WordXXXo0~303237 
YYY o0~303237 
MMM d0~99999 
TTT d0~99999 
CCC d0~199 
DDD d0~7999 
SSS d0~99999 
SDSDSD d8000~9999 

3)Configure the communication protocol

image-20220825102844-3.png

4)Cable Wiring

  • RS422

image-20220825103350-4.png

image-20220825100845-4.png

FX3U,3G,3GA Serial Protocol

Supported Series: Mitsubishi FX3U, FX3G, FX3GA series

1)V-BOX Settings

ItemSettingsNote
ProtocolMitsubishi FX3U/3G/3GA 
ConnectionRS422/RS485/RS232 
Baud rate9600~115200 
Data bit7/8 
ParityEVEN/Odd/None 
Stop bit1/2 
PLC station No.1~255 

2)Address List

TypeDevice registersHMI registersFormatRangeNote
BitXXXo0~303237 
YYY o0~303237 
MMM d0~99999 
TTT d0~99999 
CCC d0~99999 
SSS d0~99999 
SMSMSM d8000~9999 
WordXXXo0~303237 
YYY o0~303237 
MMM d0~99999 
TTT d0~99999 
CCC d0~199 
DDD d0~7999 
SSS d0~99999 
SDSDSD d8000~9999 

3)Configure the communication protocol

image-20220825102649-2.png

4)Cable Wiring

  • RS422

image-20220825103421-5.png

image-20220825100845-4.png

FX5U Serial Protocol

Mitsubishi FX5U series PLC

1)V-BOX Settings

ItemSettingsNote
ProtocolMitsubishi FX5U 
ConnectionRS422/RS485 
Baud rate9600 
Data bit7 
ParityOdd 
Stop bit1 
PLC station No.1~255Need to be the same as PLC settings

2)Address List

TypeDevice registersHMI registersFormatRangeNote
BitXXX o0~303237 
YYY o0~303237 
MMM d0~99999 
BBB h0~7FFF 
FFF d0~32767 
SBSBSB h0~7FFF 
TSTSTS d0~1023 
TCTCTC d0~1023 
STSSTSSTS d0~1023 
STCSTCSTS d0~1023 
CSCSCS d0~1023 
CCCCCC d0~1023 
SMSMSM d0~9999 
LLL d0~32767 
SSS d0~4095 
WordWWW h0~3FF 
TNTNTN d0~1023 
STNSTNSTN d0~1023 
CNCNCN d0~1023 
RRR d0~32767 
SWSWSW h0~7FFF 
ZZZ d0~23 
DDD d0~7999 
SDSDSD d0~11999 

3)PLC Settings (GX Works 3)

Create a blank FX5U project

Find the 485 serial port module in the system navigation bar and double click to enter the settings.

12.PLC Protocol_html_5c9cb13fac1e6c93.png

Select protocol in the setting item, and set parameters.

12.PLC Protocol_html_de942589ca070228.png

Set station number, and [Message Pattern] (Pattern 1 or Pattern 4)

12.PLC Protocol_html_387ec7d00b5feb59.png

Click the [Apply] button to finish the setting.

Click download and select the items as below, then click [execute] to download the configuration to PLC.

12.PLC Protocol_html_cdef1c5ec8cc2105.png

 As soon as download is completed, connect PLC with serial port, then configure it in the [Specify Connection Destination Connection].

Done.

4)Configure the communication protocol

image-20220825104904-1.png

5)Cable Wiring

  • RS422

image-20220825105105-2.png

image-20220825105533-3.png

FX5U Ethernet Protocol

Mitsubishi FX5U series PLC

1)V-BOX Settings

ItemsSettingsNote
ProtocolMitsubishi FX5U 
ConnectionEthernet 
Port No.5002Must be the same as the PLC setting
PLC station No.0 

2)Address List

TypeDevice registersHMI registersFormatRangeNote
BitXXX o0~303237 
YYY o0~303237 
MMM d0~99999 
BBB h0~7FFF 
FFF d0~32767 
SBSBSB h0~7FFF 
TSTSTS d0~1023 
TCTCTC d0~1023 
STSSTSSTS d0~1023 
STCSTCSTS d0~1023 
CSCSCS d0~1023 
CCCCCC d0~1023 
SMSMSM d0~9999 
LLL d0~32767 
SSS d0~4095 
WordWWW h0~3FF 
TNTNTN d0~1023 
STNSTNSTN d0~1023 
CNCNCN d0~1023 
RRR d0~32767 
SWSWSW h0~7FFF 
ZZZ d0~23 
DDD d0~7999 
SDSDSD d0~11999 

3)PLC Settings (GX Works 3)

Find the [Ethernet port] in the navigation area.

12.PLC Protocol_html_8e8f85ace087346c.png

Select [Own Node Settings] in the [Setting Item List];

Set [IP Address], [Subnet Mask], [Default Gateway];

Click [Detailed Settings] into [Ethernet Configuration (Built-in Ethernet Port)] windows;

12.PLC Protocol_html_5d98495052c8c10e.png

Select [SLMP Connection Module] and add into host station as below picture shows;

Set Port number as 5002 (this is necessary settings);

Click [Close with Reflecting the Setting] to save and close window;

12.PLC Protocol_html_14b489fdc6c6589d.png

Click [Apply] to completed Etherenet settings;

Switch to the [On line data operation] interface as below, check the item and click [Execute] to download.

12.PLC Protocol_html_c93025a968a8a9e7.png

4)Configure the communication protocol

图片-20220825112403-1.png

5)电缆布线

12.可编程逻辑控制器Protocol_html_2297240b57346b2a.png

L02 Serial Protocol

Mitsubishi L02 series CPU built-in Ethernet port.

V-BOX Settings

ItemsSettingsNote
ProtocolMIT L02 CPU MELSEC 
ConnectionEthernet 
Port No.1025Must be the same as the PLC setting
PLC station No.0Must be the same as the PLC setting

Address List

TypeDevice registersHMI registersFormatRangeNote
BitXXX h0~FFFF 
BitYYY h0~FFFF 
BitMMM d0~9999 
BitLLL d0~9999 
BitFFF d0~9999 
BitBBB h0~FFFF 
BitVVV d0~2047 
BitTCTCTC d0~9999 
BitSSSSSS d0~9999 
BitSCSCSC d0~9999 
BitCSCSCS d0~9999 
BitCCCCCC d0~9999 
BitSBSBSB h0~FFFF 
BitSMSMSM d0~2047 
BitSTSSTSSTS d0~1023 
BitSSS d0~9999 
BitDXDXDX h0~FFFF 
BitDYDYDY h0~FFFF 
BitTSTSTS d0~9999 
BitDbitDbitDbit d.d0~99999.0~15 
WordWWW h0~FFFF 
WordTNTNTN d0~99999 
WordSNSNSN d0~99999 
WordCNCNCN d0~99999 
WordRRR d0~99999 
WordSWSWSW h0~FFFF 
WordZZZ d0~99999 
WordZRZRZR h0~FFFF 
WordDDD d0~99999 

Communication Settings

Cable Wiring

L02 Ethernet Protocol

Mitsubishi L series CPU built-in Ethernet port.

1)V-BOX Settings

ItemsSettingsNote
ProtocolMIT L02 CPU MELSEC 
ConnectionEthernet 
Port No.1025Must be the same as the PLC setting
PLC station No.0Must be the same as the PLC setting

2)Address List

TypeDevice registersHMI registersFormatRangeNote
BitXXX h0~FFFF 
BitYYY h0~FFFF 
BitMMM d0~9999 
BitLLL d0~9999 
BitFFF d0~9999 
BitBBB h0~FFFF 
BitVVV d0~2047 
BitTCTCTC d0~9999 
BitSSSSSS d0~9999 
BitSCSCSC d0~9999 
BitCSCSCS d0~9999 
BitCCCCCC d0~9999 
BitSBSBSB h0~FFFF 
BitSMSMSM d0~2047 
BitSTSSTSSTS d0~1023 
BitSSS d0~9999 
BitDXDXDX h0~FFFF 
BitDYDYDY h0~FFFF 
BitTSTSTS d0~9999 
BitDbitDbitDbit d.d0~99999.0~15 
WordWWW h0~FFFF 
WordTNTNTN d0~99999 
WordSNSNSN d0~99999 
WordCNCNCN d0~99999 
WordRRR d0~99999 
WordSWSWSW h0~FFFF 
WordZZZ d0~99999 
WordZRZRZR h0~FFFF 
WordDDD d0~99999 

3)PLC Settings (GX Works2 )

Create a project

Set PLC IP, subnet mask and gateway;

Select [Binary Code] as communication data code;

12.PLC Protocol_html_776e17505f3fc6c0.png

Set PLC port number, for example 1025

12.PLC Protocol_html_8d0d1a22d388f70b.png

Save settings;

Download project into PLC device;

Restart PLC device;

4)Configure the communication protocol

image-20220825142659-1.png

5)Cable Wiring

12.PLC Protocol_html_2297240b57346b2a.png

QJ71E71 Ethernet Protocol

Mitsubishi QJ71E71 Ethernet communication module;

1)V-BOX Settings

ItemsSettingsNote
ProtocolMIT QJ71E71 MELSEC 
ConnectionEthernet 
Port No.1025Must be the same as the PLC setting
PLC station No.0Must be the same as the PLC setting

2)Address List

TypeDevice registersHMI registersFormatRangeNote
BitXXX h0~1FFF 
YYY h0~1FFF 
MMM d0~99999 
LLL d0~8191 
FFF d0~2047 
BBB h0~1FFF 
VVV d0~2047 
TSTSTS d0~2047 
TCTCTC d0~2047 
SSSSSS d0~2047 
SCSCSC d0~2047 
CSCSCS d0~1023 
CCCCCC d0~1023 
SBSBSB h0~7FF 
SSS d0~8191 
DXDXDX h0~1FFF 
DYDYDY h0~1FFF 
SMSMSM d8000~9999 
WordSDSDSD d0~2047 
DDD d0~12287 
WWW h0~1FFF 
TNTNTN d0~2047 
SNSNSN d0~2047 
CNCNCN d0~1023 
RRR d0~32767 
SWSWSW h0~7FF 
ZZZ d0~15 
ZRZRZR h0~FE7FF 

3)PLC Settings(GX Works2)

  • Click [Ethernet/CC IE/MELSECNET];
  • Please select [Ethernet] as network type;
  • Set station I/O number according to situation (For example, 0000 means that the module is connected to PLC CPU in first order);
  • Select [Online] as Mode;
  • Click [Operation setting] to set IP;
  • Select [Binary Code] as [Communication Data Code];
  • Set protocol: TCP;
  • Set [unpassive] in [Open system];
  • Set [receive] in [Fixed buffer];
  • Set [procedure Exist] in [Fixed buffer communication];
  • Disable [Pairing open];
  • Set [No confirm] in [Existence confirmation];
  • Host station port number: 1025;
  • Save settings;
  • Download project into PLC and restart it

4)Configure the communication protocol

image-20220825143728-1.png

5)Cable Wiring

12.PLC Protocol_html_2297240b57346b2a.png

台达 PLC

DVP 以太网协议

下载链接

DVP 串行协议

下载链接

欧姆龙可编程逻辑控制器

CP1 系列协议

下载链接

CJ2M 系列协议

下载链接

Modbus RTU

V-BOX 作为主

选择协议“Modbus RTU Slave(All Fuction)”,

然后设置波特率,端口,停止位,数据位,奇偶校验

1624342015914-382.png

V-BOX 作为从站

选择协议“Modbus RTU Master”

然后设置波特率,端口,停止位,数据位,奇偶校验

1624348709622-711.png

地址列表

类型注册函数代码和描述
304(读取输入寄存器:读取一个或多个输入寄存器中的当前二进制值)
06 (write single register: write a binary value to a holding register)
10 (write values to multiple addresses )
403 (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 )
W603 (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 )
W1603 (read holding register: read current binary value in one or more holding registers)
10 (write values to multiple addresses )
Bit001 (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)
102 (Read the input state)
05 (Force a single coil to force the on/off state of a logic coil)
0F (Write multiple bits)
W501 (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)
W1501 (Read coil state to obtain the current state of a set of logic coils)
0F (Write multiple bits)

communicate with VB inverter

download link

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

--------------------------------------------------------------------------------------------------------------------------------------------------------------------