EdgeX - Modbus Device

原创
2022/04/19 19:36
阅读数 507
AI总结

原文:https://docs.edgexfoundry.org/2.1/examples/Ch-ExamplesAddingModbusDevice/

Modbus

EdgeX - Ireland Release

This page describes how to connect Modbus devices to EdgeX. In this example, we simulate the temperature sensor instead of using a real device. This provides a straightforward way to test the device service features.
本文描述了如何将 Modebus 设备接入 EdgeX。在这个样例中,我们将模拟一个[温度传感器](https://www.audon.co.uk/ethernet_sensors/NANO_TEMP.html "temperature sensor "温度传感器")而非一个真实的设备。这是一种直截了当的测试设备服务功能的方法。

Important Notice 重要提示

To fulfill the issue #61, there is an important incompatible change after v2 (Ireland release). In the Device Profile attributes section, the startingAddress becomes an integer data type and zero-based value. In v1, startingAddress was a string data type and one-based value.
为了满足 Issue #61,在 EdgeX v2版本(Ireland 版本)有一个重要的不向前兼容的变化。在设备配置档案的属性 attributes 部分,startingAddress配置变为了从0开始的整数。而在v1版本,startingAddress是从1开始的字符串。

Environment 运行环境

You can use any operating system that can install docker and docker-compose. In this example, we use Ubuntu to deploy EdgeX using docker.
你可以使用任何能安装 docker 和 docker-compose 的操作系统。在本样例中,我们使用的是Ubuntu 和 docker 来部署 EdgeX。

Modbus Device Simulator - Modbus 设备模拟器

  1. Download ModbusPal 下载 ModbusPal
    Download the fixed version of ModbusPal from the https://sourceforge.net/p/modbuspal/discussion/899955/thread/72cf35ee/cd1f/attachment/ModbusPal.jar .
    从上述地址下载 ModbusPal。
  2. Install required lib: 安装需要的库:
    	sudo apt install librxtx-java
    
  3. Startup the ModbusPal: 运行 ModbusPal:
    	sudo java -jar ModbusPal.jar
    

Modbus Register Table - Modbus 寄存器表

You can find the available registers in the user manual.
你可以从用户手册中找到可用的寄存器表。
Modbus TCP – Holding Registers
Modbus TCP — 保持寄存器

Address Name R/W Description
4000 ThermostatL R/W Lower alarm threshold
4001 ThermostatH R/W Upper alarm threshold
4002 Alarm mode R/W 1 - OFF (disabled), 2 - Lower, 3 - Higher, 4 - Lower or Higher
4004 Temperature x10 R Temperature x 10 (np. 10,5 st.C to 105)

Setup ModbusPal 配置 ModbusPal

To simulate the sensor, do the following:
执行如下步骤来模拟Modbus传感器:

  1. Add mock device:
    添加模拟设备:

  2. Add registers according to the register table:
    根据上面的寄存器表格来添加寄存器:

  3. Add the ModbusPal support value auto-generator, which can bind to the registers:
    为寄存器添加 ModbusPal 所支持的数值生成器:

Run the Simulator 运行模拟器

Enable the value generator and click the Run button.
启用数值生成器然后点击Run按钮。

Set Up Before Starting Services 启动设备服务所需的准备工作

The following sections describe how to complete the set up before starting the services. If you prefer to start the services and then add the device, see Set Up After Starting Services
接下来的步骤描述了在启动设备服务之前所要完成的准备工作。如果你想直接开始设备服务并且添加设备,请查看 启动设备服务后的操作

Create a Custom configuration folder 创建目录用于存放自定义配置

Run the following command:
执行如下命令:

mkdir -p custom-config

Set Up Device Profile 编写设备配置档案

Run the following command to create your device profile:
执行如下命令来新建一个设备配置档案:

cd custom-config
nano temperature.profile.yml

Fill in the device profile according to the Modbus Register Table, as shown below:
根据 Modbus Register Table 来编写该设备配置档案,如下:

name: "Ethernet-Temperature-Sensor"
manufacturer: "Audon Electronics"
model: "Temperature"
labels:
  - "Web"
  - "Modbus TCP"
  - "SNMP"
description: "The NANO_TEMP is a Ethernet Thermometer measuring from -55°C to 125°C with a web interface and Modbus TCP communications."

deviceResources:
  -
    name: "ThermostatL"
    isHidden: true
    description: "Lower alarm threshold of the temperature"
    attributes:
      { primaryTable: "HOLDING_REGISTERS", startingAddress: 3999, rawType: "Int16" }
    properties:
      valueType: "Float32"
      readWrite: "RW"
      scale: "0.1"
  -
    name: "ThermostatH"
    isHidden: true
    description: "Upper alarm threshold of the temperature"
    attributes:
      { primaryTable: "HOLDING_REGISTERS", startingAddress: 4000, rawType: "Int16" }
    properties:
      valueType: "Float32"
      readWrite: "RW"
      scale: "0.1"
  -
    name: "AlarmMode"
    isHidden: true
    description: "1 - OFF (disabled), 2 - Lower, 3 - Higher, 4 - Lower or Higher"
    attributes:
      { primaryTable: "HOLDING_REGISTERS", startingAddress: 4001 }
    properties:
      valueType: "Int16"
      readWrite: "RW"
  -
    name: "Temperature"
    isHidden: false
    description: "Temperature x 10 (np. 10,5 st.C to 105)"
    attributes:
      { primaryTable: "HOLDING_REGISTERS", startingAddress: 4003, rawType: "Int16" }
    properties:
      valueType: "Float32"
      readWrite: "R"
      scale: "0.1"

deviceCommands:
  -
    name: "AlarmThreshold"
    readWrite: "RW"
    isHidden: false
    resourceOperations:
      - { deviceResource: "ThermostatL" }
      - { deviceResource: "ThermostatH" }
  -
    name: "AlarmMode"
    readWrite: "RW"
    isHidden: false
    resourceOperations:
      - { deviceResource: "AlarmMode", mappings: { "1":"OFF","2":"Lower","3":"Higher","4":"Lower or Higher"} }

In the Modbus protocol, we provide the following attributes:
在该Modbus协议中,我们提供如下定语:

  1. primaryTable: HOLDING_REGISTERS, INPUT_REGISTERS, COILS, DISCRETES_INPUT
    primaryTable16位保持寄存器 HOLDING_REGISTERS16位输入寄存器 INPUT_REGISTERS1位回路状态寄存器 COILS1位输入寄存器 DISCRETES_INPUT
  2. startingAddress This attribute defines the zero-based startingAddress in Modbus device. For example, the GET command requests data from the Modbus address 4004 to get the temperature data, so the starting register address should be 4003.
    startingAddress 该定语描述了该Modbus设备里从0开始计数的起始地址位。比如,某个GET命令要从一个Modbus设备的4004地址位来读取温度数据,那么这个起始地址应该是4003(译者:貌似Modbus说明书上的地址都是末尾地址?所以这里要转换成起始地址 = 末尾地址 - 类型位长 +1 ?)
Address Starting Address Name R/W Description
4004 4003 Temperature x10 R Temperature x 10 (np. 10,5 st.C to 105)
  1. IS_BYTE_SWAP, IS_WORD_SWAP: To handle the different Modbus binary data order, we support Int32, Uint32, Float32 to do the swap operation before decoding the binary data.
    IS_BYTE_SWAP, IS_WORD_SWAP: 为了处理不同的Modbus字节序,我们支持在解码前对 Int32, Uint32, Float32 进行字节(8位)和字(16位)的顺序调换。比如:
    For example: { primaryTable: "INPUT_REGISTERS", startingAddress: "4", isByteSwap: "false", isWordSwap: "true" }
    (译者注:如上将按照字进行顺序调换。前16位和后16位进行调换。)
  2. RAW_TYPE: This attribute defines the binary data read from the Modbus device, then we can use the value type to indicate the data type that the user wants to receive.
    RAW_TYPE:该定语描定义了从该Modbus设备读出的二进制数据的类型,然后我们可以根据valueType的定义来表示用户想要的数据类型。(译者注:这里没看懂。TODO)

We only support Int16 and Uint16 for rawType. The corresponding value type must be Float32 and Float64. For example:
对于rawType我们仅仅支持Int16Uint16。对应的数值类型必须是Float32Float64。比如:

deviceResources:
  -
    name: "Temperature"
    isHidden: false
    description: "Temperature x 10 (np. 10,5 st.C to 105)"
    attributes:
      { primaryTable: "HOLDING_REGISTERS", startingAddress: 4003, rawType: "Int16" }
    properties:
      valueType: "Float32"
      readWrite: "R"
      scale: "0.1"

In the device-modbus, the Property valueType decides how many registers will be read. Like Holding registers, a register has 16 bits. If the Modbus device's user manual specifies that a value has two registers, define it as Float32 or Int32 or Uint32 in the deviceProfile.
在该Modbus设备中,属性valueType描述了有多少个寄存器将被读取。比如一个保持寄存器有16位。如果该Modbus设备手册里说某个值占用了两个寄存器(译者注:两个地址位),那么请将此属性定义为Float32, Int32Uint32

Once we execute a command, device-modbus knows its value type and register type, startingAddress, and register length. So it can read or write value using the modbus protocol.
这样当我们执行命令时,该Modbus设备根据它的valueType,寄存器类型,起始地址和寄存器长度,就能对值进行读写了。

Set Up Device Service Configuration 对设备服务进行配置

Run the following command to create your device configuration:
执行如下命令来创建你的设备配置文件:

cd custom-config
nano device.config.toml

Fill in the device.config.toml file, as shown below:
将 device.config.toml 修改如下:

[[DeviceList]]
    Name = "Modbus-TCP-Temperature-Sensor"
    ProfileName = "Ethernet-Temperature-Sensor"
    Description = "This device is a product for monitoring the temperature via the ethernet"
    labels = [ "temperature","modbus TCP" ]
    [DeviceList.Protocols]
        [DeviceList.Protocols.modbus-tcp]
            Address = "172.17.0.1"
            Port = "502"
            UnitID = "1"
            Timeout = "5"
            IdleTimeout = "5"
        [[DeviceList.AutoEvents]]
        Interval = "30s"
        OnChange = false
        SourceName = "Temperature"

The address 172.17.0.1 is point to the docker bridge network which means it can forward the request from docker network to the host.
地址172.17.0.1指向的是docker bridge 网关,即容器内的应用可以通过该地址访问主机资源。

Use this configuration file to define devices and AutoEvent. Then the device-modbus will generate the relative instance on startup.
使用该配置文件来定义设备和AutoEvent。然后EdgeX在启动时就会创建对应该Modbus设备的实例。

The device-modbus offers two types of protocol, Modbus TCP and Modbus RTU, which can be defined as shown below:
该Modbus设备提供了两种协议:Modbus TCP 和 Modbus RTU,定义如下:

protocol Name Protocol Address Port UnitID BaudRate DataBits StopBits Parity Timeout IdleTimeout
Modbus TCP Gateway address TCP 10.211.55.6 502 1 5 5
Modbus RTU Gateway address RTU /tmp/slave 502 2 19200 8 1 N 5 5

In the RTU protocol, Parity can be:
在 RTU 协议中,奇偶性Parity 定义可以是:

  • N - None is 0 无
  • O - Odd is 1 奇
  • E - Even is 2, default is E 偶默认值

Prepare docker-compose file 准备 docker-compose 文件

  1. Clone edgex-compose
    从 edgex-compose 克隆一份
$ git clone git@github.com:edgexfoundry/edgex-compose.git
  1. Generate the docker-compose.yml file
    生成 docker-compose.yml 文件
$ cd edgex-compose/compose-builder
$ make gen ds-modbus

Add Custom Configuration to docker-compose File 向 docker-compose 文件添加自定义配置

Add prepared configuration files to docker-compose file, you can mount them using volumes and change the environment for device-modbus internal use.
向 docker-compose 文件添加之前准备好的配置文件,你可以使用 volumes 将文件挂载,然后修改 environment 让 device-modbus 找到这些文件。

Open the docker-compose.yml file and then add volumes path and environment as shown below:
打开 docker-compose.yml 文件然后添加 volumes 路径和对应的环境变量 environment,如下:

 device-modbus:
    ...
    environment:
      ...
      DEVICE_DEVICESDIR: /custom-config
      DEVICE_PROFILESDIR: /custom-config
    volumes:
    ...
    - /path/to/custom-config:/custom-config

Start EdgeX Foundry on Docker 用 Docker 启动 EdgeX Foundry

Since we generate the docker-compose.yml file at the previous step, we can deploy EdgeX as shown below:
上一步我们创建了docker-compose.yml,接下来我们可以部署运行 EdgeX 了:

$ cd edgex-compose/compose-builder
$ docker-compose up -d
Creating network "compose-builder_edgex-network" with driver "bridge"
Creating volume "compose-builder_consul-acl-token" with default driver
...
Creating edgex-core-metadata              ... done
Creating edgex-core-command               ... done
Creating edgex-core-data                  ... done
Creating edgex-device-modbus              ... done
Creating edgex-app-rules-engine           ... done
Creating edgex-sys-mgmt-agent             ... done

Set Up After Starting Services 启动设备服务后的操作

If the services are already running and you want to add a device, you can use the Core Metadata API as outlined in this section. If you set up the device profile and Service as described in Set Up Before Starting Services, you can skip this section.
如果EdgeX各项服务已经运行了,此时你想添加新设备,你可以使用本章节提到的核心元数据API。如果你已经根据前面的章节”启动设备服务所需的准备工作“设置了对应的设备配置档案和服务,你可以跳过本章节。

To add a device after starting the services, complete the following steps:
如果要在各项服务启动后添加一个新的设备,请完成如下步骤:

  1. Upload the device profile above to metadata with a POST to http://localhost:59881/api/v2/deviceprofile/uploadfile and add the file as key "file" to the body in form-data format, and the created ID will be returned. The following example command uses curl to send the request:
    将之前章节提到的设备配置档案使用POST请求发送到元数据服务API http://localhost:59881/api/v2/deviceprofile/uploadfile 记得body使用form-data格式,文件放入 file 字段。请求成功后你会得到一个该设备配置档案的ID。如下命令使用curl来完成该请求:
$ curl http://localhost:59881/api/v2/deviceprofile/uploadfile \
  -F "file=@temperature.profile.yml"
  1. Ensure the Modbus device service is running, adjust the service name below to match if necessary or if using other device services.
    首先确保Modbus设备服务运行正常,如果有必要的话你可以在下面的步骤里调整服务的名字。
  2. Add the device with a POST to http://localhost:59881/api/v2/device, the body will look something like:
    发起 POST 请求到 http://localhost:59881/api/v2/device 来创建一个设备。请求体如下:
$ curl http://localhost:59881/api/v2/device -H "Content-Type:application/json" -X POST \
  -d '[
        {
            "apiVersion": "v2",
            "device": {
               "name" :"Modbus-TCP-Temperature-Sensor",
               "description":"This device is a product for monitoring the temperature via the ethernet",
               "labels":[ 
                  "Temperature",
                  "Modbus TCP"
               ],
               "serviceName": "device-modbus",
               "profileName": "Ethernet-Temperature-Sensor",
               "protocols":{
                  "modbus-tcp":{
                     "Address" : "172.17.0.1",
                     "Port" : "502",
                     "UnitID" : "1",
                     "Timeout" : "5",
                     "IdleTimeout" : "5"
                  }
               },
               "autoEvents":[ 
                  { 
                     "Interval":"30s",
                     "onChange":false,
                     "SourceName":"Temperature"
                  }
               ],
               "adminState":"UNLOCKED",
               "operatingState":"UP"
            }
        }
    ]'

The service name must match/refer to the target device service, and the profile name must match the device profile name from the previous steps.
其中的 service name 必须和实际运行的设备服务名字一致,设备配置档案名字必须和之前步骤配置的名字一致。

Execute Commands 执行命令

Now we're ready to run some commands.
现在我们准备好执行一些命令了。

Find Executable Commands 列出可执行的命令

Use the following query to find executable commands:
使用如下请求来列出可执行的命令:

$ curl http://localhost:59882/api/v2/device/all | json_pp

{
   "apiVersion" : "v2",
   "deviceCoreCommands" : [
      {
         "deviceName" : "Modbus-TCP-Temperature-Sensor",
         "profileName" : "Ethernet-Temperature-Sensor",
         "coreCommands" : [
            {
               "url" : "http://edgex-core-command:59882",
               "name" : "AlarmThreshold",
               "get" : true,
               "set" : true,
               "parameters" : [
                  {
                     "valueType" : "Float32",
                     "resourceName" : "ThermostatL"
                  },
                  {
                     "valueType" : "Float32",
                     "resourceName" : "ThermostatH"
                  }
               ],
               "path" : "/api/v2/device/name/Modbus-TCP-Temperature-Sensor/AlarmThreshold"
            },
            {
               "get" : true,
               "url" : "http://edgex-core-command:59882",
               "name" : "AlarmMode",
               "set" : true,
               "path" : "/api/v2/device/name/Modbus-TCP-Temperature-Sensor/AlarmMode",
               "parameters" : [
                  {
                     "resourceName" : "AlarmMode",
                     "valueType" : "Int16"
                  }
               ]
            },
            {
               "get" : true,
               "url" : "http://edgex-core-command:59882",
               "name" : "Temperature",
               "path" : "/api/v2/device/name/Modbus-TCP-Temperature-Sensor/Temperature",
               "parameters" : [
                  {
                     "valueType" : "Float32",
                     "resourceName" : "Temperature"
                  }
               ]
            }
         ]
      }
   ],
   "statusCode" : 200
}

Execute SET command 执行 SET 命令

Execute SET command according to url and parameterNames, replacing [host] with the server IP when running the SET command.
根据对应的urlparameterNames可以执行 SET 命令, 请修改下面 URL 的主机名再执行该命令。

$ curl http://localhost:59882/api/v2/device/name/Modbus-TCP-Temperature-Sensor/AlarmThreshold \
    -H "Content-Type:application/json" -X PUT  \
    -d '{"ThermostatL":"15","ThermostatH":"100"}'

Execute GET command 执行 GET 命令

Replace <host> with the server IP when running the GET command.
请修改下面 URL 的主机名再执行该命令。

$ curl http://localhost:59882/api/v2/device/name/Modbus-TCP-Temperature-Sensor/AlarmThreshold | json_pp

{
   "statusCode" : 200,
   "apiVersion" : "v2",
   "event" : {
      "origin" : 1624324686964377495,
      "deviceName" : "Modbus-TCP-Temperature-Sensor",
      "id" : "f3d44a0f-d2c3-4ef6-9441-ad6b1bfb8a9e",
      "sourceName" : "AlarmThreshold",
      "readings" : [
         {
            "resourceName" : "ThermostatL",
            "value" : "1.500000e+01",
            "deviceName" : "Modbus-TCP-Temperature-Sensor",
            "id" : "9aa879a0-c184-476b-8124-34d35a2a51f3",
            "valueType" : "Float32",
            "mediaType" : "",
            "binaryValue" : null,
            "origin" : 1624324686963970614,
            "profileName" : "Ethernet-Temperature-Sensor"
         },
         {
            "value" : "1.000000e+02",
            "resourceName" : "ThermostatH",
            "deviceName" : "Modbus-TCP-Temperature-Sensor",
            "id" : "bf7df23b-4338-4b93-a8bd-7abd5e848379",
            "valueType" : "Float32",
            "mediaType" : "",
            "binaryValue" : null,
            "origin" : 1624324686964343768,
            "profileName" : "Ethernet-Temperature-Sensor"
         }
      ],
      "apiVersion" : "v2",
      "profileName" : "Ethernet-Temperature-Sensor"
   }
}

AutoEvent 自动事件

The AutoEvent is defined in the [[DeviceList.AutoEvents]] section of the device configuration file:
自动事件可以在设备配置的 [[DeviceList.AutoEvents]] 里面定义。

[[DeviceList.AutoEvents]]
Interval = "30s"
OnChange = false
SourceName = "Temperature"

After service startup, query core-data's API. The results show that the service auto-executes the command every 30 seconds.
在服务启动后,查询一下核心数据API。你会看到设备服务每三十秒自动执行了命令。

$ curl http://localhost:59880/api/v2/event/device/name/Modbus-TCP-Temperature-Sensor | json_pp

{
   "events" : [
      {
         "readings" : [
            {
               "value" : "5.300000e+01",
               "binaryValue" : null,
               "origin" : 1624325219186870396,
               "id" : "68a66a35-d3cf-48a2-9bf0-09578267a3f7",
               "deviceName" : "Modbus-TCP-Temperature-Sensor",
               "mediaType" : "",
               "valueType" : "Float32",
               "resourceName" : "Temperature",
               "profileName" : "Ethernet-Temperature-Sensor"
            }
         ],
         "apiVersion" : "v2",
         "origin" : 1624325219186977564,
         "id" : "4b235616-7304-419e-97ae-17a244911b1c",
         "deviceName" : "Modbus-TCP-Temperature-Sensor",
         "sourceName" : "Temperature",
         "profileName" : "Ethernet-Temperature-Sensor"
      },
      {
         "readings" : [
            {
               "profileName" : "Ethernet-Temperature-Sensor",
               "resourceName" : "Temperature",
               "valueType" : "Float32",
               "id" : "56b7e8be-7ce8-4fa9-89e2-3a1a7ef09050",
               "origin" : 1624325189184675483,
               "value" : "5.300000e+01",
               "binaryValue" : null,
               "mediaType" : "",
               "deviceName" : "Modbus-TCP-Temperature-Sensor"
            }
         ],
         "profileName" : "Ethernet-Temperature-Sensor",
         "sourceName" : "Temperature",
         "deviceName" : "Modbus-TCP-Temperature-Sensor",
         "id" : "fbab44f5-9775-4c09-84bd-cbfb00001115",
         "origin" : 1624325189184721223,
         "apiVersion" : "v2"
      },
      ...
   ],
   "apiVersion" : "v2",
   "statusCode" : 200
}

Set up the Modbus RTU Device 配置Modbus RTU设备

This section describes how to connect the Modbus RTU device. We use Ubuntu OS and a Modbus RTU device for this example.
本章节描述了如何将一个Modbus RTU设备接入 EdgeX。我们使用Ubuntu操作系统和一个Modbus RTU 设备作为演示。

Connect the device 连接设备

  1. Connect the device to your machine(laptop or gateway,etc.) via RS485/USB adaptor and power on.
    将设备通过RS485/USB适配器连接到你的主机上(笔记本、网关等),打开电源。
  2. Execute a command on the machine, and you can find a message like the following:
    在主机上执行命令,你会看到如下输出。
$ dmesg | grep tty
...  
...
[18006.167625] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0
  1. It shows the USB attach to ttyUSB0, then you can check whether the device path exists:
    这表示该USB设备连接到了 ttyUSB0,然后你可以检查该设备路径是否存在:
$ ls /dev/ttyUSB0
/dev/ttyUSB0

Deploy the EdgeX 部署到 EdgeX

  1. Modify the docker-compose.yml file to mount the device path to the device-modbus:
    修改 docker-compose.yml 文件,将该USB设备路径映射进服务 device-modbus:
    a. Change the permission of the device path
    修改设备路径权限
    	sudo chmod 777 /dev/ttyUSB0
    
    b. Open docker-compose.yml file with text editor.
    用编辑器打开 docker-compose.yml 文件。
    	$ nano /docker-compose.yml
    
    c. Modify the device-modbus section and save the file
    修改 device-modbus 部分的配置,然后保存该文件
    	device-modbus:
    	   ...
    	   devices:
    		 - /dev/ttyUSB0
    
  2. Deploy the EdgeX 部署到 EdgeX
$ docker-compose up -d

Add device to EdgeX 添加设备到 EdgeX

  1. Create the device profile according to the register table
    根据寄存器表,创建设备配置档案
$ nano modbus.rtu.demo.profile.yml
name: "Modbus-RTU-IO-Module"
manufacturer: "icpdas"
model: "M-7055"
labels:
  - "Modbus RTU"
  - "IO Module"
description: "This IO module offers 8 isolated channels for digital input and 8 isolated channels for digital output."

deviceResources:
  -
    name: "DO0"
    isHidden: true
    description: "On/Off , 0-OFF 1-ON"
    attributes:
      { primaryTable: "COILS", startingAddress: 0 }
    properties:
      valueType: "Bool"
      readWrite: "RW"
  -
    name: "DO1"
    isHidden: true
    description: "On/Off , 0-OFF 1-ON"
    attributes:
      { primaryTable: "COILS", startingAddress: 1 }
    properties:
      valueType: "Bool"
      readWrite: "RW"
  -
    name: "DO2"
    isHidden: true
    description: "On/Off , 0-OFF 1-ON"
    attributes:
      { primaryTable: "COILS", startingAddress: 2 }
    properties:
      valueType: "Bool"
      readWrite: "RW"

deviceCommands:
  -
    name: "DO"
    readWrite: "RW"
    isHidden: false
    resourceOperations:
      - { deviceResource: "DO0" }
      - { deviceResource: "DO1" }
      - { deviceResource: "DO2" }
  1. Upload the device profile
    上传该设备配置档案
$ curl http://localhost:59881/api/v2/deviceprofile/uploadfile \
  -F "file=@modbus.rtu.demo.profile.yml"
  1. Create the device entity to the EdgeX. You can find the Modbus RTU setting on the device or the user manual.
    创建设备实例到 EdgeX。你可以在该设备的使用手册上找到Modbus RTU的配置信息。(译者注:波特率之类的)
$ curl http://localhost:59881/api/v2/device -H "Content-Type:application/json" -X POST \
  -d '[
        {
            "apiVersion": "v2",
            "device": {
               "name" :"Modbus-RTU-IO-Module",
               "description":"The device can be used to monitor the status of the digital input and digital output channels.",
               "labels":[ 
                  "IO Module",
                  "Modbus RTU"
               ],
               "serviceName": "device-modbus",
               "profileName": "Ethernet-Temperature-Sensor",
               "protocols":{
                  "modbus-tcp":{
                     "Address" : "/dev/ttyUSB0",
                     "BaudRate" : "19200",
                     "DataBits" : "8",
                     "StopBits" : "1",
                     "Parity" : "N",
                     "UnitID" : "1",
                     "Timeout" : "5",
                     "IdleTimeout" : "5"
                  }
               },
               "adminState":"UNLOCKED",
               "operatingState":"UP"
            }
        }
    ]'
  1. Test the GET or SET command 试试GET和SET命令吧
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
AI总结
返回顶部
顶部