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 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
<== Date ==> <== Thread ==>

Subject: Re: help - writing a table column from OPI BOY to PV
From: Michael Davidsaver <mdavidsaver@gmail.com>
To: "Kasemir, Kay" <kasemirk@ornl.gov>, Tomasz Brys <Tomasz.Brys@esss.se>, "tech-talk@aps.anl.gov" <tech-talk@aps.anl.gov>
Date: Fri, 4 Aug 2017 11:38:16 +0200
I've done something similar.  There are a few small bugs with Kay's
example.  In the hope of sparing the next person who finds this in the
tech-talk archive.  A working example which populates two PVs from two
columns of a table.

> from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil
> from jarray import array
> 
> Timestamp_SP = pvs[0]
> EvtCode_SP = pvs[1]
> 
> T, E = [], []
> for row in widget.getTable().getContent():
>         T.append(float(row[0]))
>         E.append(float(row[1]))
> 
> Timestamp_SP.setValue(array(T, 'd'))
> EvtCode_SP.setValue(array(E, 'd'))

The final product is evg-seq.opi and the 4 associated python scripts:

https://github.com/epics-modules/mrfioc2/tree/1c97219c34f65437151679203bb76191b9eb6070/evgMrmApp/opi

some notes

With jython, 'array.array' and 'jarray.array' both have java arrays
underneath them, but the order of arguments of their constructors are
reversed!

The elements if the 'pvs' array of a type 'IPV' which isn't included in
the cs-studio help system.

https://github.com/ControlSystemStudio/cs-studio/blob/master/applications/opibuilder/opibuilder-plugins/org.csstudio.simplepv/src/org/csstudio/simplepv/IPV.java#L129



On 07/05/2017 05:44 PM, Kasemir, Kay wrote:
> Hi:
> 
>> Michael Davidsaver <mdavidsaver@gmail.com>
>> http://www.aps.anl.gov/epics/tech-talk/2016/msg01173.php
>> Is this what you're looking for?  To write eg. an array of double?
> 
> Michael already linked to the basics of writing an array.
> The other missing piece might be constructing the plain array in the Jython code.
> In your example, you never fetched any column from the table, you just kept writing "i", the scalar loop index, to a PV.
> Plus PVUtil.writePV("$(PREFIX):ListVo...) would perform the potentially slow PV connection in the script, i.e. on the UI thread.
> 
> Try this:
> 
> # Have this script with two PVs attached to the table widget
> #
> # pvs[0]: Something like loc://do_write_the_column(0), triggering the script execution
> # pvs[1]: That array PV to which you want to write the column, NOT triggering the script
> from org.csstudio.opibuilder.scriptUtil import PVUtil
> from array import array
> 
> if PVUtil.getInt(pvs[0]) > 0:
>     # Get the table content
>     table = widget.getTable()
>     content = table.getContent()
> 
>     # Get table's column 2 (counting from 0) into col
>     col = []
>     for row in content:
>         col.append(row[2])
> 
>     # Write that column as a double[] array to the array PV
>     pvs[1].setValue(array(col), 'd')
> 
> 
> Now have your button write 1 to loc://do_write_the_column(0)
> Note that only the first PV must trigger the script execution, not the second one, because otherwise the script writing to the array PV would trigger the script which writes the array PV which triggers the script to write the array PV etc.
> 
> -Kay
> 
> On 07/05/2017 04:14 PM, Tomasz Brys wrote:
>> Hi,
>> I need help.
>> I have an OPI BOY. I created a table Nx3, (Nrows, 3 columns), N can be from 1 to 200.
>> User can modify the table and when is ready press the button to write the whole column of the table to PV
>> The PV is type of aao , size 200. Of course, the table can have less than 200 elements.
>> What would be the easiest way to do this?
>> I tried something like that, create an Action Button and as an action I execute such a script:
>>
>> from org.csstudio.opibuilder.scriptUtil import PVUtil
>> from array import array
>>
>> tab = display.getWidget("Table")
>>
>> row = tab.getTable().getRowCount()
>> for i in range(1, row):
>>    PVUtil.writePV("$(PREFIX):ListVolt", i)  # - this works but write always one element [0]
>>    print i
>>
>> My question:
>> How I can write one column of a table to PV which is type of aao?
>> Is it possible to write the whole column at once? Or I have to do it element by element?
>> Any help will be appreciated.
>>
>> Regards
>> --
>> Tomasz Brys
>> Integrated Control System
>> European Spallation Source - ERIC
>>
>>
>>
> 


References:
help - writing a table column from OPI BOY to PV Tomasz Brys
Re: help - writing a table column from OPI BOY to PV Michael Davidsaver
Re: help - writing a table column from OPI BOY to PV Kasemir, Kay

Navigate by Date:
Prev: Webopi issue with Text Update widget rule Petrella, Nicoletta
Next: Re: XYgraph pv_name 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
Navigate by Thread:
Prev: Re: help - writing a table column from OPI BOY to PV Kasemir, Kay
Next: New releases of many areaDetector modules Mark Rivers
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
ANJ, 04 Aug 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·