EPICS Home

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

Subject: Re: CSS - how to read waveform of CHARS (or STRINGS) in a script? - SOLVED
From: Isabella Rey <[email protected]>
To: [email protected]
Date: Wed, 18 Mar 2015 12:18:56 +0000
Hi All, 

We tried Hugo's solution, but this only got the first character of the string for us so we used getLongArray instead and had to do some splitting to remove brackets and L's which were returned along with the int array. 
There may be a more elegant way to do it but the code as follows worked for us.

Cheers,
Isabella 

from org.csstudio.opibuilder.scriptUtil import PVUtil 
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil 

#Get characters as Long Int array 
#This has form e.g. 'array('l',[70L,69L,45L])' sans quotes 
v = PVUtil.getLongArray(pvs[0]) 

#split array on starting square bracket '[' 
v = str(v).split("[") 

#if this is false it means '[' wasn't present 
if len(v)>1: 
        # Select part after '[' 
        v = v[1]                 
                                    
        #Cut off end of array marked by "]" 
        v = v.split("]")[0] 

        #Remove "L"'s from array (signifying long ints) 
        v = v.replace("L","") 
        
        #split string on commas into list 
        v=v.split(",") 
        #rejoin characters into string 
        strArray = "".join(chr(int(i)) for i in v) 

On 13 March 2015 at 19:47, Hugo Slepicka <[email protected]> wrote:
Hi Isabella,

I think that this will work for you:

from org.csstudio.opibuilder.scriptUtil import PVUtil
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil

v = PVUtil.getString(pvs[0]).split(",")
myStr = "".join(chr(int(i)) for i in v)
ConsoleUtil.writeInfo(myStr)

HTH,
Hugo

On Fri, Mar 13, 2015 at 4:01 PM, Isabella Rey <[email protected]> wrote:
Hi All,

In CSS (Windows), I am trying to read a waveform of CHARS inside a Python script.
When I do PVUtil.getString, I get displayed a sequence of numbers instead of characters.

Is there any way to get the text in the script??

If I create a text update widget pointing at the waveform, I get the text correctly, I want to get the same in the script.

If it helps:
for what I need to do, I can also have a waveform of strings, rather than chars, and I need to extract the strings in the Python script.
Whichever works would be fine!

Cheers,
Isabella




--
Hugo Slepicka
+55 19 9 9902 9322



Navigate by Date:
Prev: Text input to char waveform - bug? Isabella Rey
Next: Re: Text input to char waveform - bug? Hinko Kocevar
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: Text input to char waveform - bug? Summers, Tasha
Next: Increment array counter for NDFileModeSingle Hinko Kocevar
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024