Skip to content

Commit b3bf397

Browse files
committed
Rework the handling of default values for in and out records
This commit addresses both github issues #81 and #67. The arguments to the a and long record builder functions (`aIn`, `aOut`, `longIn`, `longOut`) are brought more into line with the arguments as used in the epics_device module. This means that extra unnamed arguments can be used to specify EGU and PREC (where appropriate), and for out records the DRV limits take precedence. As a side effect, the implementation of this is made closer to that in https://github.com/dls-controls/epics_device/
1 parent 0ace830 commit b3bf397

File tree

3 files changed

+59
-36
lines changed

3 files changed

+59
-36
lines changed

docs/reference/api.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,20 @@ Test Facilities`_ documentation for more details of each function.
229229
For all of these functions any EPICS database field can be assigned a value by
230230
passing it as a keyword argument for the corresponding field name (in upper
231231
case) or by assigning to the corresponding field of the returned record object.
232-
Thus the ``**fields`` argument in all of the definitions below refers to both the
233-
optional keyword arguments listed above and record field names.
232+
Thus the ``**fields`` argument in all of the definitions below refers to both
233+
the optional keyword arguments listed above and record field names.
234234

235235
All functions return a wrapped `ProcessDeviceSupportIn` or
236236
`ProcessDeviceSupportOut` instance.
237237

238238
.. function::
239-
aIn(name, LOPR=None, HOPR=None, **fields)
240-
aOut(name, LOPR=None, HOPR=None, **fields)
239+
aIn(name, LOPR=None, HOPR=None, EGU=None, PREC=None, **fields)
240+
aOut(name, DRVL=None, DRVH=None, EGU=None, PREC=None, **fields):
241241
242-
Create ``ai`` and ``ao`` records. The lower and upper limits for the
243-
record can be specified, and if specified these will also be used to set the
244-
``EGUL`` and ``EGUF`` fields.
242+
Create ``ai`` and ``ao`` records. The lower and upper limits for the record
243+
can be specified. For ``ao`` records the ``LOPR`` and ``HOPR`` fields will
244+
be set by default to the values of the ``DRVL`` and ``DRVH`` fields
245+
respectively.
245246

246247
.. function::
247248
boolIn(name, ZNAM=None, ONAM=None, **fields)
@@ -252,9 +253,13 @@ All functions return a wrapped `ProcessDeviceSupportIn` or
252253

253254
.. function::
254255
longIn(name, LOPR=None, HOPR=None, EGU=None, **fields)
255-
longOut(name, DRVL=None, DRVH=None, EGU=None, **fields)
256+
longOut(name, DRVL=None, DRVH=None, EGU=None, **fields):
256257
257258
Create ``longin`` and ``longout`` records with specified limits and units.
259+
The lower and upper display limits for the record can be specified. For
260+
``longout`` records the ``LOPR`` and ``HOPR`` fields will be set by default
261+
to the values of the ``DRVL`` and ``DRVH`` fields respectively.
262+
258263

259264
.. function::
260265
stringIn(name, **fields)

softioc/builder.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,52 @@
1818
# The SCAN field for all input records defaults to I/O Intr.
1919

2020

21-
def _in_record(record, name, **fields):
22-
'''For input records we provide some automatic extra features: scanning,
23-
initialisation as appropriate, and blocking puts from outside the IOC.'''
24-
21+
def _set_in_defaults(fields):
2522
fields.setdefault('SCAN', 'I/O Intr')
26-
if 'initial_value' in fields:
27-
fields.setdefault('PINI', 'YES')
23+
fields.setdefault('PINI', 'YES')
2824
fields.setdefault('DISP', 1)
29-
return getattr(PythonDevice, record)(name, **fields)
25+
26+
def _set_out_defaults(fields):
27+
fields.setdefault('OMSL', 'supervisory')
28+
29+
# For longout and ao we want DRV{L,H} to match {L,H}OPR by default
30+
def _set_scalar_out_defaults(fields, DRVL, DRVH):
31+
fields['DRVL'] = DRVL
32+
fields['DRVH'] = DRVH
33+
fields.setdefault('LOPR', DRVL)
34+
fields.setdefault('HOPR', DRVH)
3035

3136

32-
def aIn(name, LOPR=None, HOPR=None, **fields):
33-
return _in_record(
34-
'ai', name, LOPR = LOPR, HOPR = HOPR, **fields)
37+
def aIn(name, LOPR=None, HOPR=None, EGU=None, PREC=None, **fields):
38+
_set_in_defaults(fields)
39+
return PythonDevice.ai(
40+
name, LOPR = LOPR, HOPR = HOPR, EGU = EGU, PREC = PREC, **fields)
3541

36-
def aOut(name, LOPR=None, HOPR=None, **fields):
37-
fields.setdefault('DRVL', LOPR)
38-
fields.setdefault('DRVH', HOPR)
39-
return PythonDevice.ao(
40-
name, LOPR = LOPR, HOPR = HOPR, **fields)
42+
def aOut(name, DRVL=None, DRVH=None, EGU=None, PREC=None, **fields):
43+
_set_out_defaults(fields)
44+
_set_scalar_out_defaults(fields, DRVL, DRVH)
45+
return PythonDevice.ao(name, EGU = EGU, PREC = PREC, **fields)
4146

4247

4348
def boolIn(name, ZNAM=None, ONAM=None, **fields):
44-
return _in_record('bi', name, ZNAM = ZNAM, ONAM = ONAM, **fields)
49+
_set_in_defaults(fields)
50+
return PythonDevice.bi(name, ZNAM = ZNAM, ONAM = ONAM, **fields)
4551

4652
def boolOut(name, ZNAM=None, ONAM=None, **fields):
47-
return PythonDevice.bo(
48-
name, OMSL = 'supervisory', ZNAM = ZNAM, ONAM = ONAM, **fields)
53+
_set_out_defaults(fields)
54+
return PythonDevice.bo(name, ZNAM = ZNAM, ONAM = ONAM, **fields)
4955

5056

5157
def longIn(name, LOPR=None, HOPR=None, EGU=None, **fields):
58+
_set_in_defaults(fields)
5259
fields.setdefault('MDEL', -1)
53-
return _in_record(
54-
'longin', name, EGU = EGU, LOPR = LOPR, HOPR = HOPR, **fields)
60+
return PythonDevice.longin(
61+
name, LOPR = LOPR, HOPR = HOPR, EGU = EGU, **fields)
5562

5663
def longOut(name, DRVL=None, DRVH=None, EGU=None, **fields):
57-
return PythonDevice.longout(
58-
name, OMSL = 'supervisory', DRVL = DRVL, DRVH = DRVH, EGU = EGU,
59-
**fields)
64+
_set_out_defaults(fields)
65+
_set_scalar_out_defaults(fields, DRVL, DRVH)
66+
return PythonDevice.longout(name, EGU = EGU, **fields)
6067

6168

6269
# Field name prefixes for mbbi/mbbo records.
@@ -92,17 +99,21 @@ def process_value(prefix, value, option, severity=None):
9299

93100
def mbbIn(name, *options, **fields):
94101
_process_mbb_values(options, fields)
95-
return _in_record('mbbi', name, **fields)
102+
_set_in_defaults(fields)
103+
return PythonDevice.mbbi(name, **fields)
96104

97105
def mbbOut(name, *options, **fields):
98106
_process_mbb_values(options, fields)
99-
return PythonDevice.mbbo(name, OMSL = 'supervisory', **fields)
107+
_set_out_defaults(fields)
108+
return PythonDevice.mbbo(name, **fields)
100109

101110

102111
def stringIn(name, **fields):
103-
return _in_record('stringin', name, **fields)
112+
_set_in_defaults(fields)
113+
return PythonDevice.stringin(name, **fields)
104114

105115
def stringOut(name, **fields):
116+
_set_out_defaults(fields)
106117
return PythonDevice.stringout(name, **fields)
107118

108119
def Action(name, **fields):
@@ -204,7 +215,8 @@ def _waveform(value, fields):
204215

205216
def Waveform(name, *value, **fields):
206217
_waveform(value, fields)
207-
return _in_record('waveform', name, **fields)
218+
_set_in_defaults(fields)
219+
return PythonDevice.waveform(name, **fields)
208220

209221
WaveformIn = Waveform
210222

@@ -232,7 +244,8 @@ def _long_string(fields):
232244

233245
def longStringIn(name, **fields):
234246
_long_string(fields)
235-
return _in_record('long_stringin', name, **fields)
247+
_set_in_defaults(fields)
248+
return PythonDevice.long_stringin(name, **fields)
236249

237250
def longStringOut(name, **fields):
238251
_long_string(fields)

tests/expected_records.db

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ record(ai, "TS-DI-TEST-01:AI")
1010
record(ao, "TS-DI-TEST-01:AO")
1111
{
1212
field(DTYP, "Python")
13+
field(OMSL, "supervisory")
1314
field(OUT, "@TS-DI-TEST-01:AO")
1415
}
1516

@@ -107,13 +108,16 @@ record(longout, "TS-DI-TEST-01:SINN")
107108
field(DRVH, "1024")
108109
field(DRVL, "0")
109110
field(DTYP, "Python")
111+
field(HOPR, "1024")
112+
field(LOPR, "0")
110113
field(OMSL, "supervisory")
111114
field(OUT, "@TS-DI-TEST-01:SINN")
112115
}
113116

114117
record(ao, "TS-DI-TEST-01:SINP")
115118
{
116119
field(DTYP, "Python")
120+
field(OMSL, "supervisory")
117121
field(OUT, "@TS-DI-TEST-01:SINP")
118122
}
119123

@@ -129,6 +133,7 @@ record(stringin, "TS-DI-TEST-01:STRINGIN")
129133
record(stringout, "TS-DI-TEST-01:STRINGOUT")
130134
{
131135
field(DTYP, "Python")
136+
field(OMSL, "supervisory")
132137
field(OUT, "@TS-DI-TEST-01:STRINGOUT")
133138
}
134139

0 commit comments

Comments
 (0)