All Products
Search
Document Center

Link IoT Edge:Connect a Modbus slave device to an edge instance over Modbus TCP

Last Updated:Jan 26, 2024

Modbus is a communication protocol based on the master/slave model. The master device requests data from slave devices. The Modbus driver of a gateway serves as the master device, and devices that connect to the gateway through the Modbus driver serve as slave devices. After the master device sends a query message to a slave device, the slave device sends a response message.

Preparations

  1. A Ubuntu 16.04 x86_64 system is prepared to run a gateway.

  2. A Windows host is prepared to run a Modbus slave simulator.

  3. Download a Modbus slave simulator from the URL of Modbus tools and install the simulator on the Windows host.

  4. Check the firewall settings of the Windows host and make sure that access to the Modbus slave device is allowed through port 502. If the access is denied, disable the firewall or change firewall settings to allow access to the port.

  5. Create an edge instance and enable a gateway. For more information, see Build an environment.

Step 1: Assign a Modbus driver to the edge instance

  1. Log on to the Link IoT Edge console.

  2. In the left-side navigation pane, click Edge Instances, and click View next to the required edge instance.

  3. Assign the required Modbus driver to the edge instance based on the CPU of the related gateway. For more information, see Modbus drivers.

    Select a driver

  4. On the Instance Details page of the edge instance, click the name of the assigned driver. Then, click Driver Configurations in the Devices section.

  5. In the Driver Configurations panel, click Add Channel. In the Add Channel panel, set the required parameters to add a channel to the Modbus driver.

    For more information about the parameters, see Modbus driver configurations. Add a channel

Step 2: Assign a sub-device to the Modbus driver

  1. In the Devices section, click Assign Sub-device. In the Assign Sub-device panel, assign a sub-device to the edge instance.
    You can select an existing Modbus device or create a sub-device. To create a sub-device, proceed with the following steps.
    Note If you want to select an existing Modbus device, the product to which the device belongs must be connected to a gateway by using the Modbus protocol. For more information, see Create a product.
  2. In the Assign Sub-device panel, click Add Sub-device.
    Add Sub-device button
  3. In the Add Device dialog box, click Create Product and create a product to which the new Modbus device belongs.
    Create a Living_Room_Lamp product
  4. In the Create Product dialog box, set the parameters as required and click OK.
    Table 1. Parameter description
    ParameterDescription
    Product Name
    The name of the product. The product name must be unique within the current Alibaba Cloud account. The name must be 4 to 30 characters in length and can contain letters, digits, underscores (_), hyphens (-), at signs (@), and parentheses ().
    Gateway Connection Protocol
    The communications protocol. You must set this parameter to Modbus.
    Authentication Mode
    The authentication method. Select an authentication method that is suitable for your devices. For more information, see Authenticate devices.
    Product DescriptionThe description of the product. This parameter is optional.
  5. In the Add Device dialog box, the new product is automatically specified in the drop-down list of the Product section. Click Configure to add a custom feature to the product. For more information, see Add a TSL feature.

    Add a custom feature to the Modbus product

  6. In the Add Self-defined Feature dialog box, click Properties and set the required parameters. Then, click Add Extended Information.

    In the Add Extended Information dialog box, set the required parameters to specify the data points of the Modbus sub-device. Add extended information

    Set the Register Address parameter based on the data points of the simulated Modbus slave device, as shown in the following figure. In this example, three attributes named aaa, bbb, and ccc are created. These attributes correspond to the data points 0, 1, and 2 of the Modbus slave device.

    Data points of the simulated device

  7. Go to the Add Device dialog of the Instance Details page in the Link IoT Edge console. Then, add a Modbus device.

    Add a sub-device

Step 3: Configure and deploy the edge instance

  1. Assign the new Modbus device to the edge instance.

  2. After the device is assigned to the edge instance, click Device Configurations in the Actions column of the device. Then, use a channel to associate the device with the Modbus driver.

    Configure a device

    Table 1. Parameters

    Parameter

    Description

    Associated Channel

    Select the channel that you have added in the Step 1: Assign a Modbus driver to the edge instance section.

    Device Station Number

    To view the value, check the ID of the Modbus slave device in Step 6 of the Step 2: Assign a sub-device to the Modbus driver section. In this example, the value of this parameter is 1.

  3. On the Instance Details page, click Deploy in the upper-right corner of the page to deploy the edge instance.

  4. Log on to the IoT Platform console. In the left-side navigation pane, choose Devices > Devices. On the Devices page, click View next to the required Modbus product.

    On the Device Details page, choose TSL Data > Status. On the Status tab, view the properties of the Modbus product. Status