Constructor
new UdpComm(plug, udpIdx)
UDP通讯接口
Parameters:
Name | Type | Default | Description |
---|---|---|---|
plug | RktPlug | 插件通信对象 | |
udpIdx | number | 0 | UDP对象索引 |
- Source
Methods
(async) devApiV1(keyStr) → {Promise}
激活设备APIv1通讯模式
Parameters:
Name | Type | Description |
---|---|---|
keyStr | string | 设备APIv1字符串密钥 |
- Source
Returns:
err/msg + retval
- Type:
- Promise
getUdpIdx() → {number}
获取当前UDP对象索引
- Source
Returns:
- Type:
- number
(async) send(host, data) → {Promise}
发送数据报
Parameters:
Name | Type | Description |
---|---|---|
host | string | 发送目标地址 |
data | string | 十六进制数据包 |
- Source
Returns:
err/msg + retval(实际发送字节数)
- Type:
- Promise
setUdpIdx(udpIdx)
设置切换UDP对象索引
Parameters:
Name | Type | Description |
---|---|---|
udpIdx | number | UDP对象索引 |
- Source
(async) start(callback, broadcast, host) → {Promise}
启动通讯 注意重复调用仅callback更改有效,retval一定返回true
Parameters:
Name | Type | Default | Description |
---|---|---|---|
callback | callback | 事件回调evt参数对象包含host(来源地址信息)/data(十六进制数据包) | |
broadcast | boolean | false | 是否启用UDP广播支持 |
host | string | 0.0.0.0:0 | 默认绑定随机未占用端口(客户端场景) 否则为绑定指定地址与端口但端口被占用将会失败(服务端场景) |
- Source
Returns:
err/msg + retval
- Type:
- Promise
(async) stop() → {Promise}
停止通讯
- Source
Returns:
err/msg
- Type:
- Promise