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

Unable to set StringOut record values #40

Closed
AlexanderWells-diamond opened this issue Sep 30, 2021 · 2 comments · Fixed by #60
Closed

Unable to set StringOut record values #40

AlexanderWells-diamond opened this issue Sep 30, 2021 · 2 comments · Fixed by #60
Assignees

Comments

@AlexanderWells-diamond
Copy link
Collaborator

I seem to be unable to set the value of a StringOut record programmatically by calling .set(). This program demonstrates the issue:

# Import the basic framework components.
from softioc import softioc, builder, asyncio_dispatcher

# Create an asyncio dispatcher, the event loop is now running
dispatcher = asyncio_dispatcher.AsyncioDispatcher()

# Set the record prefix
builder.SetDeviceName("MY-DEVICE-PREFIX")

# Create some records
strout = builder.stringOut("FLIBBLE", initial_value="ABC")

# Boilerplate get the IOC started
builder.LoadDatabase()
softioc.iocInit(dispatcher)

strout.set("DEF")

# Finally leave the IOC running with an interactive shell.
softioc.interactive_ioc(globals())

The strout.set() line generates this exception:

 File "/home/eyh46967/dev/pythonSoftIoc/docs/examples/trial_stringout.py", line 17, in <module>
    strout.set("DEF")
  File "/home/eyh46967/dev/pythonSoftIoc/softioc/device.py", line 212, in set
    datatype, length, data, array = self.value_to_dbr(value)
  File "/home/eyh46967/dev/pythonSoftIoc/softioc/device.py", line 186, in value_to_dbr
    dbrtype = self.NumpyCharCodeToDbr[value.dtype.char]
KeyError: 'U'

The device.py code appears to be trying to convert the string value into a numpy array on line 173:

value = numpy.require(value, requirements = 'C')

Examining this array gives a value.dtype.char of U, which is unknown to the NumpyCharCodeToDbr mapping dictionary.

@Araneidae
Copy link
Member

Ooh, another interesting one. This is closely related to #39 and will have to be solved together with that.

@AlexanderWells-diamond
Copy link
Collaborator Author

We need to create a single function to sanitise all inputs from all possible places (initialising initial values for in & out, setting values for in&out, and waveforms) which can handle all possible Python values and convert it to a valid EPICS value.

Ensure the validation happens before iocInit(), so it'll throw an error if something goes wrong.

Whenever we pass a value we want to sanitise it to its canonical form - numpy aray for waveforms, or python string, or underlying value for numeric types, and then return the canonicalised form.

This work will involve device.py, getting and setting the values in some consistent way.

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

Successfully merging a pull request may close this issue.

2 participants