LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing arbitrary amount of front panel indicators from sub-vi?

Hello,

I am very new to labview (one week) and very experienced in C++, if I
refer to anything incorrectly, please correct me.

I am trying to make a sub vi whose task will be to communicate (via
TCP) with a remote process. The sub vi should be able to be plugged
in to any vi and be able to both read and write the value of the front
panel indicators as dictated by the remote process. The number or
type of indicators is not known, but will be known by the remote
process. I created a working prototype whose code is in the same vi
as the indicators, but it contains two local variables (one read, one
write) for each front panel indicator. As I understand it, local
variables cannot be accessed in a sub vi,
so this approach must be
modified. I am thinking that I could have an array of each type as
inputs to the sub-vi. The arrays could contain references to each
indicator. This would allow me to access any value that the remote
process demands. Is this possible in labview? I can't figure out how
to access or modify the value of an indicator given a reference to it.
Can this be done with control references? Is there something else
that I should use? Any help is appreciated.

TS
0 Kudos
Message 1 of 5
(2,880 Views)
You can modify the value of controls and indicators with property nodes. However; you have to be able to pass the referenes into the subVI, or obtain them through VI server.

This sounds like a bit of a challenge, but is very doable. It will just be a lot of work to determine what type of data to set the values to, as you will have to figure out what the data is.

Do a search on NI's websites for information along these lines. You should see plenty of information. Also, be sure to check the examples and help that ship with LabVIEW.
0 Kudos
Message 2 of 5
(2,879 Views)
Labviewguru wrote in message news:<506500000005000000378A0000-1023576873000@exchange.ni.com>...
> You can modify the value of controls and indicators with property
> nodes. However; you have to be able to pass the referenes into the
> subVI, or obtain them through VI server.

Yes, I found property nodes shortly after posting this. It was really
hard to find, because in labview when you click on a reference and hit
help, the description is like two lines long and doesn't say how to
use it. I eventually found out about them on the ni site.

> This sounds like a bit of a challenge, but is very doable. It will
> just be a lot of work to determine what type of data to set the values
> to, as you will have to figure out what the data is.

Yep,
I got it done this morning. I took the output of the Type
Descriptor property, took the second element (index 1), bitwise and'd
that with 0xFF, tested to see if THAT was less than 8, if it was, I
sent an int constant to the proper function (variant to data for
reading, unflatten to string for writing) and if it wasn't I sent a
float constant. I found out about the g type code in the Type
Descriptor array from a discussion on the NI site and how to get at
that code by the pdf help file about Type Descriptors. Bitwise AND
and logical AND are the same function, which also took me by surprise.
Also, a reference seems to be it's own data type, as you can make an
array that contains references to indicators of different types (maybe
you can make arrays of different types with out references? I don't
know). This was _very_ convenient.

> Do a search on NI's websites for information along these lines. You
> should see plenty of information. Also, be sure to check the examples
> and hel
p that ship with LabVIEW.

Thanks for your help.

TS
0 Kudos
Message 4 of 5
(2,879 Views)
Hi TS,

Wondeful start for a non-LV programmer!

Here is some more info.

When you build the array of control refs in the main app (in prep for passing to sub-VI) the get convgerted into generic types (all element of array must be same data type). This means the sub VI is going to have to "bend over backwards" to get the data in and out of the controls and indicators.

THe bending over -backwards can be done in at least two ways.

1) Take the reference and convert it to the specific class that accurately reflect the controls data type. This will let you wire to or from the "value" input of a property node.

2) Leave the ref as generic and convert "Variant" dat from the value to the data you need. When writing, I believe LV will automatically do the convert
to variant for you.

I hope this helps,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 5
(2,879 Views)
> 1) Take the reference and convert it to the specific class that
> accurately reflect the controls data type. This will let you wire to
> or from the "value" input of a property node.

This is what I did at first, I had a case statement with about 10
cases, one for each type the value could take on. I also had to do
boolean variables, so I had to change the reference type from numeric
to control. I eventually had it working this way.

> 2) Leave the ref as generic and convert "Variant" dat from the value
> to the data you need. When writing, I believe LV will automatically do
> the convert to variant for you.

Just today (4 days after having it working the first way) I discovered
the two functions "Flattened String to Variant" and "Variant to
Flattened
String". Since I was reading and writing the values to a
tcp socket, I was flattening and unflattening the values anyway, so I
replaced a whole bunch of code (pulling the g type code from the type
descriptor, sending the type code to a case statement, where constants
of each of the possible types were, passing the constant to unflatten
from string, then sending the output of that to a control ref) with a
call to "Flattened String to Variant" and then sent the output of that
to the control reference.

It was quite an introduction to labview programming.

Thanks for your help.
0 Kudos
Message 5 of 5
(2,879 Views)