01-02-2012 10:07 AM
Hello all,
Maybe a simple question for the LV gurus out there but I'm struggling with this.
I have a camera that I'm controlling via a functional global.
When I call the different functions everything works as expected as long as I make sure that the "exit camera" function is called as the last function. (which is normal)
If I do not call the "exit camera" function as last function (ie a user closed the vi with an abort or some critical error occured inside the code), it seems like the DLL keeps a handle open and I cannot access the camera anymore until I close down LabVIEW and I physically unplug the device from my system. When I plug it back in I can again use my camera normally.
Is there a way in LabVIEW that I can keep track of my camera to determine if it is still being used or not and correctly close it when nobody is using it anymore.
I guess with OO mechanisms it should be possible but since I've never used OO before with LabVIEW I was wondering if there was an alternative solution/mechanism/example I could look at.....
Thanks for all the help and suggestions!
Kirsten
PS: I know I can disable the 'abort' button from the VI ... I'm not looking for that answer 🙂
01-02-2012 10:57 AM - edited 01-02-2012 11:00 AM
Can you programatically determine if the camera is held in this state? Does it return some specific error? In your initialization code you could check for that error and call the exit camera function.
If by "abort" you are referring to the red stop sign then that is not good. That button should not even be visible. You should have your own abort button and call exit camera along with whatever else you need to do when it is pressed. If there is a critical error you should detect that and call exit camera in your error handling routine.
[Edit: I just noticed your PS. You "can" call abort programatically. Still not good but better. At least you have the opportunity to do things like call exit camera first]
01-02-2012 12:53 PM
Yes, exiting the camera via some error handling routine would be best in your situation. There is no fix for pressing the abort button on the tool bar unless you have your own button than can gracefully shut things down programmitcally. The abort button is a hard break (like Cntl-break) and really should only be used for debugging purposes, but you may know that already.
01-02-2012 01:04 PM
Have you tried calling the Exit Camera function when your code first starts running (before you attempt to open it)? Sometimes this approach works to clean up from a previous run that left it open. If the Exit function returns an error that indicates that the camera isn't open, it's safe to ignore.
01-02-2012 01:12 PM
@k_tunsten wrote:
If I do not call the "exit camera" function as last function (ie a user closed the vi with an abort or some critical error occured inside the code), it seems like the DLL keeps a handle open and I cannot access the camera anymore until I close down LabVIEW and I physically unplug the device from my system. When I plug it back in I can again use my camera normally.
Well, the VI knows if there is an error, so the code can take appropriate action if that occurs using proper error handling.
To deal with the user closing the VI, use a "panel close?" filtering event, discard it, exit the camera, then close the VI once everything is cleaned up..