Hi:
Hi Iain,
I wish to save some Process Variables to a CSV file, but I
cannot figure out the code to retrieve the values from the PVs into
Python.
I think the problem here is that createPV doesn't create the PV
immediately. It takes some time to happen (I guess due to inter-thread
synchronization in CS-Studio). My understanding of the documentation is
that the actual create happens at a rate of 50 Hz (queue run or
something similar in the receiving thread). This means waiting a little
should fix your problem:
pv = PVUtil.createPV(widget.getPV)
time.sleep(0.1)
value = PVUtil.getDouble(pv)
The PV needs to connect. If you get the value right away, you’ll receive a null because the PV has not connected and not received the initial value, yet.
Waiting via a delay will often be sufficient, but
a) You should not wait within the script, i.e. on the UI thread, because otherwise you’ll next ask:
Why does all of CSS freeze while my script is sleeping?
b) Sometimes you need to wait 3 seconds instead of 0.1.
Better would be to add a listener to the PV which gets notified as values arrive.
Overall, performing logic like data acquisition should not be handled in the user interface.
The user interface can start, stop, monitor the data accusation, but data acquisition needs to be performed by some service.
You tell it to take data for some time, it uses data storage clients to write that to files.
-Kay
|