dSRelay 0.1.3

dSRelay 0.1.3

Maintained by Mèir Noordermeer, Siwa, Thijs.



 
Depends on:
SwiftSocket>= 0
thenPromise>= 0
 

dSRelay 0.1.3

  • By
  • Mèir Noordermeer

dSRelay

CI Status Version License Platform

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 device

Sending Commands

The binary commands documented by Robot Electronics are implemented in this library. The original documentation can be found here.

Get Status

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

// 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
}

Get Status of Relays

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
}

Get Input

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
}

Get Counters

device.getCounters().then { counters in
    // counters is a tuple of (counterValue: UInt, captureRegister: UInt)
}

Installation

dSRelay is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'dSRelay'

License

dSRelay is available under the Apache 2.0 license. See the LICENSE file for more info.