LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Register Event Callback Function with arrays of .NET connections?

Solved!
Go to solution

I am trying to determine if it is possible to setup something akin to a single .NET asynchronous message-event handler for an arbitrary number of connections to network-connected Galil motion controllers that can generate the asynchronous messages.   The attached PDF shows a basic example of how two connections to two different controllers can be opened and the asynchronous messages from those controllers monitored. 

 

But to setup the asynchronous message handling for those two connections, for each controller a specific separate "Callback Data" string control had to be created and passed as a reference to to the "User Parameter" input of the "Register Event Callback" function. From the "Register Event Callback" function a "Simple Callback message" subVI is created and it is the responsibility of the subVI to receive the messages from the open network conection to a Galil controller and move them into the "Callback Data" string control that is pointed to by the string-control reference.

 

Later, when it is time for the main VI to check for messages, it needs to check each separate "CallBack Data" String control to see if message data has been placed there by the "Simple Callback message" subVI.

 

This use of separate individual string controls to transfer data between the subVI, handling the events, and the main VI reading the messages works OK for one or two controllers, but if there are an arbitrary larger number of controllers, it would be much cleaner/easier to use an array of callback message data strings to transfer the data from the subVI to the main VI so that the main VI can index the array to find any message from a selected controller. 

 

While it is possible, instead of a reference to a simple string, to use a reference to an array or to a cluster containing an array as the "User Parameter" Input to the "Reg Event Callback" function, there does not appear to be a good way, as far as I can tell, to communicate to the (peallocated clone reentrant execution) subVI that's created, which element in the array is to be used by each clone and .NET connection.

 

Is there a way to set up a multi-channel event callback that does not require a separate, explicitly-defined string control for each connection?

0 Kudos
Message 1 of 10
(4,066 Views)

The callback simply calls a VI. You can do anything you want inside that VI. You chose to write a value to a control, but you could also just do something else, like writing the data to an action engine which would hold multiple values or pushing the values into a queue or generating a single user event which the main VI will listen to, so that all messages get to the same place. That way you also don't have to poll for new data.


___________________
Try to take over the world!
0 Kudos
Message 2 of 10
(4,054 Views)

Yes the subVI can do more and I've made use of that fact on other occasions. But at this time I have not yet been able to figure out how the one shared reentrant callback subVI can tell from which .NET connection any given message originates so that it can then sort it into the correct "bin" (assuming it has several to choose from) for later consumption by the main NI.

0 Kudos
Message 3 of 10
(4,045 Views)

Just whatever you do don't run a process in the callback VI.  Apparently ( I didn't know this until recently) it is executed in the root loop so any prolonged action in the callback will completely stall LV.

 

I need to find a reference for that piece of information, I don't expect anyone to just believe me.

0 Kudos
Message 4 of 10
(4,034 Views)
Solution
Accepted by topic author WNM

@WNM wrote:

But at this time I have not yet been able to figure out how the one shared reentrant callback subVI can tell from which .NET connection any given message originates so that it can then sort it into the correct "bin" (assuming it has several to choose from) for later consumption by the main NI.


Provide it as an input parameter.

 

Here's a quick and dirty example:

 

Event.png


___________________
Try to take over the world!
Message 5 of 10
(4,021 Views)

Thanks!  I was under the mistaken impression that a reference needed to be connected to the "User Parameter" input of the "Register Event Callback" function. Your example showed me that it could be anything and that allowed me to include an index value along with a reference to message array. It all works now. The attached PDF shows my previous code modified to use this new technique. 

 

FWIW, this code does have the flaw that multiple VIs can be modifying the "Messages Strings" array at the same time, so I need to take care of that, but that's something I know how to do.

0 Kudos
Message 6 of 10
(4,005 Views)

@WNM wrote:

 

FWIW, this code does have the flaw that multiple VIs can be modifying the "Messages Strings" array at the same time, so I need to take care of that, but that's something I know how to do.


Like I said (and even demonstrated), you can simply pass the data to a queue of some kind (queue, event, etc.) and then you don't have that problem and you don't have to poll.

 

Also, those PDFs take a long time to download for some reason. I would suggest embedded images or snippets or actual VIs when relevant.


___________________
Try to take over the world!
0 Kudos
Message 7 of 10
(3,970 Views)

Yes, the ability to strictly-type the input and then auto-generate a callback VI is a really neat feature.  I've used this quite a lot in the past.  It's much better than just sending everything as variant.  I always prefer having errors detected in the IDE (incompatible strict reference types) rather than at run-time (Variant to data)

0 Kudos
Message 8 of 10
(3,944 Views)

@tst wrote:


 

Also, those PDFs take a long time to download for some reason. I would suggest embedded images or snippets or actual VIs when relevant.


Going to a different computer here and checking I found that each PDF required less than a second to download so the problem you are experiencing must exist somewhere  between you and NI.  The PDF just acts as a container for the images and to some extent it compresses them so it ends up being slightly smaller than if I had uploaded individual images.  Since the VI makes use of a 3rd-party library that most people would not have or wanted to install, it did not make sense to upload them.

0 Kudos
Message 9 of 10
(3,917 Views)

Hi Mr.x,

         I've read your thread, it just looks similar to what i needed exactly.

        I'm using Trio motion coordinator ActiveX control, the same i communicating the device through the asynchronous mode, and i'm trying to read and write the position command simultaneously.

         But when i trying to get the parameter data, the buffer get overflows, the software manual mentioned that i need to use call back event function should be used.

   Here i parllely running the two programs in a Trio software

 one of the two software is a actual arbitrary movement and 

second is psoition data which we want to plot in a graph

Give me any possible solution.

If i'm confusing, then i will send my code and reference manual

 

Thanks and regards,

Dinesh

 

0 Kudos
Message 10 of 10
(2,790 Views)