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

Add devantech dS378 ethernet relay agent #694

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dixilo
Copy link

@dixilo dixilo commented Jun 14, 2024

Description

This pull request adds a new agent to operate devantech's dS378 ethernet relay.

Motivation and Context

Since dS378 is used in the electronics of the stimulator, the agent should be included in this repository.

How Has This Been Tested?

Test was done using the actual dS378 device.

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.

@dixilo dixilo requested a review from BrianJKoopman June 14, 2024 02:08
@BrianJKoopman BrianJKoopman added the new agent New OCS agent needs to be created label Oct 3, 2024
Copy link
Member

@BrianJKoopman BrianJKoopman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! And sorry its taken so long to get to reviewing. This looks really good overall, just a couple of minor comments, mostly related to documentation. I also made a comment about robustness to network outages, but again that can be done later if needed.

Please make a merge commit to merge in the latest from main while you're working on these.


The driver code assumes the board is configured to communicate with binary codes.
This configuration can be changed via web interface (but requires USB connection as well,
see documentation provided from the manufacturer).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add link to Manufacturer's documentation.

Comment on lines +6 to +18
GET_STATUS = 0x30, 8
SET_RELAY = 0x31, 1
SET_OUTPUT = 0x32, 1
GET_RELAYS = 0x33, 5
GET_INPUTS = 0x34, 2
GET_ANALOG = 0x35, 14
GET_STATUS = 0x30, 8
SET_RELAY = 0x31, 1
SET_OUTPUT = 0x32, 1
GET_RELAYS = 0x33, 5
GET_INPUTS = 0x34, 2
GET_ANALOG = 0x35, 14
GET_COUNTERS = 0x36, 8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here about what these represent? It seems like some single message byte that correspond to a command and an expected number of returned bytes from the dS378?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks for writing the documentation! One thing that could be added, since you wrote docstrings for the driver code, is a "Supporting APIs" section to autodoc the dS378 class in drivers.py.


from socs.agents.devantech_dS378.drivers import dS378

IP_DEFAULT = '192.168.215.241'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't hard code some default IP, that's going to depend on the network that the device is on.

'''OCS agent class for dS378 ethernet relay
'''

def __init__(self, agent, ip=IP_DEFAULT, port=17123):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make ip a required argument.

f'Could not start acq because {self.lock.job} is already running')
return False, 'Could not acquire lock.'

session.set_status('running')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now gets set automatically within the Agent when the process starts. This should be removed here.

Comment on lines +139 to +141
self._dev.set_relay(relay_number=params['relay_number'],
on_off=params['on_off'],
pulse_time=params['pulse_time'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current form this could possibly raise an AssertionError if invalid parameters are passed to the task. You should catch that, fail the task (return False), and log a message indicating the problem.

Using the param decorator commented on above would alleviate this problem, as you could ensure no invalid parameters are passed to the task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One general comment (also a bit of a nitpick, sorry) -- docstrings should always use """triple double quotes""", not single quotes. This is for consistency in the socs library, but also follows PEP8/PEP257.


def main():
'''Main function'''
ds_dev = dS378('192.168.215.100', 17123)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove hard coded IP. I'd suggest replacing with a simple sys.argv so the IP can be passed on the command line. The Lakeshore372 drives do that:

ls = LS372(sys.argv[1])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One recent thing we've been trying to do in our agents is make them robust to network outages. We're tracking that effort in #721, and there's a related discussion in #538.

In short, we'd like to be able for the agent to automatically reconnect to the device its communicating with. For devices like this one that rely on a TCP connection I recently added this TCPInterface class. It handles things like TimeoutError and other connection related exceptions, and will raise a ConnectionError, which the agent can then catch and react to accordingly by reconnecting to the device.

Again, this is relatively new, but is important for the long running processes. The only real example of this at the moment is the CryomechAgent drivers. I'm okay with putting this off to another PR (and adding this Agent to that issue I linked to), but I just wanted to mention it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new agent New OCS agent needs to be created
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants