I just wrote some python code (caputRecorder) that accidentally does the kinds things you would have to do to implement a python daemon that does the following:
1) monitor an EPICS PV, which I'll call READ
2) read the sensor whenever READ==1
3) write the sensor value to an EPICS PV, which I'll call VALUE
4) write 0 to READ.
I would implement the READ PV with a "busy" record, so that whomever writes 1 to it can find out when the read operation is done by waiting for a completion callback.
I would use PyEpics' camonitor() function to monitor READ, specifying a callback function I'll call monRead()
I would have monRead() put the READ value on a message quere if it's 1
I would have a separate thread read from that message queue, do the actual sensor read, write to VALUE, and write 0 to READ
The database might look like this:
record(busy, "READ") {
field(ZNAM, "Done")
field(ONAM, "Read")
}
record(ao, "VALUE") {
}
The python code might look like this:
import threading
import epics
import Queue
msgQueue = Queue.Queue(maxsize=10)
def reader():
value = msgQueue.get()
currValue = yourFunction()
epics.caput("VALUE", currValue)
epics.caput("READ", 0)
readThread = threading.Thread(target=reader)
readThread.daemon = True
readThread.start()
def monRead(pvname, value, char_value, **kwd):
if (value):
msgQueue.put(value)
epics.camonitor("READ",callback=monRead)
Tim Mooney ([email protected]) (630)252-5417
Software Services Group (www.aps.anl.gov)
Advanced Photon Source, Argonne National Lab
________________________________________
From: [email protected] [[email protected]] on behalf of Christian Pauly [[email protected]]
Sent: Thursday, February 05, 2015 10:58 AM
To: [email protected]
Subject: Fetching return value from external program call in StreamDevice
Hi
I want to read out a little pressure sensor, for which i have already a
small python script which reads the sensor (via i2c bus) and prints the
sensor value to the terminal. Alternatively, i could also give the
sensor value as return value upon program exit.
Now i want to read this sensor inside an EPICS IOC.
Is it possible, to use StreamDevice for this, by calling the external
script / program and evaluating the return value ?
Maybe using the "exec" statement in the protocol file ?
Reading the sensor takes some time (500ms), so it would be good to do it
asynchronously, without blocking the IOC.
Or is there any other easy way, without reimplementing all the i2c
sensor readout eg inside an ASYN driver in C++ code ?
Thanks for any hints or help
Best regards,
Christian
--
Dr. Christian Pauly
Bergische Universität Wuppertal
Fachbereich C - Physik
Gaußstraße 20, D-42119 Wuppertal
Tel: +49 (0)202 439-2632,
Fax: +49 (0)202 439-2662
- Replies:
- Re: Fetching return value from external program call in StreamDevice Kasemir, Kay
- References:
- Fetching return value from external program call in StreamDevice Christian Pauly
- Navigate by Date:
- Prev:
Re: Fetching return value from external program call in StreamDevice Kasemir, Kay
- Next:
Re: Fetching return value from external program call in StreamDevice Rod Nussbaumer
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
<2015>
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
RE: Fetching return value from external program call in StreamDevice Al Honey
- Next:
Re: Fetching return value from external program call in StreamDevice Kasemir, Kay
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
<2015>
2016
2017
2018
2019
2020
2021
2022
2023
2024
|