Discussion:
Access individual cluster elements through Python
(too old to reply)
Ravi0709
2008-07-02 08:10:06 UTC
Permalink
Hi....My project has many(500 to 800) controls and indicators
which are spread over many individual vis. I wish to control all these
vis from a single (main) vi. I am using "call by reference" technique,
which is the best way (I hope !!). To handle these controls easily I'm
using clusters. I shall control this main vi from Python. I know how to
access each individual LabVIEW control terminal from Python. I kept all
these control and indicator terminals in side clusters. Now, I'm able
to read and write whole cluster at a time, which is not my requirement.
I want to read or write only one cluster element at a given time. I
tried a lot but I'm unable to work it out. Pls...help me to solve my
problem. I have one more doubt, Instead of keeping all controls and
indicators in main vi directly, I'm simply merging into clusters. This
merging process (into clusters) takes place in individual vis. Is this
step increses/decreses complexity of model ?? We want to keep the code
as less complex as possible.Thank you,Ravinder
MikeS81
2008-07-02 09:10:06 UTC
Permalink
Hi Ravinder,
do you need a way to get the elements in a cluster within LabVIEW? If you have the reference of a cluster you can connect a property node to it, to get the reference of the controls inside the cluster. Is it what you need?
 
Hope it helps.
Mike
Ravi0709
2008-07-02 09:40:10 UTC
Permalink
Hi Mike,Thank you for ur response....I wish to access cluster elements from Python not from LabVIEW. My idea is to pass the value to an individual cluster element from Python. As I specified in first post, I can only  pass values to whole cluster at a time. I want to pass only one value to one LabVIEW cluster element from Python. I need help to write Python code to access LabVIEW program as I specified.Thank you,Ravinder
MikeS81
2008-07-02 09:40:11 UTC
Permalink
Hi Ravinder,
how do you write data into the cluster at the moment? Do you need a LabVIEW vi for it?
Mike
Ravi0709
2008-07-02 10:10:08 UTC
Permalink
HI Mike,I think I'm not explaning my problem correctly. I have many clusters on my vi's front panel (I have provided a sample cluster of my vi). I wish to control my vi (I mean... changing title, instructor or No. of students separately) from a Python program. When I tried from a python code, I was able to change all cluster elements at a time (here Title, instructor and No. of students). But my requirement is to write individual cluster elements separately. I hope I have presented my problem correctly.Thank you,RavinderP.S: "I don't want to access whole cluster at a time. I need only individual cluster element access from Python"


figure71.png:
Loading Image...
MikeS81
2008-07-02 10:10:08 UTC
Permalink
Hi Ravinder,
i understand that you use Python. How do you communicate with the vi (the vi with all your cluster)? Do you need another vi for it?
 
Mike
Ravi0709
2008-07-02 10:40:04 UTC
Permalink
Hi Mike,I'm able to communicate directly to required vi from python. I want to pass values to main vi which has clusters. I don't know, If I need another vi. I think my problem is with python code. I need help to write python code to access a cluster element directly.Thank you,Ravinder
MikeS81
2008-07-02 11:10:04 UTC
Permalink
Hi Ravinder,
can you upload your main vi? Or a vi with the same functionality?
Mike
Ravi0709
2008-07-02 11:40:05 UTC
Permalink
Hi Mike, I'm sending one VI which resembles my main vi.Thank you,Ravinder


test41.vi:
http://forums.ni.com/attachments/ni/170/336919/1/test41.vi
MikeS81
2008-07-02 12:10:05 UTC
Permalink
Hi Ravinder,
i will check it later, i have no Python now.
Mike
parthabe
2008-07-02 11:10:06 UTC
Permalink
Ravi0709 wrote:
I think my problem is with python code. I need help to write python code to access a cluster element directly.

I m afraid, this is the wrong place to seek for any help to write/fix your Python code.
Ravi0709
2008-07-02 12:10:06 UTC
Permalink
Hi Partha, u r right...but only LV users come across this problem. Thats why I requested for help in this forum.Thank you,Ravinder
Ben
2008-07-02 13:10:05 UTC
Permalink
Some how I feel like I am doing you an injustice by responding but...
If you wrote VIs that accessed the cluster elelments you are after, you could call those from Python and let them do the dirty work.
Ben
Ravi0709
2008-07-02 13:10:09 UTC
Permalink
Hi Ben, If there is no possibility of accessing individual cluster elemtnts from python then, I won't work with clusters. As I explained in first post my main vi contains hundreds of controls if I keep them directly. To avoid this, I'm using clusters. If I keep controls in some other vi and pass values to clusters, there is no meaning in using clusters.I have one doubt, keeping hundereds of controls in a single vi or merging these controls into few clusters makes any performance difference.Thank you,Ravinder
ACPRobert
2008-08-08 17:10:05 UTC
Permalink
Hello RavinderI just found this thread while looking up another problem I'm having with Python and a LV executable, but while I'm here...I recently started playing with using Python as a scripting language for automated testing using LV interface and drivers.  It turns out to be very easy.  Like you, I prefer to use clusters to pass around related data -- they're really like structures in C.  It turns out to be very easy:  myValues = getcontrolvalue("myCluster")where myValues is a tuple, which  can be converted to a list where you can manipulate control values and write them back to the VI.Hope  this helps.RobertIf you
Ravi0709
2008-08-14 21:10:07 UTC
Permalink
Hi Robert, Thank you for your reply. I was able to read/write complete cluster in a perticular order. But my wish is to access any given member of a cluster. I think it is not possible. So, I left that method. Thank you,Ravinder 
ACPRobert
2008-08-14 22:40:16 UTC
Permalink
Hi Ravinder  The elements in a cluster have a default order which you can observe by right clicking on the cluster and select "Reorder controls in cluster...." Here you can set any order you wish, or just observe the naturel order  which is the order the controls were originally added to the cluster. the Python call to get control value returns a tuple with the elements in the same order.  If an element is an array or cluster then that element is retrned as a tuple.   For my test case I have a cluster with a numeric value, an boolean, an array, and another cluster with a string and slider.     def cTest(self):    #This is a class method. The class initializer gets the reference to the vi
        tcState = list(self.VI.getcontrolvalue('TC'))    # Pick up the tuple and change it to a list
        tcState[0] = tcState[0] + 0.5   # increment numeric value
        if(tcState[2][3]):    # Check the state of the boolean array and...
            tcState[1] = True         # Turn on the button if the item is on.
        sub = list(tcState[3])    # Convert the internal cluster tuple to a list
        sub[0] = "New text"       # Change the text element
        sub[1] = 4.32             # and the slider.
        tcState[3] = sub          # replace the original sub clusters' tuple
        self.VI.setcontrolvalue('TC',tcState)  # and send the new value back to the VI!

 Python is looking like a great way to add scripting and automated testing  no changes to the underlying VI.Hope this helps.  Robert 
Loading...