-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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). |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
self._dev.set_relay(relay_number=params['relay_number'], | ||
on_off=params['on_off'], | ||
pulse_time=params['pulse_time']) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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:
socs/socs/Lakeshore/Lakeshore372.py
Line 1816 in 7631d0e
ls = LS372(sys.argv[1]) |
There was a problem hiding this comment.
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.
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
Checklist: