@@ -134,6 +134,19 @@ def Action(name, **fields):
134134}
135135
136136
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+
137150def _waveform (value , fields ):
138151 '''Helper routine for waveform construction. If a value is given it is
139152 interpreted as an initial value and used to configure length and datatype
@@ -165,7 +178,7 @@ def _waveform(value, fields):
165178 # If a value is specified it should be the *only* non keyword argument.
166179 value , = value
167180 initial_value = device ._require_waveform (value , datatype )
168- length = fields . pop ( 'length' , len (initial_value ))
181+ length = _get_length ( fields , len (initial_value ))
169182
170183 # Special case for [u]int64: if the initial value comes in as 64 bit
171184 # integers we cannot represent that, so recast it as [u]int32
@@ -176,7 +189,7 @@ def _waveform(value, fields):
176189 initial_value = numpy .require (initial_value , numpy .uint32 )
177190 else :
178191 initial_value = numpy .array ([], dtype = datatype )
179- length = fields . pop ( 'length' )
192+ length = _get_length ( fields )
180193 datatype = initial_value .dtype
181194
182195 assert length > 0 , 'Array cannot be of zero length'
0 commit comments