From fb105adb8a0974b701ca52bcd4139a10f3ec69da Mon Sep 17 00:00:00 2001 From: "alexander.mushinskiy" Date: Tue, 6 May 2025 13:00:02 +0300 Subject: [PATCH] Add IsOpen flag to SerialLink. --- ThreeByte.LinkLib/ThreeByte.LinkLib.SerialLink/SerialLink.cs | 1 + ThreeByte.LinkLib/ThreeByte.LinkLib.TcpLink/AsyncTcpLink.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ThreeByte.LinkLib/ThreeByte.LinkLib.SerialLink/SerialLink.cs b/ThreeByte.LinkLib/ThreeByte.LinkLib.SerialLink/SerialLink.cs index 7302f43..437e433 100644 --- a/ThreeByte.LinkLib/ThreeByte.LinkLib.SerialLink/SerialLink.cs +++ b/ThreeByte.LinkLib/ThreeByte.LinkLib.SerialLink/SerialLink.cs @@ -14,6 +14,7 @@ public class SerialLink : IDisposable public event EventHandler? DataReceived; public bool IsConnected => _isConnected; public bool IsEnabled => _isEnabled; + public bool IsOpen => _serialPort?.IsOpen ?? false; public bool HasData => _incomingData.Count > 0; private const int MaxDataSize = 100; diff --git a/ThreeByte.LinkLib/ThreeByte.LinkLib.TcpLink/AsyncTcpLink.cs b/ThreeByte.LinkLib/ThreeByte.LinkLib.TcpLink/AsyncTcpLink.cs index 176481e..ea30efc 100644 --- a/ThreeByte.LinkLib/ThreeByte.LinkLib.TcpLink/AsyncTcpLink.cs +++ b/ThreeByte.LinkLib/ThreeByte.LinkLib.TcpLink/AsyncTcpLink.cs @@ -391,7 +391,7 @@ private void ReadCallback(IAsyncResult asyncResult) /// Fetches and removes (pops) the next available group of bytes as received on this link in order (FIFO) /// /// null if the link is not Enabled or there is no data currently queued to return, an array of bytes otherwise. - public byte[] GetMessage() + public byte[]? GetMessage() { if (_isDisposed) { @@ -404,7 +404,7 @@ public byte[] GetMessage() return null; } - byte[] newMessage = null; + byte[]? newMessage = null; lock (_incomingData) { if (HasData)