Added SinaglR
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user