LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Event Refnum to Call Library Function

I am trying to use the method described in this post to have my callback function in a dll trigger a user event in LabVIEW. I basically need to pass the refnum to the library function so it knows what event to trigger via PostLVUserEvent.

However, I am stuck on step 1, becauase I can't pass the refnum for the user event to a library function. I can't convert it directly to a U32, which is the data type the function PostLVUserEvent is expecting. And I can't unbundle the refnum to get a number. The only way I can find the numerical value that the refnum represents is by looking at the probe. 

Does anybody know how to pass the output of Create User Event (refnum) to the Call Library Function vi?

0 Kudos
Message 1 of 4
(2,179 Views)

I usually will set the parameter of the CLFN to 'Adapt to Type' and 'Array Data Pointer'.  This passes a pointer to the desired value to the DLL and you just need to dereference it in the call to PostLVUserEvent.

0 Kudos
Message 2 of 4
(2,172 Views)

You can also use Type Cast, but then you have to be careful about your pointer size.

I think with Darin's solution, you get adaptation on 32/64-bit for free.


GCentral
0 Kudos
Message 3 of 4
(2,124 Views)

Refnums in LabVIEW are normally always an uInt32 on any platform. It is not a pointer for sure but rather a magic cookie whose value indexes into a refnum specific magic cookie jar that contains the real refnum object data as an unsorted array. Some of the 32 bits are reserved as a magic bit pattern that gets assigned randomly to the magic cookie jar at the time of its creation during startup of LabVIEW. This allows a magic cookie jar to check that a received refnum is really a reference into its list of objects before handing back the object data record.

 

But for the purpose of the LabVIEW diagram you shouldn't care about this at all and for the purpose of passing it to a C function in LabVIEW you should neither. All refnums should be passed as Adapt to Type in the Call Library Node just as Darin suggested, which for the user event will result in this on the C side:

 

__declspec(dllexport) MgErr MyFunction(LVUserEventRef *refnum, ......)
{

} 

 

For other refnums it would simply be the more generic LVRefNum instead.

 

In fact for some refnums, if you configure the Call Library Node as a pointer sized integer and directly connect the refnum to this terminal, LabVIEW will in fact coerce the refnum and pass the underlaying object data to the DLL but that is an undocumented feature and only works for some refnums. Typically IVI and VISA refnums will coerce to their underlaying VISession object and some of the other external library based refnums will pass their underlaying object data pointer instead. But this does not work for built in LabVIEW refnums (basically any refnum that happens to be present in the Refnum Control palette since the object data for those is often directly a more complex data structure rather than simply a pointer or handle).

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 4
(2,118 Views)