From 16479bbf2fa62f09f896e96e66d0720da2e45f08 Mon Sep 17 00:00:00 2001 From: Eline Jorritsma Date: Wed, 4 Sep 2024 11:34:13 +0200 Subject: [PATCH 1/2] Improve RFID reading --- SickRfid/ConnectedSickRfidController.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SickRfid/ConnectedSickRfidController.cs b/SickRfid/ConnectedSickRfidController.cs index c14c5a8..cdf712d 100644 --- a/SickRfid/ConnectedSickRfidController.cs +++ b/SickRfid/ConnectedSickRfidController.cs @@ -98,10 +98,9 @@ public async Task ReadAsync(CancellationToken cancellationToken = defaul var result = await _socket.ReceiveAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false); if (result <= 0) continue; var message = Encoding.ASCII.GetString(buffer, 0, result); - if (string.IsNullOrEmpty(message) || - message.Equals(Acknowledgements.ACK_START, StringComparison.Ordinal) || + message.Contains(Acknowledgements.ACK_START, StringComparison.Ordinal) || message.Contains(Acknowledgements.ACK_STOP, StringComparison.Ordinal)) continue; return message; From 1b80e3fe2d0b71299bf1ab88fa57ac20e2bc3b9a Mon Sep 17 00:00:00 2001 From: Eline Jorritsma Date: Thu, 5 Sep 2024 17:28:17 +0200 Subject: [PATCH 2/2] !WIP - integrating RFID Mock --- SickRfid/ConnectedSickRfidController.cs | 2 +- SickRfid/DisconnectedSickRfidController.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SickRfid/ConnectedSickRfidController.cs b/SickRfid/ConnectedSickRfidController.cs index cdf712d..f1c8eaa 100644 --- a/SickRfid/ConnectedSickRfidController.cs +++ b/SickRfid/ConnectedSickRfidController.cs @@ -100,7 +100,7 @@ public async Task ReadAsync(CancellationToken cancellationToken = defaul var message = Encoding.ASCII.GetString(buffer, 0, result); if (string.IsNullOrEmpty(message) || - message.Contains(Acknowledgements.ACK_START, StringComparison.Ordinal) || + message.Equals(Acknowledgements.ACK_START, StringComparison.Ordinal) || message.Contains(Acknowledgements.ACK_STOP, StringComparison.Ordinal)) continue; return message; diff --git a/SickRfid/DisconnectedSickRfidController.cs b/SickRfid/DisconnectedSickRfidController.cs index cb3977c..be185b9 100644 --- a/SickRfid/DisconnectedSickRfidController.cs +++ b/SickRfid/DisconnectedSickRfidController.cs @@ -18,10 +18,10 @@ internal DisconnectedSickRfidController(IPAddress ipAddress, int port) _port = port; } - public async Task ConnectAsync() + public async Task ConnectAsync(CancellationToken cancellationToken = default) { var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); - await socket.ConnectAsync(_ipAddress, _port).ConfigureAwait(true); + await socket.ConnectAsync(_ipAddress, _port, cancellationToken).ConfigureAwait(true); return new ConnectedSickRfidController().SetSocket(socket); } } \ No newline at end of file