12-15-2008 08:40 AM
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;
}
12-15-2008 09:05 AM
Hi Steve,
Rather than launch in a new thread, have you tried a new execution.
Regards
Ray Farmer
12-15-2008 09:50 AM
12-16-2008 12:24 AM - edited 12-16-2008 12:25 AM
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
12-16-2008 08:10 AM
12-16-2008 08:37 AM
Hi Steve,
I post you a small example.
what TestStand and CVI versions are you using?
regards
Ray
12-16-2008 08:41 AM
12-16-2008 03:44 PM
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