NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Leave RunUserInterface running

I would like to leave a CVI uir gui with callbacks enabled running in the background as I run through the rest of the steps in my sequence. I tried calling RunUserInterface in a second thread. The UIR window stays open, but the controls cannot be clicked after the main thread ends. How can I run a GUI in the background?

 

int sdb_panel_handle;
int thread_id;

int CVICALLBACK ThreadFunction (void *functionData) {
   int local_err;

   local_err = RunUserInterface ();

   return 0;
}


int CVICALLBACK quit_callback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    int local_err;
    switch (event)
    {
        case EVENT_COMMIT:
            local_err = HidePanel (sdb_panel_handle);
            local_err = QuitUserInterface(sdb_panel_handle);

            break;
    }
    return 0;
}

void __declspec(dllexport) LoadGui(void)
{
   int local_err;


   sdb_panel_handle = LoadPanelEx (0, "sdb_gui.uir", PANEL, __CVIUserHInst);
   local_err = DisplayPanel (sdb_panel_handle);


   CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction, NULL, &thread_id);
  
   return; 
}

0 Kudos
Message 1 of 8
(3,419 Views)

Hi Steve,

 

Rather than launch in a new thread, have you tried a new execution.

 

 

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 2 of 8
(3,417 Views)
How do I create a new execution?
0 Kudos
Message 3 of 8
(3,415 Views)

Hi Steve,

 

Run the step that calls LoadGUI in a SequenceCall that has been set to run in New Execution. Set the Sequence to return immediately.

You will probably need a Wait step in the cleanup of your MainSequence to wait for this new execution to complete, i.e. you have quit from the GUI.

 

I think your code needs to look something like the following. I have commented out the CmtScheduleThreadPoolFunction as I dont think you need it unless off course your GUI is running several threads.

 

//int sdb_panel_handle;
//int thread_id;

//int CVICALLBACK ThreadFunction (void *functionData) {
//   int local_err;

//   local_err = RunUserInterface ();

//   return 0;
//}


int CVICALLBACK quit_callback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    int local_err;
    switch (event)
    {
        case EVENT_COMMIT:
            local_err = HidePanel (sdb_panel_handle);
            local_err = QuitUserInterface(sdb_panel_handle);

            break;
    }
    return 0;
}

void __declspec(dllexport) LoadGui(void)
{
   int local_err;


   sdb_panel_handle = LoadPanelEx (0, "sdb_gui.uir", PANEL, __CVIUserHInst);
   local_err = DisplayPanel (sdb_panel_handle);

   local_err = RunUserInterface ();

//   CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction, NULL, &thread_id);
  

   DiscardPanel(sdb_panel_handle);
   return; 
}

 

Regards

Ray Farmer

Message Edited by Ray Farmer on 12-16-2008 06:25 AM
Regards
Ray Farmer
0 Kudos
Message 4 of 8
(3,396 Views)
How do I create a new execution?
0 Kudos
Message 5 of 8
(3,388 Views)

Hi Steve,

 

I post you a small example.

 

what TestStand and CVI versions are you using?

 

regards

Ray

Regards
Ray Farmer
0 Kudos
Message 6 of 8
(3,382 Views)
TestStand 4.0 CVI 8.0
0 Kudos
Message 7 of 8
(3,380 Views)

Hi Steve,

 

Here is an example, one for New Execution and  one for New Thread.

Unfortunately I haven't got CVI 8.0 but I have saved the GUI file to CVI 8.0 format and hopefully you can rebuild the project. Basically its using your code you posted in your post.

The SequenceFiles should be at version 4.0 so you can see the step setups.

 

Hope this works for you.

 

Regards

Ray Farmer 

Regards
Ray Farmer
0 Kudos
Message 8 of 8
(3,367 Views)