-
Notifications
You must be signed in to change notification settings - Fork 5
Epics, Cothread and other changes #94
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
Merged
willrogers
merged 18 commits into
DiamondLightSource:master
from
T-Nicholls:epicsCothread
Jan 21, 2019
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
87cf0a0
Update existing control system syntax to get/set_single/multiple.
T-Nicholls 0e78d3b
Other minor tweaks/changes.
T-Nicholls 0b3abd2
Redistribute epics classes to relevant modules and delete epics.py.
T-Nicholls 680efa5
Updates to hoe cothread_cs throws exceptions.
T-Nicholls 6fb6dc1
Resolve conflicts and incorporate new changes to exceptions.
T-Nicholls bcb7bb0
Some minor changes to things that mildy anoyed me.
T-Nicholls fe6aef2
Some minor fixes/changes that I have collected.
T-Nicholls d5c907d
Some doc string changes.
T-Nicholls 2e2c55c
More consistent docstrings.
willrogers 4d9e599
Add configurable timeout to CothreadControlSystem.
willrogers c57cac8
Minor improvements: logging and unused import.
willrogers 406e2fa
More consistent behaviour in CothreadControlSystem.
willrogers a5ab2bf
Merge various control system improvements from dlc-controls branches.
T-Nicholls 60679fb
Resolve conflicts from merge from master.
T-Nicholls 8ad1fac
Full tests for the cothread control system.
T-Nicholls 6e4b224
Update pytac's import style to the pep8 standard.
T-Nicholls b739f74
Merge some miscellaneous changes.
T-Nicholls 9efb23f
Sort out some issues arising on travis build.
T-Nicholls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,7 @@ bin | |
| lib | ||
| include | ||
| share | ||
| venv | ||
| venv3 | ||
| venv* | ||
| pip-selfcheck.json | ||
|
|
||
| # build artifacts | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| API documentation | ||
| API Documentation | ||
| ================= | ||
|
|
||
| .. automodule:: pytac | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,137 @@ | ||
| import logging | ||
|
|
||
| from cothread.catools import caget, caput, ca_nothing | ||
|
|
||
| from pytac.cs import ControlSystem | ||
| from cothread.catools import caget, caput | ||
| from pytac.exceptions import ControlSystemException | ||
|
|
||
|
|
||
| class CothreadControlSystem(ControlSystem): | ||
| """ The EPICS control system. | ||
| """A control system using cothread to communicate with EPICS. N.B. this is | ||
| the default control system. | ||
|
|
||
| It is used to communicate over channel access with the hardware | ||
| in the ring. | ||
|
|
||
| **Methods:** | ||
| """ | ||
| def __init__(self): | ||
| pass | ||
| def __init__(self, timeout=1.0): | ||
| self._timeout = timeout | ||
|
|
||
| def get(self, pv): | ||
| """ Get the value of a given PV. | ||
| def get_single(self, pv, throw=True): | ||
| """Get the value of a given PV. | ||
|
|
||
| Args: | ||
| pv (string): The process variable given as a string. It can be a | ||
| readback or a setpoint PV. | ||
| throw (bool): if True, ControlSystemException will be raised on | ||
| failure | ||
|
|
||
| Returns: | ||
| object: the current value of the given PV. | ||
|
|
||
| Raises: | ||
| ControlSystemException: if it cannot connect to the specified PV. | ||
| """ | ||
| try: | ||
| return caget(pv, timeout=self._timeout, throw=True) | ||
| except ca_nothing: | ||
| error_msg = 'Cannot connect to {}.'.format(pv) | ||
| if throw: | ||
| raise ControlSystemException(error_msg) | ||
| else: | ||
| logging.warning(error_msg) | ||
| return None | ||
|
|
||
| def get_multiple(self, pvs, throw=True): | ||
| """Get the value for given PVs. | ||
|
|
||
| Args: | ||
| pvs (sequence): PVs to get values of. | ||
| throw (bool): if True, ControlSystemException will be raised on | ||
| failure. If False, None will be returned for any PV | ||
| for which the get fails. | ||
|
|
||
| Returns: | ||
| sequence: the current values of the PVs. | ||
|
|
||
| Raises: | ||
| ControlSystemException: if it cannot connect to one or more PVs. | ||
| """ | ||
| results = caget(pvs, timeout=self._timeout, throw=False) | ||
| return_values = [] | ||
| failures = [] | ||
| for result in results: | ||
| if isinstance(result, ca_nothing): | ||
| logging.warning('Cannot connect to {}.'.format(result.name)) | ||
| if throw: | ||
| failures.append(result) | ||
| else: | ||
| return_values.append(None) | ||
| else: | ||
| return_values.append(result) | ||
| if throw and failures: | ||
| error_msg = '{} caget calls failed.'.format(len(failures)) | ||
| raise ControlSystemException(error_msg) | ||
| return return_values | ||
|
|
||
| def set_single(self, pv, value, throw=True): | ||
| """Set the value of a given PV. | ||
|
|
||
| Args: | ||
| pv (string): PV to set the value of. | ||
| value (object): The value to set the PV to. | ||
| throw (bool): if True, ControlSystemException will be raised on | ||
| failure | ||
|
|
||
| Returns: | ||
| float: Represents the current value of the given PV. | ||
| bool: True for success, False for failure | ||
|
|
||
| Raises: | ||
| ControlSystemException: if it cannot connect to the specified PV. | ||
| """ | ||
| return caget(pv) | ||
| try: | ||
| caput(pv, value, timeout=self._timeout, throw=True) | ||
| return True | ||
| except ca_nothing: | ||
| error_msg = 'Cannot connect to {}.'.format(pv) | ||
| if throw: | ||
| raise ControlSystemException(error_msg) | ||
| else: | ||
| logging.warning(error_msg) | ||
| return False | ||
|
|
||
| def put(self, pv, value): | ||
| """ Set the value for a given. | ||
| def set_multiple(self, pvs, values, throw=True): | ||
| """Set the values for given PVs. | ||
|
|
||
| Args: | ||
| pv (string): The PV to set the value of. It must be a setpoint PV. | ||
| value (Number): The value to set the PV to. | ||
| pvs (sequence): PVs to set the values of. | ||
| values (sequence): values to set to the PVs. | ||
| throw (bool): if True, ControlSystemException will be raised on | ||
| failure. If False, a list of True and False values | ||
| will be returned corresponding to successes and | ||
| failures. | ||
|
|
||
| Returns: | ||
| list(bool): True for success, False for failure | ||
|
|
||
| Raises: | ||
| ValueError: if the lists of values and PVs are diffent lengths. | ||
| ControlSystemException: if it cannot connect to one or more PVs. | ||
| """ | ||
| caput(pv, value) | ||
| if len(pvs) != len(values): | ||
| raise ValueError("Please enter the same number of values as PVs.") | ||
| status = caput(pvs, values, timeout=self._timeout, throw=False) | ||
| return_values = [] | ||
| failures = [] | ||
| for stat in status: | ||
| if not stat.ok: | ||
| return_values.append(False) | ||
| failures.append(stat) | ||
| logging.warning('Cannot connect to {}.'.format(stat.name)) | ||
| else: | ||
| return_values.append(True) | ||
| if throw and failures: | ||
| error_msg = '{} caput calls failed.'.format(len(failures)) | ||
| raise ControlSystemException(error_msg) | ||
| return return_values | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.