Added SinaglR

This commit is contained in:
2023-06-08 13:36:25 -07:00
parent 2c38ecb399
commit 9452454b8a
33 changed files with 3540 additions and 33 deletions

View File

@ -9,20 +9,23 @@ public class SerialService : ISerialService
private string _LastRaw;
private readonly AppSettings _AppSettings;
private readonly System.IO.Ports.SerialPort _SerialPort;
private readonly System.IO.Ports.SerialPort? _SerialPort;
public SerialService(AppSettings appSettings)
{
_LastRaw = string.Empty;
_AppSettings = appSettings;
_SerialPort = new("/dev/ttyUSB0", 9600) { ReadTimeout = 2 };
if (string.IsNullOrEmpty(appSettings.SerialPortName))
_SerialPort = null;
else
_SerialPort = new(appSettings.SerialPortName, 9600) { ReadTimeout = 2 };
}
void ISerialService.Open() =>
_SerialPort.Open();
_SerialPort?.Open();
void ISerialService.Close() =>
_SerialPort.Close();
_SerialPort?.Close();
void ISerialService.SerialPortWrite(int count, string raw)
{
@ -36,7 +39,7 @@ public class SerialService : ISerialService
else
message = $" {raw}";
byte[] bytes = Encoding.ASCII.GetBytes(message);
_SerialPort.Write(bytes, 0, bytes.Length);
_SerialPort?.Write(bytes, 0, bytes.Length);
_LastRaw = raw;
}
}