Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing a MODBUS Server for Serial Display Using AWTK

Tech 1

Model Name: modbus_server

Purpose: This model enables service provision via the MODBUS protocol, allowing remote clients (masters) to acces data.

Instantiation

A model instance is created using modbus_server.

Example:

<window v-model="modbus_server" name="main_view">

Configuration file location: design/default/data/modbus.json

Configuration File Structure

The configuration uses a JSON format.

Basic Settings

  • url: Defines the connection endpoint for the slave device.
  • unit_id: Identifier for the slave device (not required for TCP).

Example entry:

"url": "tcp://localhost:502"

Channel Definitions

Multiple channels can be defined within the channels array.

Each channel supports specific MODBUS function codes based on its type:

  • bits: Accessible with function code 1 (read) and 15 (write).
  • input_bits: Read-only using function code 2.
  • registers: Read with function code 3; write with function code 16.
  • input_registers: Read-only with function code 4.

Parameters include:

  • name: Identifier used in UI bindings.
  • start: Starting address of the register block.
  • length: Number of registers/bits.

Sample definition:

"channels": [
  {
    "name": "bits",
    "writable": true,
    "start": 0,
    "length": 100
  },
  {
    "name": "input_bits",
    "start": 0,
    "length": 200
  },
  {
    "name": "registers",
    "writable": true,
    "start": 0,
    "length": 300
  },
  {
    "name": "input_registers",
    "start": 0,
    "length": 400
  }
]

Variable Mapping

To enhance usability, variables can map to specific addresses with in channels.

Variable declaration example:

"variables": {
  "temperature_current": "input_registers.word[0]",
  "humidity_current": "input_registers.word[1]",
  "temperature_target": "registers.word[0]",
  "humidity_target": "registers.word[1]"
}

Usage in UI components:

<label text="Connection Endpoint" />
<label v-data:value="{url}" />
<label text="Device Identifier" />
<label v-data:value="{unit_id}" />
<label text="Current Temperature" />
<edit input_type="int" v-data:text="{temperature_current}" />
<label text="Current Humidity" />
<edit input_type="int" v-data:text="{humidity_current}" />

<label text="Target Temperature (modified by client)" />
<label v-data:text="{temperature_target}" />
<label text="Target Humidity (modified by client)" />
<label v-data:text="{humidity_target}" />

Data Access

Refer to documentation on modbus_client for accessing channel data.

Predefined Properties

Property Type Description
url string Connection URI
unit_id int Device identifier

Example usage:

<label text="Endpoint" />
<label v-data:value="{url}" />
<label text="ID" />
<label v-data:value="{unit_id}" />

Available Commands

None available.

Reference Implementation

See demo project: demo_modbus_server_registers

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.