Ready to test in Fab

This commit is contained in:
2023-06-03 19:05:08 -07:00
parent 1f5deedc73
commit 2c38ecb399
46 changed files with 1159 additions and 347 deletions

View File

@ -0,0 +1,44 @@
using Barcode.Host.Server.Models;
using Barcode.Host.Shared.Models.Stateless;
using System.Text;
namespace Barcode.Host.Server.Services;
public class SerialService : ISerialService
{
private string _LastRaw;
private readonly AppSettings _AppSettings;
private readonly System.IO.Ports.SerialPort _SerialPort;
public SerialService(AppSettings appSettings)
{
_LastRaw = string.Empty;
_AppSettings = appSettings;
_SerialPort = new("/dev/ttyUSB0", 9600) { ReadTimeout = 2 };
}
void ISerialService.Open() =>
_SerialPort.Open();
void ISerialService.Close() =>
_SerialPort.Close();
void ISerialService.SerialPortWrite(int count, string raw)
{
if (raw != _LastRaw)
{
string message;
if (count == _AppSettings.ExpectedScanLengthA)
message = $" {raw[2..]} {DateTime.Now:h:m tt}";
else if (count == _AppSettings.ExpectedScanLengthB)
message = $" {raw[2..]}";
else
message = $" {raw}";
byte[] bytes = Encoding.ASCII.GetBytes(message);
_SerialPort.Write(bytes, 0, bytes.Length);
_LastRaw = raw;
}
}
}