using System.IO.Ports; namespace RGB.NET.Devices.WS281X; /// /// /// Represents a serial-connection using the default microsoft serial-port implementation. /// public class SerialPortConnection : ISerialConnection { #region Properties & Fields /// /// The used for the connection. /// public SerialPort SerialPort { get; } /// public string Port => SerialPort.PortName; /// public int BaudRate => SerialPort.BaudRate; /// public bool IsOpen => SerialPort.IsOpen; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The name of the serial-port to connect to. /// The baud-rate used by the serial-connection. public SerialPortConnection(string port, int baudRate) { SerialPort = new SerialPort(port, baudRate); } #endregion #region Methods /// public void Open() => SerialPort.Open(); /// public void DiscardInBuffer() => SerialPort.DiscardInBuffer(); /// public byte ReadByte() => (byte)SerialPort.ReadByte(); /// public void ReadTo(char target) => SerialPort.ReadTo(target.ToString()); /// public void Write(byte[] buffer, int offset, int length) => SerialPort.Write(buffer, offset, length); /// public void WriteLine(string line) => SerialPort.WriteLine(line); /// public void Dispose() => SerialPort.Dispose(); #endregion }