Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Strings as values for WaveformOut has multiple issues #39

Closed
AlexanderWells-diamond opened this issue Sep 17, 2021 · 1 comment · Fixed by #60
Closed

Setting Strings as values for WaveformOut has multiple issues #39

AlexanderWells-diamond opened this issue Sep 17, 2021 · 1 comment · Fixed by #60
Assignees
Labels

Comments

@AlexanderWells-diamond
Copy link
Collaborator

Attempting to create a WaveformOut record with a String value has multiple issues regarding how PythonSoftIOC attempts to convert it into a numpy array. The failure modes are different depending on how you try and set the value.

Using initial_value="Some string" and FTVL="CHAR" you get this exception:

len() of unsized object
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/softioc/builder.py", line 167, in _waveform
    length = len(value)
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/softioc/builder.py", line 192, in WaveformOut
    _waveform(value, fields)
  File "/home/eyh46967/dev/PandABlocks-client/pandablocks/ioc.py", line 618, in _waveform_rec
    **kwargs,
  File "/home/eyh46967/dev/PandABlocks-client/pandablocks/ioc.py", line 580, in __init__
    DESC="Format string used for file naming",
  File "/home/eyh46967/dev/PandABlocks-client/pandablocks/ioc.py", line 1723, in create_block_records
    _HDF5RecordController(self._client)

Creating the record and immediately doing .set("some string") on the record seems to be ignored entirely with no exception but also no change to the record's value.

Creating the record and immediately doing .set("%abc") gives the following exception:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 232, in 'calling callback function'
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/softioc/device_core.py", line 191, in _init_record
    return self.init_record(record)
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/softioc/device.py", line 310, in init_record
    return self.__super.init_record(record)
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/softioc/device.py", line 125, in init_record
    self._write_value(record, self._value)
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/softioc/device.py", line 321, in _write_value
    value = numpy.require(value, dtype=self.dtype)
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/numpy/core/_asarray.py", line 380, in require
    return asanyarray(a, dtype=dtype)
  File "/scratch/eyh46967/pipenv/PandABlocks-client-bVxlyL_p/lib/python3.7/site-packages/numpy/core/_asarray.py", line 171, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)
ValueError: invalid literal for int() with base 10: '%abc'

From observation it also appears that doing a delayed .set() after IOC initialisation will result in similar errors, but again in a different place.

It should be noted that WaveformIn records have some attempts at handling this issue - device.py L353 has value = numpy.fromstring(value + "\0", dtype="uint8") which will work, but emits this warning:
_main__:1: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead

The workaround is to create the record and do .set(np.frombuffer("%s/%s_%d.h5".encode() + b"\0", dtype=np.uint8)) or similar.

Note that I cannot provide the value during record creation using either value or initial_value, as I need to set a maximum length of the record which is bigger than the length of the initial value. This is covered in issue #37

@AlexanderWells-diamond
Copy link
Collaborator Author

AlexanderWells-diamond commented Dec 1, 2021

This issue is mostly fixed by PR #60 , however the .set("%abc") does still have an issue - the returned array is of dtype=float32, which is incorrect. So that's the last (known) problem to cover in this issue.

EDIT: This last case is also fixed in PR#60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants