Skip to content

Add client (connect) mode for passive instruments / serial-to-LAN gateways#61

Open
xispa wants to merge 2 commits into
masterfrom
client-mode
Open

Add client (connect) mode for passive instruments / serial-to-LAN gateways#61
xispa wants to merge 2 commits into
masterfrom
client-mode

Conversation

@xispa

@xispa xispa commented Jun 2, 2026

Copy link
Copy Markdown
Member

Description of the issue/feature this PR addresses

senaite.astm currently runs only as a TCP server (server.py is built on loop.create_server(...)), so it always waits for the instrument — or its serial-to-LAN gateway — to connect in.

Some gateways are configured as passive TCP servers themselves (they only accept connections, they never dial out) and therefore expect the LIS to initiate the connection. A real-world example: an Abbott ARCHITECT ci4100 behind a Lantronix UDS1100 with Accept Incoming = Yes / Active Connect = None. In that topology both ends are passive listeners, no socket is ever established, and not a single byte (not even <ENQ>) reaches the server.

This PR adds a client (connect) mode so senaite.astm can actively open the outbound connection to such a device, while reusing the exact same ASTMProtocol receiver logic.

What changed

  • server.py: new --connect HOST:PORT mode (mutually exclusive with --listen/--port) that connects out to the instrument/gateway via loop.create_connection(...), plus --reconnect-delay (default 5s) for automatic reconnection when the link drops. Server (listen) mode is unchanged and remains the default.
  • protocol.py: ASTMProtocol gains an optional on_connection_lost future (defaults to None) that connection_lost resolves, letting the connect loop detect drops and reconnect. In server mode it stays None — no behavior change.
  • tests/test_astm_client.py: covers message reception and reconnect-after-drop by standing up a passive fake instrument that the client connects to.

Current behavior before PR

senaite.astm can only listen for incoming connections. It cannot integrate with an instrument or gateway that is itself passive and requires the LIS to initiate the connection.

Desired behavior after PR is merged

senaite.astm --connect HOST:PORT actively connects out to the instrument / gateway and processes messages with the same protocol/queue/wrapper pipeline as server mode, reconnecting automatically if the connection is lost.

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@xispa xispa requested a review from ramonski June 2, 2026 12:57
@xispa xispa marked this pull request as draft June 2, 2026 13:06
@xispa xispa marked this pull request as ready for review June 4, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant