EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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  <20212022  2023  2024  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  <20212022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Python Script call from Button press, module not found
From: "Layne \(US\), William C via Tech-talk" <tech-talk at aps.anl.gov>
To: "benjamin.franksen at helmholtz-berlin.de" <benjamin.franksen at helmholtz-berlin.de>, "anj at anl.gov" <anj at anl.gov>, "manoussakis1 at llnl.gov" <manoussakis1 at llnl.gov>
Cc: "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
Date: Fri, 16 Apr 2021 17:24:48 +0000
Just to chime in with a bash function I tend to copy-paste for different scripts. It should work for most PVs with a string representation. (Thanks Ben for the while loop trick! I had to go update mine. It's much cleaner now!)

```sh
function monitor_pv_for_value() 
{
	# Function: monitor_pv_for_value
	# Description: Template function that executes something when monitored PV matches expected value
	# Argument 1: PV name
	# Argument 2: Expected value
   
	SEP="$(echo -e "\037")" 		# Field seperator for camonitor
	
	[ -z "$1" ] && echo "Error: arg 1 must be a PV name" && return 1
	[ -z "$2" ] && echo "Error: arg 2 must be value to watch for" && return 2
	
	PV="${1}"				# Removes single quote characters as the script quotes them itself
	EXPECTED_VAL="$2"
	
	camonitor -t n "$PV" -F "$SEP" | while read line
	do
		VAL="$(echo -ne "$line" | cut -d "$SEP" -f 3)"
	
		if [[ "${VAL}" == "${EXPECTED_VAL}" ]]
		then
			# Do something with matching value...
			echo "VALUES MATCH"
		fi
	done
}
```

-----Original Message-----
From: Tech-talk [mailto:tech-talk-bounces at aps.anl.gov] On Behalf Of Ben
Franksen via Tech-talk
Sent: Friday, April 16, 2021 4:38 AM
To: Johnson, Andrew N. <anj at anl.gov>; Manoussakis, Adamandios
<manoussakis1 at llnl.gov>
Cc: EPICS tech-talk <tech-talk at aps.anl.gov>
Subject: Re: Python Script call from Button press, module not found

Am 15.04.21 um 18:46 schrieb Johnson, Andrew N. via Tech-talk:
> On Apr 15, 2021, at 11:26 AM, Manoussakis, Adamandios 
> <manoussakis1 at llnl.gov> wrote:
>> I was looking mostly into the epics.camonitor or the auto_monitor 
>> parameter (seems like camonitor just when you create the pv you can 
>> set this?) in pyepics.  The python script is just a small file 
>> generator that does some basic calculations.  I was trying to have 
>> CSS just call it to run to avoid having another application to deal 
>> with.  Either by pressing a button (execute command works fine but 
>> cannot get the execute to trigger based off a rule that I know
>> of) or by a pv changing value and css calling the script (jython 
>> doesn't work with numpy/pandas).
> 
> You might want to take a look at the separate Kryten program available 
> from https://github.com/andrewstarritt/kryten which can monitor PVs 
> and run specified commands or scripts on conditions related to those 
> PVs. Since this wouldn't be running inside your GUI it isn't subject 
> to the problems related to running multiple instances which Michael 
> mentioned.
I recently had a case where I needed that functionality for a simple test
script. I resorted to plain shell scripting, see below. As written the code
works only for a single PV but I guess it wouldn't be hard to add some
filtering / case distinctions in the loop body in case you need to monitor
more PVs.

```
sel=0
caput BPMMUXCB:sel $sel
camonitor -t n BPMMUXCB:st | while read line; do
  st=$(echo -n "$line"|cut -b 33-)
  echo "st=$st"
  if test $sel = $st; then
    sel=$(( ($st + 1) % 32 ))
    caput BPMMUXCB:sel $sel >/dev/null
    echo "sel=$sel"
  fi
done
```

Ben
--
I would rather have questions that cannot be answered, than answers that
cannot be questioned.  -- Richard Feynman



Replies:
Re: Python Script call from Button press, module not found Kasemir, Kay via Tech-talk
References:
Python Script call from Button press, module not found Manoussakis, Adamandios via Tech-talk
Re: Python Script call from Button press, module not found Kasemir, Kay via Tech-talk
RE: Python Script call from Button press, module not found Manoussakis, Adamandios via Tech-talk
Re: Python Script call from Button press, module not found Matt Newville via Tech-talk
Re: Python Script call from Button press, module not found Johnson, Andrew N. via Tech-talk
RE: Python Script call from Button press, module not found Manoussakis, Adamandios via Tech-talk
Re: Python Script call from Button press, module not found Johnson, Andrew N. via Tech-talk
Re: Python Script call from Button press, module not found Ben Franksen via Tech-talk

Navigate by Date:
Prev: RE: WIN_32 Mark Rivers via Tech-talk
Next: Re: Python Script call from Button press, module not found Kasemir, Kay via Tech-talk
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  <20212022  2023  2024 
Navigate by Thread:
Prev: Re: Python Script call from Button press, module not found Ben Franksen via Tech-talk
Next: Re: Python Script call from Button press, module not found Kasemir, Kay via Tech-talk
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  <20212022  2023  2024 
ANJ, 16 Apr 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·