Skip to content

Modbus Configuration

HCC2 Modbus TCP Server Configuration

A detailed procedure on how to configure the HCC2 Modbus Server is out of the scope of this document. It is assumed you have full access to the HCC2 software user manual and a basic understanding of the Modbus protocol. See the external references for more information.

A HCC2 Modbus Server Instance must be configured to map all HCC2 tags that the application needs into the appropriate Modbus registers.

The Modbus Server is configured through the HCC2 Unity interface. The Modbus Server register map can be configured using the "Modbus Map Editor" from the Deploy/Protocols/Modbus section.

Using the Modbus Map Editor, you can add HCC2 tags to your map using the Tag Browser. Registers can be marked as read-only or read-write.

Danger

It is important that you do not attempt to write to internal system tags. Doing so could cause unpredictable behavior and interfere with the correct operation of the HCC2.

It is also possible to create "User Tags" for storing your own information. To do this, in the Tag Name column, select the ConstructFromMnemonic option and enter a Tag Name in the Tag Mnemonic box. Ensure you select the appropriate Register Data Type and Tag Data Type. It is also advised to assign a meaningful name to the "User Defined Register Name":

Example User Tag Creation

The Modbus Map Editor will create a PDEF (Protocol Definition) file that can be deployed to the HCC2. This should be downloaded from the menu at the top of the editor.

Tip

If you have created "User Tags", the download option will raise a warning that the tag does not exist. This warning can be safely ignored as the tag will be created once the PDEF file is deployed.

Note that if there are gaps or non-contiguous addresses in the Modbus map, it is advised to set these two flags to True in the Map Editor under the Server Definition section. Make sure to download and apply the resulting PDEF file to the Modbus server after making the change: Modbus Address Gap Tolerance

Application Modbus TCP Client Configuration

The Modbus TCP Client (residing inside the application) must be configured to match the HCC2 Modbus Server configuration.

Modbus Client configuration

To configure the Modbus TCP Client scanner, perform the following steps:

  1. On your Development environment go to directory $HOME/edgesdkexample/config.
  2. Edit the file config.json.

    A portion of this file is shown below. Modify as required:

    {
        "version": "0.0.0",                     # your app version
        "variable_file": "config/vars.json",    # name of the vars config file
        "app": {
            "server_default_host": "localhost", # Address of the target Modbus Server
            "server_default_port": 502,         # Port of the target Modbus Server
            "server_default_unit" : 1,          # Modbus Slave Unit Number
            "default_time_period" : 1000,       # Time between polls (ms)
            "default_control_time_period": 100, # Time between writebacks (ms)
            "default_timeout": 0.6,             # Modbus Server response timeout (ms)
            "default_retries": 0                # number of retries
        }
    

    For C#, the config.json file is:

    {
        "Host": "192.168.X.X",       # Address of the target Modbus Server
        "Port": 502,                 # Port of the target Modbus Server
        "SlaveID": 1,                # Modbus Server Id
        "TimeBetweenPolls": 1000,    # Time between polls (ms)
        "TimeBetweenControls": 1000, # Time between writebacks (ms)
        "Timeout": 2000,             # Modbus Server response timeout (ms)
        "Retries": 0                 # number of retries
    

    Important

    Inline comments are for reference only and should not be included in your config.json file

Variable Configuration

To configure the Modbus TCP Client variable configuration, perform the following steps:

  1. On your Development VM Machine, go to the directory $HOME/edgesdkexample/config.
  2. Edit the file vars.json.
  3. On this json file, you can configure the application input and output variables. There are four types of variables: Input_status, Holding_registers, Input_registers, and Coils. You need to create one variable per register configured at Modbus TCP Server level.

    The basic configuration of a variable is as follows:

    "Input_registers": [
    {
        "name": "input_var1",
        "collection_size": 1,
        "type": "float",
        "register_number": 0,
        "num_registers": 2,
        "writable": false,
        "word_swap": false,
        "byte_swap": false
    },
    
    ]
    

    where:

    Parameter Description
    Input registers The type of register to be used for this variable. In this example, it is Modbus input register type. Options include:
    + "Input_status"
    + "Coils"
    + "Input_registers"
    + "Holding_registers"
    name The name of the variable as used by the application.
    collection_size The number of values to read for this variable. If greater than 1, the tag returned from get_value will contain an indexable array in the value variable, otherwise it will return a single variable.
    type The type of variable. Options are “boolean”, “integer” and “float”.
    register_number The register number of this variable as defined in the Modbus Server configuration.
    num_registers The number of consecutive registers that contains this variable.
    writable Flag indicating if this variable will be read-only (false) or read-write (true). Use true for output (writeback) registers.
    word_swap If it is required to swap 16-bit words of a 32-bit integer or float.
    byte_swap If it is required to two swap bytes in the 16-bit words.

You should create these types of blocks for each one of the tags required by the application for each Modbus Data type.

Please refer to the vars.json file in the example application for the full structure of this file.

Tip

Use the Live Data page in the HCC2 to filter and locate your tags and their values. To locate all tags on a particular Modbus link, filter on the Server Tag ID defined in Deploy/Modbus