51 lines
1.0 KiB
C#
51 lines
1.0 KiB
C#
using System.IO.Ports;
|
|
namespace Tidstagning
|
|
{
|
|
class Relay
|
|
{
|
|
SerialPort com;
|
|
public Relay(string ComPort = null)
|
|
{
|
|
com = new SerialPort();
|
|
com.PortName = ComPort;
|
|
com.BaudRate = 9600;
|
|
try
|
|
{
|
|
com.Open();
|
|
} catch
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public void Set(int output, byte state) {
|
|
byte[] command = {0xff, 0x01, state};
|
|
if (com.IsOpen)
|
|
{
|
|
com.Write(command, 0, 3);
|
|
}
|
|
}
|
|
public void Close() {
|
|
if (com.IsOpen)
|
|
{
|
|
com.Close();
|
|
}
|
|
}
|
|
|
|
public static string[] GetPorts()
|
|
{
|
|
string[] ports;
|
|
|
|
if (SerialPort.GetPortNames().Length != 0)
|
|
{
|
|
ports = SerialPort.GetPortNames();
|
|
}
|
|
else
|
|
{
|
|
ports = new string[]{ "N/A" };
|
|
}
|
|
return ports;
|
|
}
|
|
}
|
|
}
|