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

Waveforms with empty array initial values do not update as expected #55

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

Waveforms with empty array initial values do not update as expected #55

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

Comments

@AlexanderWells-diamond
Copy link
Collaborator

When using a WaveformOut record and doing .set() and .get(), the behaviour is not as expected when the initial_value is an empty numpy array:

# Import the basic framework components.
from softioc import softioc, builder, asyncio_dispatcher
import numpy
# Create an asyncio dispatcher, the event loop is now running
dispatcher = asyncio_dispatcher.AsyncioDispatcher()

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

# Create some records
wo = builder.WaveformOut("TEST", initial_value=numpy.array([]))

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

print(wo.get())
wo.set(numpy.array([10]))
print(wo.get())

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

This program prints:

...
iocRun: All initialization complete
[]
[]

If you change the initial_value to numpy.array([1]) then the program prints out the expected results:

...
iocRun: All initialization complete
[1]
[10]

Apologies if this is a duplicate of an existing issue, but it certainly is a novel symptom.

@AlexanderWells-diamond
Copy link
Collaborator Author

This is likely to be an issue in ProcessDeviceSupportOut._process. The check against empty arrays is not working as intended - passing a numpy.array(10.) and a numpy.array([]) passes the check and returns EPICS_OK.

The probable fix for this is to extend the if check to do something like this:

if value.shape == self._value.shape and (value == self._value).all() and not self.__always_update:

This needs testing and tweaking for all Out record types, as this'll obviously fail for any non-array values.

@Araneidae
Copy link
Collaborator

Ah. The problem is the maximum array length is now zero!

There are two places where an error could be reported here:

  1. A zero length waveform is invalid
  2. We should probably raise an error when truncating writes to arrays

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