Using Unserver to Connect to PLCs over Modbus RTU

Using Unserver to Connect to PLCs over Modbus RTU

What is Unserver?
[Unserver](https://unserver.xyz) is a software tool designed to simplify communication with Modbus
RTU networks.It’s useful as a data acquisition layer for creating HMIs and testing Modbus networks.
How it Works?
Unserver provides an HTTP API over a Modbus network. The API allows clients to work with Modbus data using predefined objects called “tags”. The user creates tags during configuration.
![HMI applications connect to Modbus networks via Unserver]
 
Using Unserver to Connect to PLCs over Modbus RTU
Using Unserver to Connect to PLCs over Modbus RTU
Each tag is a group of properties, which correspond to specific Modbus addresses.
Each property is defined with a specific data type, for example int16, BCD16 or float32.
When a client requests read/write of a tag, Unserver “translates” it into appropriate Modbus requests.
![Unserver automatically creates HTTP API based on configuration]
Getting Started
·
First, download the latest build at [Unserver official
site](https://unserver.xyz).
The trial/non-commercial license of Unserver is free.
·
To install Unserver, simply extract the installation package.
·
Now open “network.json” in a text editor to configure the correct serial port used for Modbus connection:
“`json
“port”: {“name”: “COM1”,

“baudRate”: 9600,

“dataBits”: 8,

“parity”: “none”,

“stopBits”: 1,

“timeoutMs”: 500
}
“`
·
In the same file specify the address of one or more of your Modbus
devices:
“`json
“devices”: [
    {

“alias”: “plc1”,

“address”: “1”
    }
]
“`
All
configuration files use JSON format, which is an easy and programmer-friendly way of specifying text-based configuration.
·
The next step is creating some tags.
Open
“tags.json” and review the default tag configuration, which looks
like this:
“`json
[
  {

“name”: “getting-started”, “device”:
“device1”,

“properties”: [
      {
“name”: “test-property”, “address”:
“HR0”, “type”: “numeric”, “raw”:
“int16” }
    ]
  }
]
“`
·
This configuration creates a tag named `getting-started` with one
property – `test-property`.The property is mapped to the Modbus address `HR0`
as a 16-bit signed integer.
·
You can edit the “address” setting if you wish to use another Modbus register.
·
Make sure to save both configuration files before continuing.
Test Your Tag
·
Now we are ready to run Unserver.
·        First, start `unserver.exe`. During the first run it will ask your permission to bind to an http endpoint.If the configuration is valid, you should not see any error messages in the console.
·        Now make sure you PC is connected to the Modbus device via the port you specified in `network.json`
·
Open a web browser and navigate to http://localhost:9000/tags/getting-started.You should now see the value of the
tag in the browser window.
Build a Test Web Page
Create a file named `index.html` with the following content:
“`html

       

            var value = unserver.watchProperty('getting-started.test-property', function(value){

                document.write('tag value: ' + value);

            });

       




“`
This creates an empty web page
The script will call Unserver and update the page every time a new value of `test-property` is received.
What’s Next
We have covered the basics of getting started with Unserver.
To use more advanced data acquisition features:
– View the [complete documentation](https://unserver.xyz/docs)

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro