dSRelay is a small library to connect with Robot Electronics network relay devices. This library implements all binary commands specified by Robot Electronics' documentation.
To run the example/tests project, clone the repo, and run pod install from the Example directory first.
This library was tested on the dS282
To create a device:
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 deviceThe binary commands documented by Robot Electronics are implemented in this library. The original documentation can be found here.
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
}Note: the order of relay status indicated in the bytes returned was changed between firmware versions 2 and 3. This library takes this difference into account and thus should work with any device with any firmware.
For reference:
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 is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'dSRelay'dSRelay is available under the Apache 2.0 license. See the LICENSE file for more info.