Skip to content

Add shared serial port access between tabs#1401

Open
tomfrew wants to merge 1 commit intoqzind:masterfrom
teamkeel:shared-serial-port
Open

Add shared serial port access between tabs#1401
tomfrew wants to merge 1 commit intoqzind:masterfrom
teamkeel:shared-serial-port

Conversation

@tomfrew
Copy link
Copy Markdown

@tomfrew tomfrew commented Jan 7, 2026

Summary

Enables multiple browser tabs to share access to the same serial port. Previously, only the first tab could open a serial port; subsequent tabs received "port busy" errors.

Fixes #1366

Changes

  • New SerialPortMonitor - Central coordinator following the existing StatusMonitor pattern with reference counting
  • New SharedSerialPort - Wraps JSSC SerialPort with multi-listener dispatch, broadcasts received data to all connected tabs
  • New SerialSession - WebSocket session wrapper for sending serial events
  • Modified SerialOptions - Added explicit settings tracking and equals() methods for conflict detection
  • Modified SerialUtilities - Routes through SerialPortMonitor instead of direct SerialIO creation
  • Modified SocketConnection - Added cleanup on disconnect

Behavior

  • Bidirectional: All tabs can send and receive data
  • First opener wins: First tab's port settings (baud rate, parity, etc.) become canonical
  • Joining tabs: Can join without specifying settings, or must specify matching settings
  • Reference counting: Physical port closes only when last listener disconnects
  • Conflict handling: Rejects with clear error if explicit settings differ from the open port

Testing

We have a dev testing utility using socat to create virtual serial port pairs for automated testing without physical hardware. It's not included in this PR since socat isn't universally available, but we can add it if helpful for CI or review.

@tresf
Copy link
Copy Markdown
Contributor

tresf commented Jan 7, 2026

We have a dev testing utility using socat to create virtual serial port pairs for automated testing without physical hardware. It's not included in this PR since socat isn't universally available, but we can add it if helpful for CI or review.

@Vzor- and I are working on integrating TestNG, so we'd love to see something similar to socat to ensure basic functionality is working, but until we have some boilerplate tests, I'd rather we hold off on adding this to our codebase. Furthemore, @bratpeki is working on NPM tests, which may be a better home, depending.

Thanks for the contribution, @Vzor- and I will be reviewing this shortly. If you need a one-off build in the meantime, just let me know, I'd happily provide one that's signed and all that.

@tresf tresf assigned Vzor- and tresf Jan 7, 2026
@tresf tresf added this to the 2.3.0 milestone Jan 7, 2026
@tomfrew
Copy link
Copy Markdown
Author

tomfrew commented Jan 14, 2026

Thanks @tresf

I could push the virtual serial port testing parts in a separate PR if that's helpful and you're welcome to just close it?

It's not super urgent for us for now so no worries about a one-off build but thanks. Do you have a rough estimate for when the 2.3.0 will ship?

@tresf
Copy link
Copy Markdown
Contributor

tresf commented Jan 16, 2026

I could push the virtual serial port testing parts in a separate PR if that's helpful and you're welcome to just close it?

@tomfrew TestNG is in WIP status on the testng branch. Feel free to PR against it if you'd like to add some unit tests. I understand that calling socat from Java is a bit extra, but that's the best way forward for now, I think.

With regards to testing on platforms such as Windows, I spent hours attempting this today, but it seems that we need a signed kernel-mode driver and the ones that are compatible with JSSC just-so-happen to also be commercially licensed in either a time-limited or feature-limited fashion not allow running in any automated fashion.

I considered patching JSSC to allow named pipes directly to make this easier on ourselves but we'd have to add some win32 API bypasses, which wouldn't really be an honest test.

So if we do add tests, we'll probably have to skip windows for the foreseeable future (I'd love to be proven wrong here).

It's not super urgent for us for now so no worries about a one-off build but thanks. Do you have a rough estimate for when the 2.3.0 will ship?

Our plan is to start QA on 2.2.6 in the next week or two, then we'll be bumping master branch to 2.3.0-SNAPSHOT merging the ivy branch for better dependencies. This creates a moving target with TestNG since it should be targeted against IVY (for quite a few reasons), but we're still in the R&D process on the testng branch so that'll change as-needed/convenient.

We're hoping a 2.3.0 in February / March. Almost definitely by April.

@tresf
Copy link
Copy Markdown
Contributor

tresf commented Jan 26, 2026

I could push the virtual serial port testing parts in a separate PR if that's helpful and you're welcome to just close it?

@tomfrew TestNG is in WIP status on the testng branch. Feel free to PR against it if you'd like to add some unit tests. I understand that calling socat from Java is a bit extra, but that's the best way forward for now, I think.

FYI, TestNG is live on master, feel free to propose whatever tests you'd like. We've been getting more and more requests for this feature, so it'll have eyes as soon as possible. We're currently prioritizing #1368 for the 2.2.6 release.

@tresf
Copy link
Copy Markdown
Contributor

tresf commented Jan 26, 2026

FYI, created a temporary branch to make this available to our portal. https://github.com/qzind/tray/tree/shared-serial. When this branch is rebased on master, getByteArray --> toByteArray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared serial port access between tabs

3 participants