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  <20162017  2018  2019  2020  2021  2022  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  <20162017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: CSS gets freeze while running a script
From: Matt Newville <[email protected]>
To: palak shimpee <[email protected]>
Cc: EPICS Tech Talk <[email protected]>
Date: Fri, 30 Sep 2016 07:14:52 -0500
Palak,

If the idea is to capture values and timestamps for a few PVs to an external file outside of CSS, I would suggest using pyepics and a script like this:

#####
from time import sleep
from datetime import datetime
from epics import PV

pvs = [PV('PVNAME1'), PV('PVNAME2'), PV('PVNAME3')

fout = open('PVlist.txt', 'w')

header = ['# Time  ']
for pv in pvs:
    header.append(pv.pvname)
header = '  '.join(header)
fout.write("%s\n" % header)

while True:
    try:
        thisline = [str(datetime.now())]
        for pv in pvs:
            thisline.append(pv.get(as_string=True))
        thisline = ' '.join(thisline)
        fout.write("%s\n" % thisline)
        fout.flush()
        sleep(0.01)
    except KeyboardInterrupt:
        break
fout.close()

####

You definitely want a short "sleep()" in your loop.    If you're really worried about missing events (or if you're worried that you will be capturing too many repeated values) It might be better to use a more sophisticated approach using monitor callbacks so that values are written to a file every time they change, but only when they change.


A few comments on your script:


On Fri, Sep 30, 2016 at 12:47 AM, palak shimpee <[email protected]> wrote:
In CSS I am running a python code and CSS is getting freeze as I already have got a suggestion to run the code outside CSS. But please can you help me how I can do it. Code is as below: 

from org.csstudio.opibuilder.scriptUtil import PVUtil
import os,sys
import subprocess
import glob
from os import path
from datetime import datetime
while (pv0==TRUE)

what is pv0, and for that matter what is TRUE?
 

pv=PVUtil.getDouble(pvs[1])

what is pvs[1]?
 

i = datetime.now()
sys.stdout=open("test2.txt","wb")

redefining sys.stdout has the disadvantage that this is done for all output for the entire process.  All you really want is to print some output to a file.
 

print str(i), pv, pv, pv, pv, pv
sys.stdout.close()  


Hope that helps,

--Matt Newville

References:
CSS gets freeze while running a script palak shimpee

Navigate by Date:
Prev: CSS gets freeze while running a script palak shimpee
Next: HTTP access to control systems screens Ryan Slominski
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: CSS gets freeze while running a script palak shimpee
Next: SNCSEQ error when making MakeBaseApp.pl Saeed Haghtalab
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  <20162017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Oct 2016 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·