Open kurup opened 3 weeks ago
I recently had a similar issue when initialising an NTEnum struct (see this PR: https://github.com/epics-base/p4p/pull/154). I think the ideal fix is to make it as similar to the NRScalar wrap() code as possible, something like this:
if isinstance(value, Value):
V = value
elif isinstance(value, ntwrappercommon):
kws.setdefault('timestamp', value.timestamp)
V = value.raw
elif isinstance(value, dict):
V = self.Value(self.type, value)
else:
# index or string (use NTEnum.assign() here, different from NTScalar)
self.assign(V, value)
self._annotate(V, **kws)
However, the code above would break the existing functionality of setting index/choices like this initial={'index': N, 'choices': [...]}
.
I've been looking at implementing NTEnum PVs using p4p and I've run into an issue with setting the
alarm
anddescriptor
parts of the struct failing when using a put operation from a client. It looks like this has not been implemented yet in the wrap method and only setting the index or choices is supported. The following change to the wrap method fixes this:It'd be good to include this in master if you're happy with this fix.