MODBUS Master Protocol
From Smart LCD
MODBUS HOST Script Operation
Script Functions
TOPWAY Smart LCD with MODBUS host interface can direct access MODBUS slave device. The MODBUS Host Script Editor is for building the accessing relationship script. TOPWAY Smart LCD MODBUS Scrip is a runtime script that runs periodically to link up the data in between.
| Smart LCD
VP Variables |
TOPWAY Smart LCD
MODBUS Script |
MODBUS slave
device data | ||
|---|---|---|---|---|
VP_N16 VP_N32 VP_N64 VP_G16 |
<--> | <--> |
Coils Contacts Registers Holding Registers |
Script Read Operation
Script read operation initials by Script itself, and call the MODBUS slave to provide the data. When data received, it will copy it to the predefined mapped address based on Address Mapping.
| Smart LCD
VP Variables |
TOPWAY Smart LCD
MODBUS Script |
MODBUS slave
device data | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
VP_N16 VP_N32 VP_N64 VP_G16 |
<--- |
|
<--- |
Coils Contacts Registers Holding Registers | ||||||
| ---> | ||||||||||
Script Write Operation
Script write operation initials by Script itself, and write to the Smart LCD VP Variables. Then the data will send to the mapped MODBUS slave address based on Address Mapping.
In case, the Smart LCD display project trigged a VP (e.g. a VP updated by an onscreen touch key) where it was mapped in the Address Mapping. The data will send to the mapped MODBUS slave address, accordingly.
MODBUS HOST SCRIPT EDITOR
Quick Start (Example)
1. Start the Script Editor In TOPWAY SGTools; Menu à Tools à MODBUS Product Script Editor
2. Scrip Config Select Script* keep the properties as is
3. Add a Address Mapping (16bit data)
Select Address Mapping; Press
in the tool bar; Select the newly add Relative;
Config its properties
- set VP type as N16
- choose VP address as 0x08000
- set MODBUS type as Holding_Reg_4x
- set MODBUS address as 0x0000
- set MODBUS length 1
- set slave address as 1
e.g. Map Smart LCD VP_N16 (0x080000) with MODBUS slave (ID=1) Holding_Reg_4x (0x0000)
4. Add a Address Mapping (32bit data)
Select Address Mapping; Press
in the tool bar; Select the newly add Relative;
Config the related properties
- set VP type as N32
- choose VP address as 0x02000
- set MODBUS type as Holding_Reg_4x
- set MODBUS address as 0x0030
- set MODBUS length 2
- set slave address as 1
e.g. Map Smart LCD VP_N32 (0x020000) with MODBUS slave (ID=1) Holding_Reg_4x (0x0030 and 0x0031) note. Holding_Reg_4x 0x0030 for VP_N32 MSB Holding_Reg_4x 0x0031 for VP_N32 LSB
5. Add a Global Logical Process
Select Global under Logical Processing; Press
in the tool bar; Select the newly add Logical Process;
Config the Logical Process
- Perform Operation as Read
- Perform Connotation as always
- Slave ID as 1
- Operation Variable as 0x0000
- Modus Len as 1
e.g. Make a scrip that periodically read MODBUS slave (ID=1) Holding_Reg_4x (0x0000) note. Based on above defined mapping, result will store into Smart LCD VP_N16 (0x080000)
6. Add a Page for Logical Processing
Select Logical Processing; Press
in the tool bar
7. Add a Page Logical Process
Select Page(n) under Logical Processing; Press
in the tool bar; Select the newly add Logical Process
Config the Logical Process
- Perform Operation as Write
- Perform Connotation as always
- Slave ID as 1
- Operation Variable as 0x080000
- Operation Value Type as const
- Operation Value as 255
e.g. Make a scrip that periodically write 255 to Smart LCD VP_N16 (0x080000) when Page[0] is showing on screen note. Based on above defined mapping, 255 will also send to MODBUS slave (ID=1) Holding_Reg_4x (0x0000)
8. Save and Compile pressto save; press
to compile1.
Tool Bar
| Import | Select a .xml file to be import, and put it into the script | |||||||||
| Save | Save the edited result into project_directory/Resource/Script.xml | |||||||||
| Compile | Compile the script.xml and store into project_directory/Resource/Modbus.xml | |||||||||
| Add |
| |||||||||
| Del | Delete a sub-node | |||||||||
| COPY | Copy a sub-node | |||||||||
| Paste | Paste a copied sub-node | |||||||||
| Clear | Clear all sub-node | |||||||||
| Sort | Sort the sub-node by VP address order | |||||||||
| Move Up | Move a sub-node up | |||||||||
| Move Down | Move a sub-node down | |||||||||
| Extend | reserved option; allow a single fetch in complied script that address more than 64 data |
Address Mapping Options
| Properities | Options |
|---|---|
| VP Resource | VP_N16: 16bit number variable
VP_N32: 32bit number variable VP_N64: 64bit number variable VP_G16: 16bit graphic variable |
| VP address | Select the defined VP in the display project |
| VP Len | No. of the successive VP data, 1~255 |
| MODBUS Type | Coil_0x / Input_1x / Input_Reg_3x / Holding_Reg_4x (*1) |
| MODBUS Address | Modbus Address, 0x0000~0xFFFF |
| MODBUS Len | No. of successive MODBUS data |
| Slave ID | Slave ID, 1~247 |
| Label | A text string for tag (option) |
Note
*1.
| MODBUS Type | Descriptions |
|---|---|
| Coil_0x | Discrete Output Coils (1bit) (RW) |
| Input_1x | Discrete Input / Contacts (1bit) (R) |
| Input_Reg_3x | Analog Input / Registers (16bit) (R) |
| Holding_Register_4x | Analog Output / Holding Registers (16bit) (RW) |
Logical Process Options
| Properties | Options |
|---|---|
| Perform Range | Perform in, Global / Page[n] |
| Perform Operation | Read / BLCtrl / BeepCtrl / Write |
| Perform Condition | ">", "==", "<", "!=", ">=", "<=", "always" |
| Condition Variable | Select the defined VP in the display project |
| Condition Value | A decimal value for condition check |
| Slave ID | Slave ID, 1~247 |
| Operation Variable | Read: Select a MODBUS data address (MODBUS address may input manually) (*2.)
Write: Select a VP variable address (*3.) |
| VP Len | No. of the successive VP data, 1~255 |
| Operation Value Type | Const / Variable |
| MODBUS Len | No. of successive MODBUS data, 1~10000 |
| Label | A text string for tag (option) |
Note
*1.
| Address | Descriptions |
|---|---|
| 0x:0x0001 | Coil_0x Address 0x0001 |
| 1x:0x0001 | Input_1x Address 0x0001 |
| 3x:0x0001 | Input_Reg_3x Address 0x0001 |
| 4x:0x0001 | Holding_Reg_4x 0x0001 |
*2. Read result will store back to the VP variable address that defined in the Address Mapping.
*3. Data Write to the VP variable will send to the mapped MODBUS slave address that defined in the Address Mapping.
Page[n] Options
| Properities | Options |
|---|---|
| Operation Page | Select the defined Page in the display project |
Script Format (reference)
Address Mapping
Link up Smart LCD VP variable address with MODBUS address for showing it in sub-node of the editor
Format: [Label] Relative[VP_add, mb_type: mb_address], vplen[vp_length], mblen[mb_length], slaveID[slave_id]]
Logical Process Type
- Global: process periodically
- Page[n] : processes during the Page[n] is showing on screen. (n is the PAGE ID in the Smart LCD)
Logical Process Functions
- Read: read data form the slave device.
- BLCtrl: control the Smart LCD brightness by a const or a variable value
- BeepCtrl: sound the buzzer by a const or a variable value (0=off, 1=on)
- Write: write a data to a slave with a const or a variable value.
| Functions | Format |
|---|---|
| Read | [Label] Read, if(@Conditional_Variable Perform_Condition Condition_Value), mbAddr[mb_type: mb_add], mblen[mb_len], slaveID[dev_id] |
| BLCtrl | [Label] BLCtrl, if(@Conditional_Variable Perform_Condition Condition_Value), Const[val] or Variable[VP_add] |
| BeepCtrl | [Label] BeepCtrl, if(@Conditional_Variable Perform_Condition Condition_Value), Const[val] or Variable[VP_add] |
| Write | [Label] BeepCtrl, if(@Conditional_Variable Perform_Condition Condition_Value) = Const[val] or Variable[VP_add], vplen[vp_len] |
Note
*1. Perform_Condition options: "always", ">","==","<","!=",">=","<="