FreeIOE开发文档
  • Introduction
  • 基础介绍
    • FreeIOE是什么
    • 名词解释
  • 开发引导
    • 开发入门
    • 环境搭建
      • 使用网关产品
      • 使用虚拟网关
      • 使用VSCode插件开发
      • 其他应用开发方式
    • 应用开发
      • 应用是什么
      • 快速构建应用
        • 数据采集
        • 数据上云
        • 边缘计算
        • 设备通讯
      • 深入理解应用
        • 应用本质
        • 从零构造
        • 应用配置可视化
      • 注意事项
      • 应用示例
    • 发布应用
      • 申请账户
      • 新建应用
      • 克隆应用
      • 应用打包
      • 应用上传
  • 接口文档
    • 应用接口
      • 应用基础类模块
        • 应用基础类
        • MQTT应用基础类
      • 系统接口
      • 基础接口
      • 设备对象
      • 统计接口
      • 日志接口
      • 事件类型和等级
      • 云配置接口
      • 云配置帮助接口
      • 数据通讯模块
        • 端口模块
        • 帮助模块
        • 端口超时封装
      • 工具类模块
        • 数据订阅计算
        • 数据拼接
        • 数据流缓存
    • 系统服务接口
      • 配置服务
      • 软件分发服务
      • 扩展管理服务
      • 应用管理服务
      • 缓存服务
    • 其它资料 & 文档
      • Lua语言学习
      • 二进制数据操作
      • 文件操作
      • 模块列表
      • IOE模块
      • 串口操作模块
      • 累计量计算模块
      • 工具模块
        • helper模块
        • leds模块
        • gpios模块
        • sysinfo模块
        • 周期计时模块
Powered by GitBook
On this page
  • 应用基础接口
  • set_handler
  • list_devices
  • add_device
  • del_device
  • get_device
  • send_ctrl
  • cleanup
  • _dump_comm
  • _fire_event

Was this helpful?

  1. 接口文档
  2. 应用接口

基础接口

应用基础接口

FreeIOE框架为每个应用创建的服务接口,用以帮助应用快速构建设备模型等操作

set_handler

设定处理回调函数。

函数原型

function api:set_handler(handler, watch_data)
end

参数说明

  • handler

    回调函数集合(table)

  • watch_data

    是否关注其他应用创建的设备数据消息

示例代码

local api = sys:data_api()
api:set_handler({
    on_comm = function(src_app, dev_sn, dir, timestamp, ...) end, -- watch_data = true
    on_stat = function(src_app, dev_sn, state, prop, value, timestamp) end, -- watch_data = true
    on_input = function(src_app, dev_sn, input, prop, value, timestamp, quality) end, -- watch_data = true
    on_add_device = function(src_app, dev_sn, props) end, -- watch_data = true
    on_del_device = function(src_app, dev_sn, props) end, -- watch_data = true
    on_mod_device = function(src_app, dev_sn) end, -- watch_data = true
    on_output = function(src_app, dev_sn, output, prop, value, timestamp) end, -- 数据输出项回调
    on_output_result = function(src_app, priv, result, err) end, -- 数据输出项请求执行结果回调
    on_command = function(src_app, dev_sn, command, params) end, -- 命令回调
    on_command_result = function(src_app, priv, result, err) end, -- 命令请求执行结果回调
    on_ctrl = function(src_app, command, params) end, -- 应用控制接口
    on_ctrl_result = function(src_app, priv, result, err) end, -- 应用控制执行结果回调
})

API_VER: 5 API_VER 5支持了 on_output_result 和 on_command_result接口

list_devices

枚举系统中所有设备对象的描述信息 (meta, inputs, outputs, commands等等)

函数原型

function api:list_devices()
end

add_device

函数原型

function api:add_device(sn, meta, inputs, outputs, commands)
end

参数说明

  • sn

    设备序列号

  • meta

    设备Meta信息

  • inputs

    设备输入项列表

  • outputs

    设备输出项列表

  • commands

    设备控制项列表

示例代码

--- 创建设备模型
local inputs = {
    {name="tag1", desc="tag1 desc", unit="KV", vt="float"},
    {name="tag2", desc="tag2 desc", unit="KV", vt="float"}
}
local outputs = {
    {name="output1", desc="output1 desc", unit="V"},
}
local commands = {
    {name="command1", desc="command desc"},
}

local meta = self._api:default_meta()
meta.name = "Example Device"
meta.description = "Example Device Meta"
--- 生成设备模型对象
local dev = self._api:add_device(sn, meta, inputs, outputs, commands)

del_device

删除设备。 dev为设备对象实例。

函数原型

function api:del_device(dev)
end

get_device

获取设备对象实例。 此接口对象可以用来读取设备输入项数据,写入设备输出项,发送设备控制项。 当secret值被指定且与设备源应用中设定的secret值一致时,可获取设备的输入项数据写入的权限。 参考: device:share(secret)接口

函数原型

function api:get_device(sn, secret)
end

send_ctrl

发送应用控制指令。 会调用应用设定的handler.on_ctrl。 如需跟踪结果需要设定on_ctrl_result处理函数

函数原型

function api:send_ctrl(app, ctrl, params)
end

cleanup

接口清理接口(sys接口清理时,会自动调用此接口)

函数原型

function api:cleanup()
end

_dump_comm

内部接口

函数原型

function api:_dump_comm(sn, dir, ...)
end

_fire_event

内部接口

函数原型

api:_fire_event(sn, level, data, timestamp)
Previous系统接口Next设备对象

Last updated 5 years ago

Was this helpful?

创建新的采集设备对象。返回设备对象实例(参考)。

了解

设备API
更多信息