LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why won't the program execute case EVENT_COMMIT: statement within the callback function?

When I run the project, once I click inside the frequency control, the program crashes. I set breakpoints withing the code and the case EVENT_COMMIT: is never executed. It hits the switch (event) and then goes directly to return 0. Why is this happening? (I've double-checked my control on the UIR panel and the control mode is set to "hot" as usual.)

int CVICALLBACK FREQUENCY (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
unsigned int fvco; //oscillator frequency
int fref=FSNOM; //reference frequency
int flag1;
double divn, divr=RNOM;

switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (PANEL, PANEL_FREQUENCY, &f
vco); //gets frequency
GetCtrlVal (PANEL, PANEL_GAIN, &s_cpgain); //gets gain value
flag1=1;
if((fvco<(FMIN/1e6))|(fvco>(FMAX/1e6))) flag1=0; //checks range of frequency

while(flag1==0);

fvco*=1e6; //converts freq to MHz
divn=MakeInteger(fvco/fref); //sets n divider
fvco=fref*divn; //recalculates frequency
GainAdjust(fvco); //function to set gain based on frequency input

FindData(divr, divn); //function to calculate structure elements
Build_NCL(ADF_NCL); //function to calculate elements of binary words

Display_PANEL_data(); //function to display data to panel

break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}
0 Kudos
Message 1 of 4
(3,320 Views)
When you click on a button you will get multiple events. The first one will be EVENT_LEFT_CLICK (3), then you should get an EVENT_COMMIT (1) next. Look at the value of the "event" variable and see what event you are getting. It is most likely a left-click and not a commit event. A left-click will not be followed by a commit unless the control is enabled and hot. I would check these two attributes (with GetCtrlAttribute) in the callback when you get the left-click event.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 4
(3,320 Views)
I looked at the "event" variable and it is a 1. I think I may be dealing with a larger problem however. I have two panels, each with a frequency input control. Originally, they both had the same constant name but different callback function names. When I changed one of the frequency constant names, the program would go into the case statement as desired. However, this revealed another problem in which the values are not being read from the controls using the GetCtrlVal (panel, panel_name, &variable). Are there some fundamental rules that I am violating when using multiple panels?
0 Kudos
Message 3 of 4
(3,320 Views)
You should never have the exact some constant name for two controls. Remember the constant name is going to be a combination of the PANEL constant and the control constant. So if you have two panels with constants PANEL1 and PANEL2, the constant names for one control in each panel can be the same, say BUTTON1 since they would translate to PANEL1_BUTTON1 and PANEL2_BUTTON1.

Your code above doesn't look right (GetCtrlVal(panel, panel_name, &variable). It should be GetCtrlVal(panelHandle, PANEL_CONTROL, &value) where panelHandle is the handle of the panel returned by LoadPanel, PANEL_CONTROL is the constant referring to the control, and value is a variable of the appropriate data type to hold the data from the control PANEL_CONTROL. If you
post your project, I could probably easily tell you what the problem is.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 4 of 4
(3,320 Views)