I hung my head in shame as I gave up on my old relay boards and ironically went back to the same company I started with, Control Anything. Now that I’m DC for the relays and using their Bluetooth model and an expansion board. So part number wise, I got a BTADR85ProXR (Bluetooth master, 8 channel, 5 Amp SPDT Relay board) and a XR165 (slave, 16 Channel, 5 Amp SPDT relay board). The nice thing about their boards and Bluetooth is it mounts as a serial port AND is wireless so I can’t blow up another laptop.
While I do have the c# relay board file still, I think it needs some work to make it work far better. I think I may shift to a queue (first in, first out) for commands. Due to the massive difference in commands, I needed to change a few things. On the Robotic Connection boards, everything was timer based, with Control Anything boards, I control the timing. They do have timers onboard, however their documentation has a warning precision worries me.
New UI for relay board tester:
Another big change I did with the source is changed it to a very simple metaphor for operating the API. Stuff typically turned stuff ON or OFF so I changed stuff from AllRelaysOnBank, AllRelaysOn, and RelaysOn to what you see below. I found a new command that may cause an issue but overall, I think this works nicely. Simple and clean, like snow. Snow hides all.
Some code from my refactored / tweaked Control Anything class:
public bool On()
{
write(new byte[] { startCommand, 130, 0 });
return success();
}
public bool On(int Relay)
{
write(new [] { startCommand, (byte)(Relay + 8) });
return success();
}
public bool On(int Bank, int Relay)
{
toggleRelayCommand(Bank, Relay, true);
return success();
}
private static void toggleRelayCommand(int Bank, int Relay, bool TurnOn)
{
Relay += 100 + ((TurnOn) ? 8 : 0);
write(new [] { startCommand, (byte)Relay, (byte)Bank });
}
private static void write(byte[] bytes)
{
ComPort.WriteBuffer(bytes);
}
private static bool success()
{
return success(85);
}
private static bool success(int successCode)
{
var temp = ComPort.ReadBufferChar();
#if DEBUG
Console.WriteLine(temp);
#endif
return (temp == successCode);
}