@@ -134,6 +134,19 @@ def Action(name, **fields):
134
134
}
135
135
136
136
137
+ def _get_length (fields , default = None ):
138
+ '''Helper function for getting 'length' or 'NELM' from arguments'''
139
+
140
+ if 'length' in fields :
141
+ assert 'NELM' not in fields , 'Cannot specify NELM and length together'
142
+ return fields .pop ('length' )
143
+ elif 'NELM' in fields :
144
+ return fields .pop ('NELM' )
145
+ else :
146
+ assert default is not None , 'Must specify waveform length'
147
+ return default
148
+
149
+
137
150
def _waveform (value , fields ):
138
151
'''Helper routine for waveform construction. If a value is given it is
139
152
interpreted as an initial value and used to configure length and datatype
@@ -165,7 +178,7 @@ def _waveform(value, fields):
165
178
# If a value is specified it should be the *only* non keyword argument.
166
179
value , = value
167
180
initial_value = device ._require_waveform (value , datatype )
168
- length = fields . pop ( 'length' , len (initial_value ))
181
+ length = _get_length ( fields , len (initial_value ))
169
182
170
183
# Special case for [u]int64: if the initial value comes in as 64 bit
171
184
# integers we cannot represent that, so recast it as [u]int32
@@ -176,7 +189,7 @@ def _waveform(value, fields):
176
189
initial_value = numpy .require (initial_value , numpy .uint32 )
177
190
else :
178
191
initial_value = numpy .array ([], dtype = datatype )
179
- length = fields . pop ( 'length' )
192
+ length = _get_length ( fields )
180
193
datatype = initial_value .dtype
181
194
182
195
assert length > 0 , 'Array cannot be of zero length'
0 commit comments