Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass .net in actor framework

Hi,

I have an instrument that the vendor provides a .net object to communicate with it. I wrote a LVclass which holds the vendor provided .net object and the functions to talk the instrument and it worked fine. Then I tried to use the instrument class I wrote in my main program written using actor framework. I bundled the instrument class in the the actor before calling Launch Actor. After the actor was launched, I got error trying to talk to the instrument. I checked that I could talk to the instrument right before launching actor and I checked it the first thing in the actor core and it fialed. It seems to me that there was something strange passing a LVclass with a .net object.

The error message is 1172 (System.ArgumentNullException: Key cannot be null. Parameter name: key). I'm running LV 2012 (12.0.1f5, 32-bit).

I may have a workaround, but I would like to know where the problem is. Does anyone has an idea?

Thanks,

Joseph

0 Kudos
Message 1 of 7
(6,246 Views)

If this turns out to have anything to do with putting a .net refnum inside a LV class, I'll be stunned. I'll owe you a drink-of-your-choice the next time you come to Austin. .NET refnums are just integer values so far as the class is concerned -- just like any other refnum.

Put a probe on the refnum when you read it out of the LabVIEW class.

If the numeric value of the probe is 0, then you didn't actually write the refnum into the actor object. Maybe you wrote it into a forked copy of the actor?

If the numeric value of the probe is non-zero, then the refnum is being deallocated at some point -- refnums have the same lifetime as the top-level VI that creates them. Are you having your top-level VI acquire the .NET refnum and then quit? If so, that will deallocate any refnums that were allocated by the top-level VI.

0 Kudos
Message 2 of 7
(3,660 Views)

I am currently using .NET objects  in my actors without issue.  I second AristosQueue's thoughts on possible root causes.  In my application, the actors own the .NET refnums for their entire lifetimes.  Give your actor a method for opening the .NET reference, create a message for this method, and then call this message in that actors Pre-Launch Init.vi.  I bet this will solve your problem.

0 Kudos
Message 3 of 7
(3,660 Views)

Thank you very much. It did deallocated during the quit of the top-level VI. I moved the code and it worked.

Joseph

0 Kudos
Message 4 of 7
(3,660 Views)

Woo hoo!

0 Kudos
Message 5 of 7
(3,660 Views)

AristosQueue wrote:

If this turns out to have anything to do with putting a .net refnum inside a LV class, I'll be stunned.

Joseph, since you're in LV2012, there does exist one issue with AppBuilder you may watch out for, where it does not correctly relink a .NET reference inside a class to an assembly that's part of the distro. My workaround for this problem was to store the .NET reference in the class as a flattened type, using accessors to translate back and forth from the typed reference.

All other .NET constants/methods/ctors/controls/etc were relinked properly in the distro -- just not the .NET ref inside the class. This does not affect linkages to .NET assemblies in the GAC (i'm guessing, since that link does not change from source to distro), only with assemblies shipped with the distro. (I've not tested if this behavior is fixed in newer versions than LV2012 SP1.)

Zing. Stunned ya.

(and here's a screenshot of the workaround from the original bug report)

original.png

Message 6 of 7
(3,660 Views)

Jack: Good to know, but it is still not a store-and-retrieve problem. That's an AppBuilder issue. I'm not buying drinks yet. 😉

0 Kudos
Message 7 of 7
(3,660 Views)