DiamondLightSource / pythonSoftIOC

Embed an EPICS IOC in a Python process
Apache License 2.0
34 stars 9 forks source link

boolOut records require ZNAM and ONAM if initial_value is set #44

Closed AlexanderWells-diamond closed 2 years ago

AlexanderWells-diamond commented 3 years ago

If you create a boolOut record, specify an initial_value, and do NOT specify ZNAM and ONAM explicitly the resultant record has no value. I'm not sure if this is just unclear documentation or an actual bug.

# 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
bo1 = builder.boolOut('BO1', initial_value=1)
bo2 = builder.boolOut('BO2', ZNAM=0, ONAM=1, initial_value=1)

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

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

And on the command line we see BO1 has no value, while BO2 does:

[...]$ caget MY-DEVICE-PREFIX:BO1
MY-DEVICE-PREFIX:BO1           
[...]$ caget MY-DEVICE-PREFIX:BO2
MY-DEVICE-PREFIX:BO2           1
thomascobb commented 3 years ago

partly associated with #43

Araneidae commented 2 years ago

A couple of notes on this.

It's a little misleading to write bo2 = builder.boolOut('BO2', ZNAM=0, ONAM=1, initial_value=1), as both ZNAM and ONAM will be converted to strings. Once we realise this, then we can rewrite the definitions of bo1 and bo2 to fill in the defaults as:

bo1 = builder.boolOut('BO1', ZNAM='', ONAM='', initial_value=1)
bo2 = builder.boolOut('BO2', ZNAM='0', ONAM='1', initial_value=1)

In the light of this, the observed behaviour is, unfortunately, normal behaviour as expected from EPICS.