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.
- A Ubuntu 16.04 x86_64 system is prepared to run a gateway.
- A Windows host is prepared to run a Modbus slave simulator.
- Download a Modbus slave simulator from the URL of Modbus tools and install the simulator on the Windows host.
- Check the firewall settings of the Windows host and make sure that access to the Modbus slave device is allows through port 502. If the access is denied, disable the firewall or change firewall settings to allow access to the port.
- 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
- Log on to the Link IoT Edge console.
- In the left-side navigation pane, click Edge Instances, and click View next to the required edge instance.
- Assign the required Modbus driver to the edge instance based on the CPU of the related
gateway. For more information, see Modbus drivers.
- On the Instance Details page of the edge instance, click the name of the assigned driver. Then, click Driver Configurations in the Devices section.
- 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.
Step 2: Assign a sub-device to the Modbus driver
- 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.
- On the Assign Sub-device page that appears on the right side of the console, click Add Sub-device.
- In the Add Device dialog box, click Create Product to create a product to which the Modbus device belongs.
- In the Create Product dialog box, specify the required parameters, and click OK.
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 Overview. Product Description The description of the product. This parameter is optional.
- 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.
- 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.
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.
- Go to the Add Device dialog of the Instance Details page in the Link IoT Edge console. Then, add a Modbus device.
Step 3: Configure and deploy the edge instance
- Assign the new Modbus device to the edge instance.
- 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.
Table 2. 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.
- On the Instance Details page, click Deploy in the upper-right corner of the page to deploy the edge instance.
- Log on to the IoT Platform console. In the left-side navigation pane, choose . On the Devices page, click View next to the required Modbus product. On the Device Details page, choose . On the Status tab, view the properties of the Modbus product.