Skip to content

Release the serial port when connection fails - #170

Merged
glopesdev merged 1 commit into
harp-tech:mainfrom
glopesdev:release-port-on-failed-connect
Oct 30, 2026
Merged

glopesdev merged 1 commit into
harp-tech:mainfrom
glopesdev:release-port-on-failed-connect

Conversation

@glopesdev

Copy link
Copy Markdown
Contributor

CreateAsync disposes the AsyncDevice it creates when the identity check fails, when the device replies to the identity read with an error, or when the operation is canceled. The serial port is closed before the returned task faults.

Without this, the port would stay open until the device object was finalized, so connecting again to the same port would fail with UnauthorizedAccessException.

Tested against a Behavior board using the interface generated from the test metadata, whose identity check fails against that board. After the failed connection, opening the same serial port again throws UnauthorizedAccessException with the code generated from main, and succeeds with this change.

CreateAsync disposes the device it creates when reading or checking
the device identity fails, including on cancellation, so the serial
port is closed before the returned task faults. Connecting again on
the same port no longer fails because an earlier attempt left it open.
@glopesdev glopesdev added the fix Pull request that fixes an issue label Oct 30, 2026
@glopesdev
glopesdev merged commit baf9803 into harp-tech:main Oct 30, 2026
9 checks passed
@glopesdev
glopesdev deleted the release-port-on-failed-connect branch October 30, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull request that fixes an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant