Modbus

Purpose

This tutorial can help you quickly to build a Modbus application with Advantech EdgeX SDK.

Gateway Environment

Note: In Windows, Docker containers are completely isolated from local machine. In order to share Windows folders with Docker containers, you first need to configure the "Shared Drives" option in Docker Desktop settings. The computer also needs to restart to finish the configuration changed.

Modbus Device

Here, we choose the ModSim32 application for simulation on Windows. https://www.win-tech.com/html/modsim32.htm

The following table shows the configurations of the Modbus simulator.

Add Modbus Device Service

1) Download the Modbus sample from GitHub, then copy to Advantech EdgeX SDK installation location.

git clone https://github.com/Advantech-EdgeX/tutorial-modbus tutorial-modbus xcopy /s tutorial-modbus* c:\Advantech\EdgeX-API\EdgeX-tools\

2) The Modbus sample contains following files and folder.

modbus – This folder contains Modbus device service configurations docker-compose-modbus.yml – Modification for Modbus device service modbus.tst – Testing config file of Modsim32 application

3) To deploy Modbus device service.

docker-compose -f docker-compose-modbus.yml up -d device-modbus

Create Modbus Device/Device Profile

In our sample, both device and device profiles are created which the definition of the protocol shown in the table.

However, you can create the other device and input the related parameters through edgex-ui-go. For the device profile, the easiest approach is to just upload the profile.

Test Modbus Device Service

1) Launch Modsim32 application to load the testing config file. (File > Restore Test Config > Choose modbus.tst file)

2) Connect to service port. The predefined number is 501.

3) After Modsim32 connection finished, then you can use edgex-ui-go for EdgeX commands sending/receiving.

4) The output result of command 1: {"device":"WISE-4012","origin":1623326175129752600,"readings":[{"origin":1623326175116855800,"device":"WISE-4012","name":"Temperature","value":"50"},{"origin":1623326175124556300,"device":"WISE-4012","name":"Humidity","value":"70"}],"EncodedEvent":null}

5) The output result of command 2: {"device":"WISE-4012","origin":1623326183105216000,"readings":[{"origin":1623326182998939000,"device":"WISE-4012","name":"Fan","value":"true"},{"origin":1623326183089695200,"device":"WISE-4012","name":"Light","value":"true"}],"EncodedEvent":null}

Last updated