LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use an array of references

Hi,

I defined a couple of GOOP objects, each of which has a reference. I want to dynamically add/remove these references into/from an array and, in my implementaion, I had this array a globle variable so that different VI's can access it.

But I always got a "refnum conflict" error when I tried to insert a new reference into the array.

Why? Thank you.

-Jianchu
0 Kudos
Message 1 of 9
(3,740 Views)
Each GOOP class's refnum is a different data type, and labview will not allow you to have an array of objects that are different types. You will need to create an array of refnum values. Typecast the refnums to a U32, and store an array of these -- you may actually want to create an array of clusters and have one element be the refnum value, and the other be the refnum type (as an enum, or something). Then, when you access them, you will need to cast them back to the correct type. Another option, instead of a cluster, is to store an array of variants. Either way you will need to inspect to see what type of refnum you have stored and operate on it appropriately.

Good luck,

-Jim
Message 2 of 9
(3,740 Views)
Thanks a lot for the reply, Jim.

I think I understand your first solution. But there is a problem:

I created an array of clusters with two elements: one is the typecasted refnum; the other is the refnum type. In my case, references refer to datalog files.

But after I bundled the new refnum and refnum type and wanted to insert it to the cluster array, I couldn't wire it to the NEW ELEMENT/SUBARRAY terminal. It says "the type of the source is cluster of 2 elements""the type of the sink is double". Actually, it is the same error when I tried to insert a refnum into a refnum array.

Look forward your further help.

-Jianchu
0 Kudos
Message 3 of 9
(3,740 Views)
Jianchu,

Please attach an example VI. This will give me a better idea of what your doing (and the problem).

-Jim
0 Kudos
Message 4 of 9
(3,740 Views)
Thanks, Jim.

I am working on some plug-and-play medical instrumentation prototyping. Two GOOP objects (ECG,PO) are developed. In my LabVIEW code, I need to open/close these two objects when corresponding devices connected to/disconnected from the computer.

I want to build a reference array which I can use to operate (primary data storage) the appropriate object.

I browsed your webpage "Object Oriented Design methods in LabVIEW " on OpenG.org. I guess my problem is related to the so-called "Datalog File Refnum Shell", but I don't have an exact idea.

I attached the two GOOP files and a test fie showing the wiring error.

Your help is highly appreciated.

-Jianchu
Download All
0 Kudos
Message 5 of 9
(3,740 Views)
Here is a VI that shows how to build a generic array of GOOP References. Notice that the GOOP Class string tells you the type of the GOOP object. If you still need help let me know.

Good Luck,

Jim
0 Kudos
Message 6 of 9
(3,740 Views)
Thanks. This solves my problem.

But I don't understand why we need a "Read file" function for GOOP class. Please let me know where I can learn more about it.

-Jianchu
0 Kudos
Message 7 of 9
(3,740 Views)
Jianchu,

Ah yes, that little bit of LabVIEW Magic is a trick I learned from Jean-Pierre Drolet. GOOP Refnums are single-element enums wrapped in a datalog file refnum shell. The "Read File" function is used to access the contents of the datalog file refnum, effectively unwrapping the enum type. Once we have the enum type we can get the string value of its 0th item's name, which is the GOOP object name. There are other ways of doing this. You can read the Type Descriptor of the GOOP Refnum and parse it, but that would look even more complicated than the "Read File" trick. Th
e most simple option is use the "Get GOOP Object Type" VI of the OpenG Toolkit's LabVIEW Data Tools Library. This uses the latter mechanism, and will make more sense on your block diagram.

Cheers,

-Jim
0 Kudos
Message 8 of 9
(3,740 Views)
Jianchu,

Here is a page that describes a little better about how datalog file refnums work and why they were chosen for use in GOOP objects:

Object Oriented Design methods in LabVIEW

Cheers,

-Jim
0 Kudos
Message 9 of 9
(3,740 Views)