tidstagning/Tidstagning/Relay.cs

34 lines
731 B
C#
Raw Normal View History

2020-04-21 15:47:38 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
namespace Tidstagning
{
class Relay
{
SerialPort com;
public Relay(string ComPort)
{
com = new SerialPort();
com.PortName = ComPort;
com.BaudRate = 9600;
com.Open();
}
public void Set(int output, byte state) {
byte[] command = {0xff, 0x01, state};
com.Write(command, 0, 3);
}
public void Close() {
if(com.IsOpen)
com.Close();
}
public static string[] GetPorts()
{
return SerialPort.GetPortNames();
}
}
}