diff --git a/docs/reference/api.rst b/docs/reference/api.rst index e40ef2cc..7efab9e0 100644 --- a/docs/reference/api.rst +++ b/docs/reference/api.rst @@ -273,8 +273,12 @@ All functions return a wrapped `ProcessDeviceSupportIn` or status = mbbIn('STATUS', 'OK', - ('FAILING', "MINOR"), - ('FAILED', "MAJOR")) + ('FAILING', 'MINOR'), + ('FAILED', 'MAJOR'), + ('NOT CONNECTED', 'INVALID')) + + Severities can also be assigned using the `softioc.alarm` numerical + severities if preferred. Numerical values are assigned to options sequentially from 0 to 15 and cannot be overridden. diff --git a/softioc/builder.py b/softioc/builder.py index 3e639d21..8c6272e1 100644 --- a/softioc/builder.py +++ b/softioc/builder.py @@ -62,6 +62,9 @@ def longOut(name, DRVL=None, DRVH=None, EGU=None, **fields): 'ZR', 'ON', 'TW', 'TH', 'FR', 'FV', 'SX', 'SV', # 0-7 'EI', 'NI', 'TE', 'EL', 'TV', 'TT', 'FT', 'FF'] # 8-15 +# All the severity strings supported by SV +_severityStrings = ["NO_ALARM", "MINOR", "MAJOR", "INVALID"] + # Converts a list of (option [,severity]) values or tuples into field settings # suitable for mbbi and mbbo records. def _process_mbb_values(options, fields): @@ -69,6 +72,9 @@ def process_value(prefix, value, option, severity=None): fields[prefix + 'ST'] = option fields[prefix + 'VL'] = value if severity: + if isinstance(severity, int): + # Map alarm.MINOR_ALARM -> "MINOR" + severity = _severityStrings[severity] fields[prefix + 'SV'] = severity # zip() silently ignores extra values in options, so explicitly check length assert len(options) <= 16, "May not specify more than 16 enum values" diff --git a/tests/expected_records.db b/tests/expected_records.db index 290c5c82..61d383db 100644 --- a/tests/expected_records.db +++ b/tests/expected_records.db @@ -1,8 +1,3 @@ -# This file was automatically generated on Fri 13 Aug 2021 16:49:03 BST. -# -# *** Please do not edit this file: edit the source file instead. *** -# - record(ai, "TS-DI-TEST-01:AI") { field(DTYP, "Python") @@ -73,6 +68,7 @@ record(mbbi, "TS-DI-TEST-01:MBBI") field(TWSV, "MINOR") field(TWVL, "2") field(ZRST, "One") + field(ZRSV, "MAJOR") field(ZRVL, "0") } diff --git a/tests/sim_records.py b/tests/sim_records.py index 7bcd9861..3009e356 100644 --- a/tests/sim_records.py +++ b/tests/sim_records.py @@ -4,7 +4,7 @@ from epicsdbbuilder import GetRecordNames, WriteRecords -from softioc import softioc +from softioc import softioc, alarm from softioc.builder import * import numpy @@ -26,7 +26,9 @@ def on_update_name(value, name): t_boolin = boolIn('BOOLIN', 'True', 'False', initial_value=False) t_longin = longIn('LONGIN', initial_value=33) t_stringin = stringIn('STRINGIN', initial_value="Testing string") -t_mbbi = mbbIn('MBBI', 'One', 'Two', ('Three', "MINOR"), initial_value=2) +t_mbbi = mbbIn( + 'MBBI', ('One', alarm.MAJOR_ALARM), 'Two', ('Three', "MINOR"), + initial_value=2) t_ao = aOut('AO', initial_value=12.45, on_update_name=on_update_name) t_boolout = boolOut( diff --git a/tests/test_records.py b/tests/test_records.py index 2d50973b..756a44ec 100644 --- a/tests/test_records.py +++ b/tests/test_records.py @@ -10,7 +10,7 @@ def test_records(tmp_path): path = str(tmp_path / "records.db") builder.WriteRecords(path) expected = os.path.join(os.path.dirname(__file__), "expected_records.db") - assert open(path).readlines()[4:] == open(expected).readlines()[4:] + assert open(path).readlines()[5:] == open(expected).readlines() def test_enum_length_restriction(): with pytest.raises(AssertionError):