Add Serials

This commit is contained in:
Dan Clark
2025-02-07 09:03:02 +00:00
parent 63f448f490
commit a08f86eb74
19 changed files with 270 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
using System.IO.Ports;
namespace Toolkit.Foundation;
public class SerialConnection(SerialPort serialPort) :
ISerialConnection
{
public bool IsOpen { get; private set; }
public void Close()
{
if (IsOpen)
{
try
{
serialPort.Close();
}
catch
{
}
IsOpen = serialPort.IsOpen;
}
}
public bool Open()
{
if (!IsOpen)
{
try
{
serialPort.Open();
serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer();
}
catch
{
}
IsOpen = serialPort.IsOpen;
}
return IsOpen;
}
}