Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create TCPInterface class as base class for TCP based interfaces to devices #769

Merged
merged 6 commits into from
Nov 21, 2024

Conversation

BrianJKoopman
Copy link
Member

Description

This PR introduces the TCPInterface class, extracted from the Cryomech agent's PTC class, mostly unmodified. I did rename a bit of the API to more closely match the socket API, which developers might already be familiar with.

While extracting this I wrote a docstring for the PTC class, which was missing that.

Motivation and Context

Good error handling for any interface is tricky. This class should allow all TCP based agents to use the same error handling logic. I plan to use this next on the Lakeshore 372 agent, so this is one step towards that, and ultimately a step towards #721.

How Has This Been Tested?

This has been tested within the Cryomech agent, testing unplugging the network connection between the agent and compressor. I also tested a power cycle, which triggers the reset path that 72f5a00 modifies. Here are the logs from testing. The first "Connection re-established" was after unplugging and replugging. The second is from the power cycle:

2024-10-04T18:08:10-0400 startup-op: launching init
2024-10-04T18:08:10-0400 start called for init
2024-10-04T18:08:10-0400 init:0 Status is now "starting".
2024-10-04T18:08:10-0400 init:0 Status is now "running".
2024-10-04T18:08:10-0400 PTC Model: 4_19
2024-10-04T18:08:10-0400 PTC Serial Number: 10444
2024-10-04T18:08:10-0400 Software Revision is: 2.155
2024-10-04T18:08:10-0400 start called for acq
2024-10-04T18:08:10-0400 acq:1 Status is now "starting".
2024-10-04T18:08:10-0400 Response from acq.start(): Started process "acq".
2024-10-04T18:08:10-0400 init:0 PTC agent initialized
2024-10-04T18:08:10-0400 init:0 Status is now "done".
2024-10-04T18:08:10-0400 acq:1 Status is now "running".
2024-10-04T18:08:25-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:08:36-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:08:43-0400 Connection re-established.
2024-10-04T18:09:02-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:13-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:24-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:35-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:46-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:50-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:51-0400 Connection error: [Errno 32] Broken pipe
2024-10-04T18:09:51-0400 Resetting the connection to the device.
2024-10-04T18:09:51-0400 Unable to connect. [Errno 111] Connection refused
2024-10-04T18:09:51-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:52-0400 Connection not established.
2024-10-04T18:09:52-0400 Resetting the connection to the device.
2024-10-04T18:09:52-0400 Unable to connect. [Errno 111] Connection refused
2024-10-04T18:09:52-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:53-0400 Connection not established.
2024-10-04T18:09:53-0400 Resetting the connection to the device.
2024-10-04T18:09:53-0400 Unable to connect. [Errno 111] Connection refused
2024-10-04T18:09:53-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:54-0400 Connection not established.
2024-10-04T18:09:54-0400 Resetting the connection to the device.
2024-10-04T18:09:54-0400 Unable to connect. [Errno 111] Connection refused
2024-10-04T18:09:54-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:55-0400 Connection not established.
2024-10-04T18:09:55-0400 Resetting the connection to the device.
2024-10-04T18:09:55-0400 Unable to connect. [Errno 111] Connection refused
2024-10-04T18:09:55-0400 Failed to get data from compressor. Check network connection.
2024-10-04T18:09:56-0400 Connection not established.
2024-10-04T18:09:56-0400 Resetting the connection to the device.
2024-10-04T18:09:56-0400 Connection re-established.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@BrianJKoopman BrianJKoopman added the enhancement New feature or request label Oct 4, 2024
@BrianJKoopman BrianJKoopman marked this pull request as ready for review October 4, 2024 22:15
@BrianJKoopman BrianJKoopman force-pushed the koopman/cryomech-robustness branch from 81929b9 to 2bddc4f Compare October 7, 2024 17:01
Base automatically changed from koopman/cryomech-robustness to main October 7, 2024 17:37
@BrianJKoopman BrianJKoopman force-pushed the koopman/tcp-device-interface-class branch from 32e4b63 to 54027b0 Compare October 7, 2024 17:54
@BrianJKoopman
Copy link
Member Author

I'm going to go ahead and merge this (after a rebase.) I thought I'd have a chance to test its use in the context of applying it to the 372 agent, but that's been slow, and I'd like to use it on another agent that I can more readily test.

This better mimics the socket API, which developers looking to use TCP might
already be familiar with.
Default to 4096, the reasonable example value from upstream docs, which is
commonly used in existing agents.
@BrianJKoopman BrianJKoopman force-pushed the koopman/tcp-device-interface-class branch from 527498a to 97d00a1 Compare November 21, 2024 18:10
@BrianJKoopman BrianJKoopman merged commit 97054e6 into main Nov 21, 2024
7 checks passed
@BrianJKoopman BrianJKoopman deleted the koopman/tcp-device-interface-class branch November 21, 2024 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant