LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

what's the safe way to do initialization and finalization?

Solved!
Go to solution

Hi all,

  I have a thrid party driver for an external device to use in my CVI. I have to initialize the driver when the main panel is initialized and HAVE to release the driver upon the closing of the application. In my code, the main structure is something like

 

int main (int argc, char *argv[])
{
    char s[10];
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
<code removed by Moderator>

 

Here I put the code to initialize the driver before DisplayPanel and will release the driver at the end of the main function. I am wondering if this is safe and the right way to do that? The reason why I am asking is the external driver is so strange, if the application using that not release the driver properly, other application can't use it unless to reboot the system.

 

I search online and see someone to release the driver in the event EVENT_CLOSE of the main panel, is that better way to do the finalization here? If so, any function like EVENT_START or EVENT_INITIALIZATION so I can do some initialization there?

 

Thanks.

0 Kudos
Message 1 of 2
(3,244 Views)
Solution
Accepted by dragondriver

Hi Dragondriver,

 

It sounds like the person used event_close in order to close out the reference to the driver if the UI is exited. This makes sense. You could include both without a problem. For example, you could initialize and close out the reference to the driver in each subprogram or subroutine you write that uses the driver, in addition to automatically closing out any references to it if the UI is closed accidentally in the middle of a subroutine. This would be a good way to do it.

 

Regards,
Basil
Applications Engineering
National Instruments
0 Kudos
Message 2 of 2
(3,196 Views)