LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Each time I use the Active X Automation Open feature a new Instance is created even if one already exists?

The story so far...
 
I am using the Active X features to create an event callback structure in combination with a queue to achieve an event driven structure. The initial registration is performed in  a Sub VI using a Automation Open dialogue  and after completion the reference is stored in a variable created at the top level VI (not a global). Afterwards each time I try to reconnect to the interface of the COM object (normally for communication purposes via a CAN Bus) even though I pass the original stored reference into the Automation Open dialogue, a new instance is created of the COM Object. Consequently, multiple instances of the COM Object are created resulting in loss of synchronisation between the COM object and the LabView Program. As a result when the Lab View program is terminated the a fatal exception error occurs crashing the program.
 
So my questions are:
 
1. How can I ensure that the same reference is used (either directly or via the Automation Open dialogue after creation and that no additional Instances of the COM Object are created?
2. Is it possible to create the initial instance of the COM Object in a SubVI (limited scope) and store the reference created in a variable created in the Top Level VI that has been passed into the SubVI or is the reference always destroyed on leaving the Sub VI?
3. What effect does the Close Reference dialogue have on the referenced instance of the COM Object and when should it be used?
 
I have been trying to solve with this problem for a week with the Active X experts without success so I hope someone can help.
 
Many thanks in advance.
 
Ian Melville 
 
0 Kudos
Message 1 of 9
(3,080 Views)
Hi Ian Melville,
you can check if the connected reference is valid. Use a case structure with true/false case. If the reference is valid use the reference, if not create a new one.
 
Hope it helps.
Mike
Message 2 of 9
(3,079 Views)

Hi Mike

Thanks for the quick reply. This is where I am a bit puzzled about the operation of the Automation Open dialogue. According to the help infomation when left in its default state the dialogue will first try and connect to an existing valid reference before creating a new reference/instance. This does not appear to work, at least not how I interperate the available information about how it should work. In any case what would you consider an appropriate test of whether a reference is valid (appart from a non-null value)? 

Regards

 

Ian

0 Kudos
Message 3 of 9
(3,074 Views)

Hi Ian,

you can use a shift register to store your refnum and check it with "not a refnum". See the attached picture.

Hope it helps.
Mike

0 Kudos
Message 4 of 9
(3,071 Views)
> 1. How can I ensure that the same reference is used (either directly or
via the Automation Open dialogue after creation and that no additional
Instances of the COM Object are created?

Use Open Automation only once.

> 2. Is it possible to create the initial instance of the COM Object in a
SubVI (limited scope) and store the reference created in a variable created
in the Top Level VI that has been passed into the SubVI or is the reference
always destroyed on leaving the Sub VI?

Make an action engine. E.g. a while loop with a case. The while loop has a
shift register which holds the reference. The TRUE case does an open
automation, the false case simply passes the previous value.

> 3. What effect does the Close Reference dialogue have on the referenced
instance of the COM Object and when should it be used?

If you mean Close Reference function, it closes the reference, and releases
the object. You use it for each reference you've opened, once you're done
with it.

Regards,

Wiebe.


0 Kudos
Message 5 of 9
(3,067 Views)

Hi Wiebe.

Thanks for the input and the solutions when a reference is lost. What I'm still trying to understand is the reason/mechanism that causes the reference to be lost in the first place?  Is the storing of a reference in a cluster via a local variable for future use not allowed? The reason I ask is that the Program is nested structure with SubVi's within SubVi's which does not easily lend itself to the Action Engine structure that yourself and Mike suggested.

Regards

Ian

 

0 Kudos
Message 6 of 9
(3,051 Views)
Originally you mentioned:

>Afterwards each time I try to reconnect to the interface of the COM
object (normally for communication purposes via a CAN Bus) even though I
pass the original stored reference into the Automation Open dialogue, a new
instance is created of the COM Object.

I think you need to tell us more about this. Most important question: how do
you notice that a new instance is created?

Normally, an external reference (.com or .net) should stay open untill
explicitelly closed. Now there might be an optimalisation bug or something,
but it's hard to tell without seeing any code.

Regards,

Wiebe.


0 Kudos
Message 7 of 9
(3,026 Views)

Hi Wiebe

I have the ability to debug the COM Object using .NET Visual Studio and can see that every time the interface is accessed the process to create a new instance is performed. During recent discussions it has become apparent that the because I have created the original instance/refnum in a SubVi when the SubVi is exited the instance resources are released thus causing the refnum to be no longer valid. As the COM Object needs a reference to the original instance to shutdown the event handling properly I need to ensure the original refnum/instance is not released until the end of the LabView program shutdown. Would a AE/FG actually help under these circumstances?

Best Regards

 

Ian Melville

0 Kudos
Message 8 of 9
(3,009 Views)
> I have the ability to debug the COM Object using .NET Visual Studio and
can see that every time the interface is accessed the process to create a
new instance is performed. During recent discussions it has become apparent
that the because I have created the original instance/refnum in a SubVi when
the SubVi is exited the instance resources are released thus causing the
refnum to be no longer valid. As the COM Object needs a reference to
the original instance to shutdown the event handling properly I need to
ensure the original refnum/instance is not released until the end of the
LabView program shutdown. Would a AE/FG actually help under these
circumstances?

Why don't you give it a try? An AE/FG that buffers the reference woudn't
take much longer then 5 minutes to make. I can't do it for you, I don't have
..NET Visual Studion to debug the AX behaviour. That is a nice feature
though!

Regards,

Wiebe.


0 Kudos
Message 9 of 9
(3,001 Views)