/// <summary> /// This function will be called any time any output signal is changed. It will create /// a byte array for either sol1 - sol8 (output port 0) or sol9 - sol16 (output port 1) /// and convert it into a byte to write to the Io board. Since our Io boards work in /// reverse logic (i.e 1 means off and 0 means on) our starting result is 0xFF /// or 1111 1111. /// /// 16 = output port 0, 17 = output port 1 /// </summary> private void WriteToIoBoard(byte port) { bool[] source; byte result = 0xFF; // This assumes the array never contains more than 8 elements. if (port == 16) // output port 0 { source = new bool[8] { sol1, sol2, sol3, sol4, sol5, sol6, sol7, sol8 }; } else // output port 1 { source = new bool[8] { sol9, sol10, sol11, sol12, sol13, sol14, sol15, sol16 }; } int index = 0; // convert the bool array to a byte foreach (bool b in source) { if (b) { result &= (byte)~(1 << (index)); } index++; } USBIOBoardService.WritePort(BoardNum, port, result); }
/// <summary> /// This command calls the Stop command in USBIOService which will close all connections /// and removes the objects from our ActiveIoBoards dictionary. Then it will restart the /// USBIOService which redetects any connected Io boards. /// </summary> public static void Execute() { USBIOBoardService.Stop(); // lets give USBIOService half a second to handle its business Thread.Sleep(500); // now restart that USBIOBoardService.Start(); }
/// <summary> /// This function will be called any time any output signal is changed. It will create /// a byte array for either sol1 - sol8 (output port 0) and convert it into a byte to /// write to the Io board. Since our Io boards work in reverse logic (i.e 1 means off /// and 0 means on) our starting result is 0xFF or 1111 1111. /// /// 16 = output port 0 /// </summary> private void WriteToIoBoard(byte port) { bool[] source = new bool[8] { sol1, sol2, sol3, sol4, sol5, sol6, sol7, sol8 }; byte result = 0xFF; int index = 0; // convert the bool array to a byte foreach (bool b in source) { if (b) { result &= (byte)~(1 << (index)); } index++; } USBIOBoardService.WritePort(BoardNum, port, result); }