Modbus is a master/slave communications protocol that enables the master device to request data from slave devices. In this example, the Modbus driver on a gateway serves as the Modbus master device, and devices that connect to the gateway through the Modbus driver serve as Modbus slave devices. After the master device sends a query message to a slave device, the slave device replies with a response message.

Prerequisites

  1. A Ubuntu 16.04 x86_64 system is ready for running a gateway.
  2. A Windows host is ready for running a simulated Modbus slave device.
  3. The software for simulating the Modbus slave device is downloaded and installed on the Windows host. To download the software, click Modbus tool download address.
  4. The firewall on the Windows host allows access to the Modbus slave device through port 502. If the firewall blocks other devices from connecting to the slave device through port 502, disable the firewall or cancel that blocking on the firewall.
  5. An edge instance is created and a gateway is assigned to the edge instance. For more information, see Build an environment.

Step 1: Assign a Modbus driver to the edge instance

  1. Log on to the IoT Platform console and choose Link IoT Edge > Edge Instances in the left-side navigation pane. On the page that appears, find the target edge instance and click View in the Actions column. The Instance Details page appears.
  2. Assign an official Modbus driver to the edge instance based on the CPU architecture of the gateway device assigned to the edge instance. For more information, see Modbus driver.
    Select a driver
  3. On the Instance Details page of the edge instance, click the name of the assigned driver in the All Drivers section on the left. Then click Driver Configurations next to Devices on the right.
  4. In the Driver Configurations dialog box that appears, click Add Channel. In the Add Channel dialog box that appears, set parameters to add a channel to the Modbus driver.
    For more information about parameter descriptions, see Modbus driver configurations.Add a channel

Step 2: Bind the simulated Modbus slave device to the Modbus driver

  1. In the Devices section, click Assign Sub-device. In the Modbus driver settings, assign a device to the edge instance.
    You can select an existing Modbus device or create a new device. To create a device, follow these steps:
    Note If you want to select an existing device, the device must be connected to a gateway by using the Modbus protocol. For more information, see Create a product.
  2. On the Assign Sub-device page that appears on the right side of the console, click Add Sub-device.
    Add Sub-device
  3. In the Add Device dialog box, click Create Product to create a product to which the Modbus device belongs.
    Create a product (living room lamp)
  4. In the Create Product dialog box, specify the required parameters, and click OK.
    Create a product
    Table 1. Parameters
    Parameter Description
    Product Name The name of the product. The product name must be unique for the current account. The product 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 device. For more information, see Authenticate devices.
    Product Description The description of the product. This parameter is optional.
  5. In the Add Device dialog box, the name of the product that you have created is automatically filled in the Product parameter. Click Configure to add custom features for the product.

    On the Product Details page that appears, click the Define Feature tab and click Edit Draft. On the Edit Draft page that appears, click Add Self-defined Feature.

    Add a custom feature for the Modbus product
  6. In the Create Self-Defined Feature dialog box that appears, click Properties, set the required parameters, and then click Add Extended Information.
    In the Add Extended Information dialog box that appears, set parameters to specify the property address on the simulated Modbus slave device.Add extended information

    Set the Register Address parameter based on the property address settings of the simulated Modbus slave device, as shown in the following figure. In this example, add properties aaa, bbb, and ccc for the product, which correspond to property addresses 0, 1, and 2 on the simulated Modbus slave device, respectively.

    Property address settings of the simulated Modbus slave device
  7. Go back to the Add Device dialog box over the Instance Details page and add the Modbus slave device.
    Add a sub-device to the Modbus product - Apsara Stack

Step 3: Configure and deploy the edge instance

  1. On the Instance Details page of the edge instance, click Assign Sub-device. In the Assign Sub-device dialog box that appears, select the Modbus slave device you added and click Assign to assign it to the edge instance.
  2. On the Instance Details page, click the Devices & Drivers tab, find the Modbus slave device in the Devices section, and then click Device Configurations in the Actions column. In the Device Configurations dialog box that appears, set the required parameters to bind the Modbus slave device to the Modbus driver.
    Device Configurations dialog box
    Table 2. Parameters for binding the Modbus slave device to the Modbus driver
    Parameter Description
    Associate Channel Select the channel you created in Step 1: Assign a Modbus driver to the edge instance.
    Slave Station Number Set this parameter to the ID of the simulated Modbus slave device in step 6 in Step 2: Bind the simulated Modbus slave device to the Modbus driver. In this example, set this parameter to 1.
  3. On the Instance Details page, click Deploy in the upper-right corner to deploy the edge instance.
  4. Choose Devices > Devices in the left-side navigation pane. On the Devices page that appears, find the Modbus slave device and click View in the Actions column.
    On the Device Details page that appears, click the Status tab and view the property data of the Modbus slave device.Status