LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Initialization problem

Solved!
Go to solution

Hi,

This is my code:

 

int main (int argc, char *argv[])
{
int error = 0;

/* initialize and load resources */
nullChk (InitCVIRTE (0, argv, 0));
errChk (panelHandle = LoadPanel (0, "CVI GUI.uir", Panel));

/* display the panel and run the user interface */
errChk (DisplayPanel (panelHandle));
errChk (RunUserInterface ());

//initialize everything else
if(cycle == 0)           Initialize (Panel);
else                          ResetTextBox (Panel, tabPanel1_tbxSystemMessage_A, "not initialized");



Error:
/* clean up */
if (panelHandle > 0)
DiscardPanel (panelHandle);
return 0;
}

 

void Initialize (int panel)
{

srand(time (NULL));

 

//now enable timer
SetCtrlAttribute(panel, tabPanel1_tmrTIMER, ATTR_ENABLED, TRUE);

}//END Initialize()

 

I encountered 2 problems that I cannot fix at this time.  I use global variable 'cycle' as my cycle count, with the initial value of 0.  'cycle' is incremented by 1 each time the timer ticks.  In the Main() code, when it is zero, I call my Initialize() function.  However:

 

1.  The Inifitialize() function is never called.  The Timer is never enabled.

2.  The object referencing has problem.  This line:

 

ResetTextBox (Panel, tabPanel1_tbxSystemMessage_A, "not initialized");

 

has a problem with 'Panel' (a global object).  I try again with 'panelHandle,' and it still faults out.  Same thing with this line:

 

SetCtrlAttribute(panel, tabPanel1_tmrTIMER, ATTR_ENABLED, TRUE);

 

The passed 'panel' is incorrect so the timer is never enabled, but I do not know what is the correct one for it.  Anyone has any idea on how to fix it?

 

0 Kudos
Message 1 of 4
(4,392 Views)

To start with the second problem:

 

The correct function call is ResetTextBox ( panelHandle,... and not ResetTextBox ( Panel,...

 

For the same reason your Initialize function does not work, you should pass panelHandle as parameter, not Panel...

I would assume that your Initialize function is called but that the function call SetCtrlAttribute ( panel,... does not work because also SetCtrlAttribute expects a panel handle...

 

You may want to have a look at the help for these functions, too.

Message 2 of 4
(4,386 Views)
Solution
Accepted by topic author hn_sofec

I think I found the root of the problem.  These two lines:

 

errChk (DisplayPanel (panelHandle));
errChk (RunUserInterface ());

 

bring up the UI and the thread goes into it.  Anything done on the UI written after these two lines are not executed until the thread leaves the UI.  The Timer object only exists in the UI thread.  So, anything done to the 'panel' and the timer object must be inside the UI thread.  I have changed my code to get things done.  Anyways, thank you so much Wolfgang.

 

 

0 Kudos
Message 3 of 4
(4,383 Views)

You are perfectly right in your analysis... (sorry for sleeping)

Message 4 of 4
(4,381 Views)