MODBUS Master Protocol: Difference between revisions

From Smart LCD
Tag: New redirect
 
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
#REDIRECT [[MODBUS HOST Script]]
Smart LCD MODBUS Master Product can direct access MODBUS slave devices for real-time control and access.
 
== MODBUS Master Product Script Operation ==
 
=== Script Functions ===
TOPWAY Smart LCD with MODBUS Master interface can direct access MODBUS Slave device.
The Script Editor is for building the accessing relationship script.
TOPWAY Smart LCD MODBUS host script 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
|<-->
|[[File:Cycle image.png|128x128px]]
|<-->
|
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
|-
| rowspan="2" |
VP_N16
VP_N32
VP_N64
VP_G16
|<---
|
{| class="wikitable"
! colspan="3" |Address Maping
|-
|VP
|<-->
|MB
|}
|<---
| rowspan="2" |
Coils
Contacts
Registers
Holding Registers
|-
|
|[[File:Cycle image-R.png|128x128px]]
| --->
|}
=== 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.
 
{|
!
!Smart LCD
VP Variables
!
!TOPWAY Smart LCD
MODBUS Script
!
!MODBUS slave
device data
|-
| rowspan="2" |Touch
===>
| rowspan="2" |
VP_N16
VP_N32
VP_N64
VP_G16
| --->
|
{| class="wikitable"
! colspan="3" |Address Maping
|-
|VP
|<-->
|MB
|}
| --->
| rowspan="2" |
Coils
Contacts
Registers
Holding Registers
|-
|<---
|[[File:Cycle image-W.png|128x128px]]
|
|}
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.
 
== SCRIPT EDITOR ==
 
=== Quick Start (Example) ===
'''1. Start the Script Editor'''
In TOPWAY SGTools; Menu à Tools à MODBUS Product Script Editor
[[File:MODBUS HOST SCRIPT EDITOR-SGT start.png|320x320px]]
'''2. Scrip Config'''
Select Script*
keep the properties as is
[[File:MODBUS HOST SCRIPT EDITOR-config.png|640x640px]]
'''3. Add a Address Mapping (16bit data)'''
Select Address Mapping; Press [[File:MODBUS SCRIPT EDITOR-add.png]] 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)
[[File:MODBUS HOST SCRIPT EDITOR-Mapping01.png|640x640px]]
'''4. Add a Address Mapping (32bit data)'''
Select Address Mapping; Press [[File:MODBUS SCRIPT EDITOR-add.png]] 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
[[File:MODBUS HOST SCRIPT EDITOR-mapping 02.png|640x640px]]
'''5. Add a Global Logical Process'''
Select Global under Logical Processing; Press [[File:MODBUS SCRIPT EDITOR-add.png]] 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)
[[File:MODBUS HOST SCRIPT EDITOR-Global process.png|640x640px]]
'''6. Add a Page for Logical Processing'''
Select Logical Processing; Press [[File:MODBUS SCRIPT EDITOR-add.png]] in the tool bar
[[File:MODBUS HOST SCRIPT EDITOR-page process.png|640x640px]]
'''7. Add a Page Logical Process'''
Select Page(n) under Logical Processing; Press [[File:MODBUS SCRIPT EDITOR-add.png]] 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) <u>when Page[0] is showing on screen</u>
note. Based on above defined mapping, 255 will also send to MODBUS slave (ID=1) Holding_Reg_4x (0x0000)
[[File:MODBUS HOST SCRIPT EDITOR-page process Add.png|640x640px]]
'''8. Save and Compile'''
press [[File:MODBUS SCRIPT EDITOR-save.png]] to save; press [[File:MODBUS SCRIPT EDITOR-compile.png]] to compile1.
 
=== Tool Bar ===
{| class="wikitable"
|-
|[[File:MODBUS SCRIPT EDITOR-open.png|38x38px]]
|'''Import'''
|Select a .xml file to be import, and put it into the script
|-
|[[File:MODBUS SCRIPT EDITOR-save.png]]
|'''Save'''
|Save the edited result into project_directory/Resource/Script.xml
|-
|[[File:MODBUS SCRIPT EDITOR-compile.png]]
|'''Compile'''
|Compile the script.xml and store into project_directory/Resource/Modbus.xml
|-
|[[File:MODBUS SCRIPT EDITOR-add.png]]
|'''Add'''
|
{| class="wikitable"
|Address Mapping
|add a Address  Mapping sub-node.
|-
|Logical Processing
|Add Page[n] sub-node,  where Page[n] is in the current project
|-
|Global
|add Logical  Processing sub-node.
|-
|Page[n]
|add add Logical  Processing sub-node in Page[n]
|}
|-
|[[File:MODBUS SCRIPT EDITOR-del.png]]
|'''Del'''
|Delete a sub-node
|-
|[[File:MODBUS SCRIPT EDITOR-copy.png]]
|'''COPY'''
|Copy a sub-node
|-
|[[File:MODBUS SCRIPT EDITOR-paste.png]]
|'''Paste'''
|Paste a copied sub-node
|-
|[[File:MODBUS SCRIPT EDITOR-clear.png]]
|'''Clear'''
|Clear all sub-node
|-
|[[File:MODBUS SCRIPT EDITOR-sort.png]]
|'''Sort'''
|Sort the sub-node by VP address order
|-
|[[File:MODBUS SCRIPT EDITOR-move up.png]]
|'''Move Up'''
|Move a sub-node up
|-
|[[File:MODBUS SCRIPT EDITOR-move dn.png]]
|'''Move Down'''
|Move a sub-node down
|-
|[[File:MODBUS SCRIPT EDITOR-extend.png]]
|'''Extend'''
|reserved option; allow a single fetch in complied script that address more than 64 data
|}
 
=== Address Mapping Options ===
{| class="wikitable"
!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'''
 
<nowiki>*</nowiki>1.
{| class="wikitable"
!'''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 ===
{| class="wikitable"
!'''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'''
 
<nowiki>*</nowiki>1.
{| class="wikitable"
!'''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
|}
<nowiki>*</nowiki>2. Read result will store back to the VP variable address that defined in the Address Mapping.
 
<nowiki>*</nowiki>3. Data Write to the VP variable will send to the mapped MODBUS slave address that defined in the Address Mapping.
 
=== Page[n] Options ===
{| class="wikitable"
!'''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.
 
{| class="wikitable"
!'''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'''
 
<nowiki>*</nowiki>1. Perform_Condition options: "always", ">","==","<","!=",">=","<="

Latest revision as of 16:42, 9 June 2025

Smart LCD MODBUS Master Product can direct access MODBUS slave devices for real-time control and access.

MODBUS Master Product Script Operation

Script Functions

TOPWAY Smart LCD with MODBUS Master interface can direct access MODBUS Slave device.
The Script Editor is for building the accessing relationship script.
TOPWAY Smart LCD MODBUS host script 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
<---
Address Maping
VP <--> MB
<---
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.
Smart LCD

VP Variables

TOPWAY Smart LCD

MODBUS Script

MODBUS slave

device data

Touch

===>

VP_N16
VP_N32
VP_N64
VP_G16
--->
Address Maping
VP <--> MB
--->
Coils
Contacts
Registers
Holding Registers
<---
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.

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
press  to 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
Address Mapping add a Address Mapping sub-node.
Logical Processing Add Page[n] sub-node, where Page[n] is in the current project
Global add Logical Processing sub-node.
Page[n] add add Logical Processing sub-node in Page[n]
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", ">","==","<","!=",">=","<="