dSRelay
dSRelay 是一个用于连接机器人电子网络继电器设备的小型库。此库实现了机器人电子文档中指定的所有二进制命令。
要运行示例/测试项目,请克隆该仓库,并从 Example 目录中首先运行 pod install
。
此库在 dS282 上进行了测试。
要创建设备:
if let device = Device(ipaddress: <ipaddress>, port : 17123) {
// do something
}
device.getStatus().then { status in // asynchronously get info of device
}
if let status = device.getRelayStatus().value // synchronously get info of device
发送命令
机器人电子记录的文档中实现的二进制命令。原始文档可以在这里找到。
获取状态
device.getStatus.then { status in
// status is a Dictionary<String, UInt> with the following keys:
// moduleID
// systemFirmwareMajor
// systemFirmwareMinor
// appFirmwareMajor
// appFirmwareMinor
// volts
// internalTemperature
}
设置继电器
// set a relay on/off
device.setRelay(relayNr: 1, set: Status.On).then { result in
// result is a boolean inidicating whether the command succeeded
}
// set a relay on for a certain duration (in ms)
device.setRelay(relayNr: 1, pulseTime: 1000).then { result in
// result is a boolean inidicating whether the command succeeded
}
获取继电器状态
注意:在固件版本2和3之间,返回的字节中继电器状态的顺序发生了变化。此库考虑了这种差异,因此应该可以与任何具有任何固件的设备一起工作。
仅供参考
device.getRelayStatus().then { statuses in
// statuses is an array of 32 (virtual) relays, 0 = status for relay 1 .. 31 = status for (virtual) relay 32
}
获取输入
device.getInputStatus().then { inputs in
// array of 8 booleans for each input's status (on/off)
}
device.getAnalogueInputStatus().then { inputs in
// array of 8 UInt16s indicating the analogue input's status
}
获取计数器
device.getCounters().then { counters in
// counters is a tuple of (counterValue: UInt, captureRegister: UInt)
}
安装
dSRelay通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中
pod 'dSRelay'
许可证
dSRelay遵循Apache 2.0许可证。有关更多信息,请参阅LICENSE文件。