Skip to content

Serialize transport access for async calls#23

Merged
c3rebro merged 1 commit intomasterfrom
handle-com-port-access-errors
Jan 23, 2026
Merged

Serialize transport access for async calls#23
c3rebro merged 1 commit intomasterfrom
handle-com-port-access-errors

Conversation

@c3rebro
Copy link
Owner

@c3rebro c3rebro commented Jan 23, 2026

Motivation

  • Concurrent async calls could interleave writes/reads on the underlying COM transport and provoke device-level AccessDenied errors, so transport access needs serialization inside the library.

Description

  • Added an async lock field SemaphoreSlim _transportLock to TWN4ReaderDevice to serialize access to the transport.
  • Wrapped the transport TX/RX path in DoTXRXAsync with await _transportLock.WaitAsync() and a finally that calls _transportLock.Release() to ensure calls do not overlap.
  • Added a test helper ConcurrentReaderTransport that detects overlapping write/read cycles.
  • Added a unit test CallFunctionRawAsync_SerializesConcurrentCalls to verify concurrent CallFunctionRawAsync calls are serialized and do not overlap.

Testing

  • Ran dotnet test tests/Elatec.NET.Tests/Elatec.NET.Tests.csproj, which executed the test suite and passed: 24 passed, 0 failed.

Codex Task

@c3rebro c3rebro merged commit c44ef2a into master Jan 23, 2026
1 of 2 checks passed
@c3rebro c3rebro deleted the handle-com-port-access-errors branch January 23, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant