Getting Started

Index > Getting Started

This section will demonstrate the most basic configuration of Unserver to communicate with a single Modbus device.

To learn about more advanced configuration options, use the following pages: configuration, tags, API

Prerequisites

  • Unserver should be installed on your PC
  • A Modbus RTU or TCP device/network, physically connected to the PC

Step 1: Configure Unserver

Open network.json - a text file located in Unserver working directory. The purpose of network.json is to setup communication links used by Unserver to read and write data.

Adjust the configuration file to match your setup. For example, use the following code if you have a Modbus TCP device:

{
  // list of communication links used by Unserver
  "links":[
    {
      "name": "demo-link",
      "protocol": "modbus-tcp",
      "settings": {
        "ip": "127.0.0.1",
        "port": 502
      }
    }
  ],
  // list of devices connected to communication links
  "devices": [
    {
      "name": "demo-device",
      "link": "demo-link"
      "address": "1"
    }
  ],
  // API endpoint configuration
  "api": {
    "port": 9000
  }
}

Adjust the ip property of the link to match the IP address of your Modbus device.

Adjust the address property to match Slave ID of the device.

To connect to a Modbus RTU device, use a different configuration similar to this:

{
  // list of communication links used by Unserver
  "links":[
    {
      "name": "demo-link",
      "protocol": "modbus-rtu",
      "settings": {
        "port": "COM1",
        "baudRate": 9600,    
        "dataBits": 8,
        "parity": "none",
        "stopBits": 1,
        "timeoutMs": 500
      }
    }
  ],
  // list of devices connected to communication links
  "devices": [
    {
      "name": "demo-device",
      "link": "demo-link"
      "address": "1"
    }
  ],
  // API endpoint configuration
  "api": {
    "port": 9000
  }
}

Adjust the serial port setting to match your setup.

In both cases above, we have initialized a Modbus communication link named demo-link and added one device named demo-device.

The next step is defining some tags.

Step 2: Create Tags

The purpose of the ‘tags.json’ file is to configure ‘tags’, which map individual Modbus addresses onto Unserver API endpoints.

Open tags.json, and put the following code in it:

[
  {
    "name": "demo-tag", "device": "demo-device", 
    "properties": [
      // you can change 'HR0' to another Modbus address
      { "name": "demo-property", "address": "HR0" }
    ]
  }
]

With this configuration we have created one tag: demo-tag with a single property: test-property.

The value of the property will be read/written using Holding Register 0 of the device and interpreted as a 16-bit integer.

Step 3: Test the Tag

Run unserver.exe and make sure there are no error messages in the console. If there are errors, see troubleshooting startup errors for possible solutions, as the issue is probably a simple misconfiguration.

In a web browser navigate to http://localhost:9000/tags/demo-tag

You should now see the current value of the tag:

{
    "success":true,
    "name":"demo-tag",
    "data":{
        "demo-property": 0
    }
}

Or you will see an unsuccessful response:

{
    "success":false,
    "name":"demo-tag",
    "message":"Timeout while communicating with a field device"
}

This means Unserver does not get a response from the device.

Again, if something doesn’t work, please refer to the troubleshooting page for solutions.

What’s Next

FREE TRIALLearned Something? Try it for yourself with free community license.Download Now

Never Miss an Update

If you enjoy our products or posts, please subscribe. You will get our best content via email.
Unsubscribe at any time. Don't worry - we don't spam.