Robot Electronics EthRly16 .net core lib April 30, 2015

2 minute read

Table of contents

Let’s move on to the next quick bit of code I refurbished lately. This time it’s a C# Library for an 8-port relay card from RobotElectronics. Specifically the EthRly16 with an ethernet port and 8 relays of which each one has a Normally-Open and Normally-Closed output. That probably explains the 16 in the model name, or its the 16 amps of switching load, who knows.

How to use it

EthRly16Card relayCard = new EthRly16Card("");

Like the IPWE library this one will be instantiated by telling it the ip address of the device. After that you can use all functions the EthRly16 has to offer. Ask for the input voltage, the firmware version, the MAC address or to get to the good part, set and unset one or all relays and query the current states of them.

double voltage = relayCard.GetInputVoltage();
byte[] mac = relayCard.GetMacAddress();
int version = relayCard.GetFirmwareVersion();
bool[] states = relayCard.GetRelaysStates();

relayCard.SetRelay(i, true);

The library including a sample console project is available on Github.

How it works

The relay card offers a tcp endpoint which is used to send commands to the device. More information about that is listed on the device website that is accessible using the ip address in the browser address line. Basically you send two bytes to the device. The first byte contains the command code and the second if needed the payload. After that you get the response which is usually one byte, except you query the mac address. In that case you get of course six bytes which represents the mac address.

Hopefully this will help someone and if you have questions leave a comment or send me an email or a tweet. See you with the next post.