-
Notifications
You must be signed in to change notification settings - Fork 9
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
Enable setting alarm status of Out records #157
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ff3460
Enable setting alarm status of Out records
AlexanderWells-diamond 5f46132
Change default alarm values
AlexanderWells-diamond d351bae
Add note that NO_ALARM is valid for status too
AlexanderWells-diamond 5cdc614
Remove unnecessary delayed processing of value
AlexanderWells-diamond 4388c69
Clean up code after review
AlexanderWells-diamond 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 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 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 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 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 |
---|---|---|
|
@@ -137,7 +137,7 @@ def _process(self, record): | |
return self._epics_rc_ | ||
|
||
def set(self, value, | ||
severity=alarm.NO_ALARM, alarm=alarm.UDF_ALARM, timestamp=None): | ||
severity=alarm.NO_ALARM, alarm=alarm.NO_ALARM, timestamp=None): | ||
'''Updates the stored value and triggers an update. The alarm | ||
severity and timestamp can also be specified if appropriate.''' | ||
value = self._value_to_epics(value) | ||
|
@@ -176,9 +176,17 @@ def __init__(self, name, **kargs): | |
self.__enable_write = True | ||
|
||
if 'initial_value' in kargs: | ||
self._value = self._value_to_epics(kargs.pop('initial_value')) | ||
value = self._value_to_epics(kargs.pop('initial_value')) | ||
initial_severity = alarm.NO_ALARM | ||
initial_status = alarm.NO_ALARM | ||
else: | ||
self._value = None | ||
value = self._default_value() | ||
# To maintain backwards compatibility, if there is no initial value | ||
# we mark the record as invalid | ||
initial_severity = alarm.INVALID_ALARM | ||
initial_status = alarm.UDF_ALARM | ||
|
||
self._value = (value, initial_severity, initial_status) | ||
|
||
self._blocking = kargs.pop('blocking', blocking) | ||
if self._blocking: | ||
|
@@ -190,18 +198,17 @@ def init_record(self, record): | |
'''Special record initialisation for out records only: implements | ||
special record initialisation if an initial value has been specified, | ||
allowing out records to have a sensible initial value.''' | ||
if self._value is None: | ||
# Cannot set in __init__ (like we do for In records), as we want | ||
# the record alarm status to be set if no value was provided | ||
# Probably related to PythonSoftIOC issue #53 | ||
self._value = self._default_value() | ||
else: | ||
self._write_value(record, self._value) | ||
if 'MLST' in self._fields_: | ||
record.MLST = self._value | ||
record.TIME = time.time() | ||
record.UDF = 0 | ||
recGblResetAlarms(record) | ||
|
||
self._write_value(record, self._value[0]) | ||
if 'MLST' in self._fields_: | ||
record.MLST = self._value[0] | ||
|
||
record.TIME = time.time() | ||
|
||
record.UDF = 0 | ||
record.NSEV = self._value[1] | ||
record.NSTA = self._value[2] | ||
recGblResetAlarms(record) | ||
return self._epics_rc_ | ||
|
||
def __completion(self, record): | ||
|
@@ -216,9 +223,14 @@ def _process(self, record): | |
if record.PACT: | ||
return EPICS_OK | ||
|
||
# Ignore memoized value, retrieve it from the VAL field directly later | ||
_, severity, alarm = self._value | ||
|
||
self.process_severity(record, severity, alarm) | ||
|
||
value = self._read_value(record) | ||
if not self.__always_update and \ | ||
self._compare_values(value, self._value): | ||
self._compare_values(value, self._value[0]): | ||
# If the value isn't making a change then don't do anything. | ||
return EPICS_OK | ||
|
||
|
@@ -227,11 +239,11 @@ def _process(self, record): | |
not self.__validate(self, python_value): | ||
# Asynchronous validation rejects value, so restore the last good | ||
# value. | ||
self._write_value(record, self._value) | ||
self._write_value(record, self._value[0]) | ||
return EPICS_ERROR | ||
else: | ||
# Value is good. Hang onto it, let users know the value has changed | ||
self._value = value | ||
self._value = (value, severity, alarm) | ||
record.UDF = 0 | ||
if self.__on_update and self.__enable_write: | ||
record.PACT = self._blocking | ||
|
@@ -248,15 +260,26 @@ def _value_to_dbr(self, value): | |
return self._dbf_type_, 1, addressof(value), value | ||
|
||
|
||
def set(self, value, process=True): | ||
def set_alarm(self, severity, alarm): | ||
'''Updates the alarm status without changing the stored value. An | ||
update is triggered, and a timestamp can optionally be specified.''' | ||
self._value = (self._value[0], severity, alarm) | ||
self.set( | ||
self.get(), | ||
severity=severity, | ||
alarm=alarm) | ||
|
||
|
||
def set(self, value, process=True, | ||
severity=alarm.NO_ALARM, alarm=alarm.NO_ALARM): | ||
'''Special routine to set the value directly.''' | ||
value = self._value_to_epics(value) | ||
try: | ||
_record = self._record | ||
except AttributeError: | ||
# Record not initialised yet. Record the value for when | ||
# Record not initialised yet. Record data for when | ||
# initialisation occurs | ||
self._value = value | ||
self._value = (value, severity, alarm) | ||
else: | ||
# The array parameter is used to keep the raw pointer alive | ||
dbf_code, length, data, array = self._value_to_dbr(value) | ||
|
@@ -265,11 +288,11 @@ def set(self, value, process=True): | |
self.__enable_write = True | ||
|
||
def get(self): | ||
if self._value is None: | ||
if self._value[0] is None: | ||
# Before startup complete if no value set return default value | ||
value = self._default_value() | ||
else: | ||
value = self._value | ||
value = self._value[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can simplify this, return self._epics_to_value(self._value[0]) |
||
return self._epics_to_value(value) | ||
|
||
|
||
|
This file contains 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.
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.
Put reading
self._value
andself._read_value(record)
on adjacent lines, then it's much clearer that they're working together and you might not need the comment!