跳到主要内容

Wcs设备API接口

可以基于该接口调用 智慧物流系统 中得各种设备。 实现设备属性得查询,设备属性得下发,设备方法调用。

基础信息

Base URL: http://logimaster-api-base-url:port/api/thing-management/devices

数据传输对象(DTO)

DeviceDto

设备信息数据传输对象

{
"id": "string (Guid)",
"name": "string",
"productName": "string",
"productDisplayName": "string",
"driverName": "string",
"ipAddress": "string",
"port": "number",
"description": "string",
"connectionStatus": "ConnectionStatus枚举",
"lastUpdatedTime": "DateTime?",
"propertyValues": "DevicePropertyValueDto[]",
"active": "boolean",
"creationTime": "DateTime",
"lastModificationTime": "DateTime?",
"creatorId": "Guid?",
"lastModifierId": "Guid?"
}

InvokeServiceDto

调用服务请求数据传输对象

{
"serviceIdentifier": "string",
"parameters": {
"key1": "value1",
"key2": "value2"
}
}

SetPropertyValueDto

设置属性值请求数据传输对象

{
"propertyIdentifier": "string",
"value": "string"
}

API 端点

1. 获取设备信息

GET /{id}

获取指定ID的设备详细信息。

参数

  • id (路径参数): 设备ID,类型为Guid

响应

  • 200 OK: 返回设备信息
    {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "name": "温度传感器01",
    "productName": "TempSensor",
    "productDisplayName": "温度传感器",
    "driverName": "ModbusTCP",
    "ipAddress": "192.168.1.100",
    "port": 502,
    "description": "车间温度监测设备",
    "connectionStatus": 1,
    "lastUpdatedTime": "2023-12-01T10:30:00Z",
    "propertyValues": [],
    "active": true
    }

示例

GET /api/thing-management/devices/123e4567-e89b-12d3-a456-426614174000

2. 设置设备属性值

POST /{id}/property

设置指定设备的属性值。

参数

  • id (路径参数): 设备ID,类型为Guid

请求体

{
"propertyIdentifier": "temperature_threshold",
"value": "25.5"
}

响应

  • 200 OK: 属性设置成功

示例

POST /api/thing-management/devices/123e4567-e89b-12d3-a456-426614174000/property
Content-Type: application/json

{
"propertyIdentifier": "temperature_threshold",
"value": "30.0"
}

3. 调用设备服务

POST /{id}/service

调用指定设备的服务方法。

参数

  • id (路径参数): 设备ID,类型为Guid

请求体

{
"serviceIdentifier": "restart",
"parameters": {
"delay": 5,
"force": true
}
}

响应

  • 200 OK: 返回服务执行结果
    {
    "success": true,
    "message": "设备重启成功",
    "timestamp": "2023-12-01T10:35:00Z"
    }

示例

POST /api/thing-management/devices/123e4567-e89b-12d3-a456-426614174000/service
Content-Type: application/json

{
"serviceIdentifier": "calibrate",
"parameters": {
"mode": "auto",
"reference_value": 25.0
}
}

4. 设置设备激活状态

POST /{id}/active

设置指定设备的激活状态。

参数

  • id (路径参数): 设备ID,类型为Guid
  • active (查询参数): 激活状态,类型为boolean

响应

  • 200 OK: 状态设置成功

示例

POST /api/thing-management/devices/123e4567-e89b-12d3-a456-426614174000/active?active=true

错误响应

所有API在出错时(http状态码为500)会返回标准错误格式:

{
"error": {
"code": "错误代码",
"message": "错误描述",
"details": "详细错误信息"
}
}

常见错误状态码:

  • 400 Bad Request: 请求参数错误
  • 404 Not Found: 设备不存在
  • 500 Internal Server Error: 服务器内部错误