Skip to content

Commit 7d852a0

Browse files
Allow arrays of strings to be used with Waveforms
Note the tests fail, largely due to now numpy defaults to a floating point dtype, which we cannot coerce into an array of strings. Also TODOs need completion...
1 parent 565bca1 commit 7d852a0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

softioc/builder.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def Action(name, **fields):
148148
'uint32': 'ULONG',
149149
'float32': 'FLOAT',
150150
'float64': 'DOUBLE',
151+
'bytes32': 'STRING',
152+
'bytes320': 'STRING',
151153
}
152154

153155
# Coverts FTVL string to numpy type
@@ -160,6 +162,7 @@ def Action(name, **fields):
160162
'ULONG': 'uint32',
161163
'FLOAT': 'float32',
162164
'DOUBLE': 'float64',
165+
'STRING': 'S40',
163166
}
164167

165168

@@ -211,11 +214,15 @@ def _waveform(value, fields):
211214

212215
# Special case for [u]int64: if the initial value comes in as 64 bit
213216
# integers we cannot represent that, so recast it as [u]int32
217+
# Special case for array of strings to correctly identify each element
218+
# of the array as a string type.
214219
if datatype is None:
215220
if initial_value.dtype == numpy.int64:
216221
initial_value = numpy.require(initial_value, numpy.int32)
217222
elif initial_value.dtype == numpy.uint64:
218223
initial_value = numpy.require(initial_value, numpy.uint32)
224+
elif initial_value.dtype.char == "S":
225+
initial_value = numpy.require(initial_value, numpy.dtype("S40"))
219226
else:
220227
initial_value = numpy.array([], dtype = datatype)
221228
length = _get_length(fields)

softioc/device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def _read_value(self, record):
391391
return result
392392

393393
def _write_value(self, record, value):
394+
value = _require_waveform(value, self._dtype)
394395
nord = len(value)
395396
memmove(
396397
record.BPTR, value.ctypes.data_as(c_void_p),

tests/test_record_values.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ def record_values_names(fixture_value):
189189
),
190190
numpy.ndarray,
191191
),
192+
(
193+
"wIn_byte_string_array",
194+
builder.WaveformIn,
195+
[b"AB", b"CD", b"EF"],
196+
numpy.array(
197+
[b"AB", b"CD", b"EF"], dtype=numpy.dtype("|S40")
198+
),
199+
numpy.ndarray,
200+
),
201+
(
202+
"wOut_byte_string_array",
203+
builder.WaveformOut,
204+
[b"AB", b"CD", b"EF"],
205+
numpy.array(
206+
[b"AB", b"CD", b"EF"], dtype=numpy.dtype("|S40")
207+
),
208+
numpy.ndarray,
209+
),
192210
(
193211
"longStringIn_str",
194212
builder.longStringIn,

0 commit comments

Comments
 (0)