02-27-2012 06:42 PM
I want to work with real time sequences using some of the events available in the VS LabVIEW API, such as the Sequence Complete Event.
Taking a peak inside the VI, one can see that the event is registered like shown below using a call to the RegEvents:
The catch, is that my main application already makes use of a RegEvent calls for other user events, and it is set like shown below:
The 2 user events: Data_Input and Data_Parameters are the ones already defined for other tasks. I added a constant into the third event as a placeholder for the Sequence Complete Event... This constant was obtained from the API VI so it is the right type. However, I fail to see how to "join" the two sets of events... the only way out I can see right now is to modify the VS API vi, so that its event registration is done on a new set of registration already including the 2 initial events.... All examples I found, operate on a pre-established set of events, but none seems to show how to add extra events....
Isn't there a way to register user-events with separate calls to Reg Events ?
Thx,
L.
02-27-2012 07:59 PM - edited 02-27-2012 08:00 PM
Possible approach here ..? : registering each user event that is created with a seperate Register For Event then bundle the output event registration numbers into a cluster.
L.
02-27-2012 09:03 PM
02-27-2012 09:04 PM
02-28-2012 11:41 AM - edited 02-28-2012 11:43 AM
Ok, so it looks like this :
with B the actual RT Sequence "Sequence Completed Event" registration # and A another event that will be used
to actually register the "Sequence Completed Event"
The A event is dealt with as below:
Only when the "Sequence Completed Event" is registered, it can be captured with another event case like:
Now the problem I am having is this:
Session Ref is retrieved from a VI launched with VI Server that sets the rt sequence's parameters (rtsequence.vi say) . rtsequence.vi is more or less like the one we talked about here: It takes advantage of the VS API to set the real time sequence parameters and channels, and creates the Session Ref. Instead of starting the sequence in it, now I want to pass the Session Ref to the main VI, which then deals with it adding the Completion Event.
What I am running against is that Session Ref remains valid only as long as rtsequence.vi runs. Which is the problem, because rtsequence.vi only initiates the rt sequence session and then completes since nothing left to do in it, which in my main.vi creates an error where Session Ref is retrieved in the event structure, as it appears to be no more valid....
Any idea?
thx
L.
02-28-2012 08:44 PM
What you are seeing is part of LabVIEW's regular behavior. When a top-level VI that was running goes idle, it automatically cleans up any references it opened, including .NET references such as the session object. It is pretty difficult to work around this.
The first question I would ask is whether this VI you're launching via VI Server can't be called as a regular subVI instead. That would prevent the references it was creating from being cleaned up.
If you can't do that, there's one option I can think of using the VeriStand API to help out. This rtsequence VI that creates the session ref that is launched via VI Server currently doesn't seem to be deploying the sequence session, correct? It just creates the session and sends it via an event to another VI that is supposed to start the session?
If that is the case, you can slightly modify your workflow and keep the same functionality. Try modifying your workflow as follows:
1. Have the rtsequence VI deploy the sequence session, but set the auto-run flag to false. This deploys all the data, but doesn't start running the sequences.
2. Instead of sending the session ref via the event from the rtsequence VI, send the deployed session ID string. Rtsequence.vi can go ahead and close its session ref.
3. Have the VI that receives the event open its own reference to the session using the session ID and the API function to open a reference to a deployed session.
4. Update this VI to simply call Run on the already-deployed session instead of deploying it.
This trick will work in your case (if I understand it correctly) because each top-level VI (sender and receiver) opens its own independent .NET reference to the session, so it doesn't matter if the original session ref gets closed.
02-28-2012 09:00 PM
I think I understand what you mean, and it should work, since the sequences would be managed based on names like you indicate. Thx! I will try this next week and report back.
The reason the rtsequence.vi are called dynamically is because they are front-ends for rtsequence.nivsseq files. Same name, different extension. Similarly, they are associated with a rtsequence.ini that contains several set of parameters and channels to be used by that sequence that can be identified by sections...
The other option I will look into and compare with your suggested approach is to launch the rtsequence.vi asynchronously and have all the sequence management done by the VI itself rather than to defer to the main.vi... This way I can choose between "run and collect" or "run and forget" depending on the case...
Thx.
Laurent