LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using scripting to add and remove subVIs to another code programatically

Hi everyone,

 

I am using a QMH architecture for a project which can have a variable number of cameras attached to it. Is it possible to use API Scripting to add subVIs to the code when more cameras are required? 

 

In the picture I have my code so far, I'd want to duplicate the Camera Loop for however many cameras are required. If I made the whole loop a subVI would I then be able to place it using API scripting (or another method?) on this block diagram and connect it to the queue and the error?

 

I'm completely new to API scritping so it may not be a good thing to try and do, but if it's possible I'll give it a shot.

 

Many thanks

Pete

0 Kudos
Message 1 of 11
(3,757 Views)

I would not use scripting to change subVI's just to vary the number of cameras operating which you would consider a normal part of executing the code.  The subVI's would have to be in a non-running, and not in a position to be run in order to be edited.  Then you would have to asynchronously call them once the scripting is done modifying them.

 

The proper thing to do would be create a reentrant subVI that can be called multiple times.  Asynchronously call as many copies of that as you need.

Message 2 of 11
(3,729 Views)

Hi RavensFan,

 

What I've been thinking since posting is to have a non-running subVI that is close enough to a template of what I need each time a new camera is created. This can then be copied and pasted using scripting into the main VI, I'm looking into connecting the terminals now which is where it might fall down. I've attached an image showing the Camera(SubVI) which is copy pastable and the subVI that contains a script that copies it from that subVI and pastes it in the main VI. It will require me to move the camera control on the FP and the while loop on the BD to the correct positions and connecting the queue and error terminals but it looks promising.

 

Having a reentrant subVI, would that enable me to be able to view the images coming from the camera grab command? 

0 Kudos
Message 3 of 11
(3,725 Views)

Hello Woody

I can't answer your question, but I can offer two alternative ideas.

You could just spawn multiple instances of the VI that you attached and add an Input for a Camera "Object". Then you would have one QMH for each camera in an array of cameras.

Alternatively, your loops could acquire and process data from all cameras in an array. That way your data would be synchronized.

Regards

0 Kudos
Message 4 of 11
(3,722 Views)
Modifying code on the fly is exactly the wrong way to do what you are wanting to accomplish. The idea given earlier to launch multiple instances of the same reentrant VI is the way to go.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 11
(3,697 Views)

Thanks for the input guys,


The trouble I have with using a reentrant subVI is that I can't see the output of the IMAQ Grab.vi which would be called within the subVI and output it on seperate indicators on the front panel of the main vi. Alternatively have a single indicator that can switch between all the different cameras.

 

Is there a way to see indicators within a subVI with a while loop in it in the calling VI whilst it is running?**

 

Sorry if I'm being a complete noob with the reentrant VI, it's because I am ^^

 

Many thanks

 

**Edit: found this http://digital.ni.com/public.nsf/allkb/0F4EA104660C0AF38625726F0069B27E 

 

0 Kudos
Message 6 of 11
(3,682 Views)

You can pass a reference to an indicator into the subVI.  Use that with a property node in the subVI to update the indicator.

0 Kudos
Message 7 of 11
(3,670 Views)

Yes sorry, found the white paper just after posting that, thanks for the speedy response though!

 

I'll give it some more thought when I'm fresh tomorrow but I'm struggling to think how to display the different camera images using a single reentrant VI. some sort of array of cameras would be doable but then they wouldnt be able to be called simultaneously due to having to be indexed. A small time delay is undesirable but could probably be coped with as I'm applying a timestamp to each of the frames taken from the cameras.

0 Kudos
Message 8 of 11
(3,665 Views)
Yes, it's called subpanels. Tomorrow I'm posting something that might give you some ideas. The example uses nonreentrant VIs but the same basic technique works for reentrant ones as well.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 11
(3,664 Views)

Should I use a parallism for loop to run the subVIs on an array of cameras and then output to an array of IMAQ indicators?  Or would the subpanel idea be better? I can't get it working with a single indicator at the moment.

0 Kudos
Message 10 of 11
(3,623 Views)