How to create associated variables (Modbus configuration control tutorial 2)

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

How to create associated variables (Modbus configuration control tutorial 2)

2 How to create associated variables

Jump symbol serial port screen modbus protocol supports the creation of coils, discrete inputs, holding registers, input registers, content variables, and system variables, as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图
Variable typeRelated description
CoilsParticipating in communication: 0x01/0x05/0x0F
Discrete InputParticipating in communication: 0x02
Holding RegisterParticipating in communication: 0x03/0x06/0x10
Input RegisterParticipating in communication: 0x04
Memory variablesdo not participate in communication: used as intermediate variables, to record some information, etc.
System variablesdo not participate in communication: such as system baud rate, running time, etc.

The screen configuration in this chapter is set to host mode, introducing the creation and binding of coils, discrete inputs, hold registers, input registers, and system variables.

Scope of application: full series.

For protocol activation and variable-related instructions, refer to the link: "Modbus Basic Parameter Description".

2.1 Coils

The [Coil] interface is used to display and control the state of the "Coil" variable in the MODBUS protocol. The button control is directly bound to the "Coil" type variable. The state of the coil is 0 or 1, corresponding to the button being up (0) or pressed (1). After running, when the "Coil" value at that address changes, the state of the button control changes in real time. Similarly, by clicking the button, the state of the coil variable type corresponding to the address in the slave device can be changed

Variable configuration

Create a "unit status" variable, set the variable type to "coil", add child nodes "on/off" and "run/stop", configure the variable address to 0x0000, and refer to the Modbus Basic Parameter Description for detailed settings, as shown below.

How to create associated variables (Modbus configuration control tutorial 2)插图1

Screen configuration

Add a button control (Control ID: 1) to the screen. In the property panel of the button control, set the associated variable to "Unit Status/On/Off". The operation style of the button is a switch, as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图2

Run Preview

Through the above two steps, the button control with Control ID 1 is associated with the variable "Unit Status/On/Off". At this point, compile the project and run the virtual serial port screen, establishing a connection with the MODBUS Slave software. The button control displays the status of "Unit Status/On/Off". Simultaneously, clicking the button control changes the state of the variable "Unit Status/On/Off". Similarly, the button control with Control ID 2 is associated with the variable through the above method, achieving corresponding status display and control functions. As shown below

How to create associated variables (Modbus configuration control tutorial 2)插图3

2.2 Discrete Input

The [Discrete Input] screen displays the status of the "discrete input" variable in the MODBUS protocol. The icon control is directly bound to the "discrete input" type of variable. The icon control will display the status of the variable, and when the value of the "discrete input" at that address changes, the icon control will correspondingly change

Variable Configuration

Add a variable: Create a "Unit Fault" variable, add a child node "Compressor Low Pressure", set the variable type to "Discrete Input", configure the variable address to 0x0000, and refer to the Modbus Basic Parameter Description for detailed settings, as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图4

Screen Configuration

Add an icon control (Control ID: 1) to the screen. In the property panel of the icon control, set the associated variable to "Unit Fault/Compressor Low Pressure". Similarly, bind the icon controls with IDs 2 to 4 to their corresponding variables. Refer to the "Configuration Controls Tutorial - Icon Controls" for instructions on how to create, as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图5

Run Preview

Through the above two steps, the icon control with Control ID 1 is associated with the variable "Unit Fault/Compressor Low Pressure". At this point, compile the project and run the virtual serial port screen, establishing a connection with the MODBUS Slave software. The icon control displays the status of the variable "Unit Fault/Compressor Low Pressure".

How to create associated variables (Modbus configuration control tutorial 2)插图6

2.3 Maintain registers

The "Hold Register" screen directly displays the value of the "Hold Register" variable in the MODBUS protocol. The text control is directly bound to the "Hold Register" type variable. The text control will display the value of the variable. When the value of the "Hold Register" at this address changes, the text control will correspondingly change.

Variable Configuration

Add Variable: Create a "Set Temperature" variable, set the variable type to "Hold Register", and configure the variable address to 0x0000. If this variable represents temperature, and the slave transmits a value of 225℃ while the actual temperature is 22.50℃, then the scaling ratio between the actual value and the transmitted value is 0.1, and the offset value is 0. Therefore: Set "Value Conversion" to "Yes", "Scaling" to "0.1", and "Translation" to "0". For detailed setting instructions, refer to the Modbus Basic Parameter Description, as shown below.

How to create associated variables (Modbus configuration control tutorial 2)插图7

Screen Configuration

Add a text control (control ID: 1) to the screen, as shown in Figure 4-14. In the property panel of the text control, set the associated variable to "Set Temperature", and the input method to "Pop-up System Keyboard Input (user host can input)" mode, as shown below.

How to create associated variables (Modbus configuration control tutorial 2)插图7

Run Preview

Through the above two steps, the text control with control ID 1 is associated with the variable "Set Temperature". At this point, compile the project and run the virtual serial port screen, establish a connection with the MODBUS Slave software, and the text control will display the value of the variable "Set Temperature". Click the text control to pop up the keyboard, where you can set the value of the variable "Set Temperature".

How to create associated variables (Modbus configuration control tutorial 2)插图8

2.4 Input register

The [Input Register] screen directly displays the value of the "Input Register" variable in the MODBUS protocol. The text control is directly bound to a variable of type "Input Register", and the text control will display the value of the variable. When the value of the "Input Register" at that address changes, the text control will correspondingly change

Variable configuration

Create a "temperature" variable, set the variable type to "input register", and configure the variable address to 0x0000, as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图9

Screen configuration

Add a text control (Control ID: 1) to the screen. In the property panel of the text control, set the associated variable to "temperature" as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图10

Run Preview

Through the above two steps, the text control with Control ID 1 is associated with the "temperature" at address 0x0000. At this point, compile the project and run the virtual serial port screen, establish a connection with the MODBUS Slave software, and the text control will display the value of the hold register at address 0x0000. Similarly, after associating the text controls with Control IDs 2, 3, and 4 with different variables through the above method, they can display the values of the corresponding addresses, as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图11

2.5 System Variables

[System Variables] System variables are predefined variables in the system, facilitating direct access. These predefined variables on the screen include baud rate (readable), backlight brightness (readable and writable), buzzer switch (1 enables the buzzer, 0 disables it, readable and writable), communication fault (0 indicates normal, non-0 indicates fault, readable), current screen ID (readable and writable), running time (unit: minutes, readable), date (readable), etc

Variable Configuration

Add a variable: Create a "backlight brightness" variable, set the variable type to "System Variable", and set the system variable parameter to "backlight brightness". For detailed settings, refer to the Modbus Basic Parameter Description, as shown below

How to create associated variables (Modbus configuration control tutorial 2)插图12

Screen Configuration

Add a progress bar control (Control ID: 2) and a slider control (Control ID: 3) to the screen. In the property panel of the progress bar control, set the sliding notification to "Associated Slider"; in the property panel of the slider control, set the associated variable to "backlight brightness". For specific applications of the slider control and progress bar control, refer to the Tutorial on Configuring Controls - Tutorial on Slider Control, as shown below

Run Preview

Through the above two steps, the slider control with Control ID 2 is associated with the memory variable "backlight brightness"; at this point, compile the project and run the virtual serial port screen. Sliding the cursor of the "Slider Control" can control the backlight brightness of the screen.

How to create associated variables (Modbus configuration control tutorial 2)插图13
Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.