LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Access individual cluster elements through Python

Hi Ravinder,

i will check it later, i have no Python now.

Mike

0 Kudos
Message 11 of 20
(2,534 Views)
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
0 Kudos
Message 12 of 20
(2,530 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 13 of 20
(2,520 Views)
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
0 Kudos
Message 14 of 20
(2,515 Views)
Hello Ravinder
I 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.

Robert


If you

0 Kudos
Message 15 of 20
(2,439 Views)

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 

0 Kudos
Message 16 of 20
(2,416 Views)

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 

0 Kudos
Message 17 of 20
(2,409 Views)

Hi Robert,

 

Yah.....It looks very easy. Thank you...Once we get tuple to list we can play round it.....I'm using python and LabVIEW together to automate the test system. I think python and LV combination helps greately to automate test  systems.

Thanks..

Ravinder 

0 Kudos
Message 18 of 20
(2,384 Views)

R u trying to interface Labview VI and Python or exe built from Labview and Python?

0 Kudos
Message 19 of 20
(1,887 Views)
Odd number,

Why post to such an old thread? You've already started one, please stick to it.
0 Kudos
Message 20 of 20
(1,884 Views)