Author Topic: Voice control for USB relay board  (Read 1945 times)

pakitt1970

  • Newbie
  • *
  • Posts: 2
Voice control for USB relay board
« on: August 06, 2021, 06:25:43 AM »
Hey folks… I am new here and I was wondering if voice attack can be used to operate sub relay boards and if so if anyone knows of any plug-in it would be greatly appreciated…. Thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4767
  • RTFM
Re: Voice control for USB relay board
« Reply #1 on: August 06, 2021, 03:16:59 PM »
There is no standard for "sub relay boards", so that would depend on the specific product you're referring to.

If it's something that expects a simple text command over a serial connection, that may not even require a plugin.

pakitt1970

  • Newbie
  • *
  • Posts: 2
Re: Voice control for USB relay board
« Reply #2 on: August 16, 2021, 08:23:17 AM »
Damn typo.  I meant usb relay boards…. Something like this
SainSmart USB Eight Channel Relay Board for Automation - 12 V

https://www.amazon.com/dp/B0093Y89DE/ref=cm_sw_r_cp_api_glt_fabc_9KGZ3J1FWRKHJRDGTM0V

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4767
  • RTFM
Re: Voice control for USB relay board
« Reply #3 on: August 16, 2021, 09:28:39 AM »
According to the Amazon comments, basic operation just requires a single byte.

As a simple test, you could try using the serial port file system endpoints built-into Windows.

E.G. open a command prompt, type in
Code: [Select]
echo W > COM1and see if seven of the relays turn on (replace COM1 with the serial port identifier of your device)


To control each relay individually, you'd likely want to use a plugin or inline function, given that 255 is not a simple ASCII character. There is no such plugin (or inline function) that I'm personally aware of.

You'll also need to either keep track of which relays are on already, as the interface is stateless (meaning, if you send a command to turn on only one relay, it'll turn all the other ones off), or check whether the board you're using supports retrieving the current state (especially useful between sessions/after power cycling).


A basic(-ish) inline function could look something like
Code: [Select]
using System.IO.Ports;
using System.Collections;

public class VAInline
{
public void main()
{
VA.SetBoolean("relay0On", !VA.GetBoolean("relay0On") ?? false); // Toggles the first relay each time the inline function executes

byte[] serialBytes = {0};
BitArray dataBits = new BitArray(serialBytes);

for (int i = 0; i < 8 ; i++)
{
bool relayState = VA.GetBoolean("relay" + i + "On") ?? false;
{
dataBits.Set(i, relayState);
}
}

dataBits.CopyTo(serialBytes, 0);

SerialPort port = new SerialPort("COM9");

port.Open();

port.Write(serialBytes, 0, serialBytes.Length);
VA.WriteToLog("sent " + serialBytes[0]); // Writes the decimal value of the byte to the log

port.Close();
}
}
If you set a series of Boolean variables, named "relay0On" to "Relay7On" to either True or False, the corresponding relays should energize or de-energize accordingly when you execute the inline function.

Relay 0 (I.E. the first relay) is toggled each time the inline function executes, and a decimal representation of the byte is written to the log, for testing. Neither are required for normal operation.