cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 

accessing controls in another panel from a callback function

I think this is a simple question but I just can't seem to find an answer for it.  Here's my scenario:  I have two panels open, when the user changes a particular value in the second panel a graph is redrawn in the first panel.  A callback function is used to capture the value change in the second panel, and here is where my problem occurs... I get an error when I try to access the graph control in the first panel.  I have noticed that this problem occurs whenever I try to access another panel from a callback function which was called from a different panel.  In short, is there a way to access a panel (and its controls) from within a callback function which was called from another panel?  Thanks in advance!
 
-JR
0 kudos
Mensaje 1 de 17
5.139 Vistas

Hello JR,

In each function to access a control, the first two parameters are 'panel' and 'control'. The 'panel' parameter should be the handle you obtain from the LoadPanel or NewPanel functions. So if you want to access a control on a second panel, just make sure that you use the correct panel handle for the 'panel' parameter.

If you're still confused, just let me know and I'll explain some further...

0 kudos
Mensaje 2 de 17
5.123 Vistas

Hi Whim, thanks for the reply.  I understand what you are saying but I need some further clarification.  When a callback function is called from my second panel, I would like to alter content on BOTH the first and second panels.  Changing control values for the second panel works fine but unfortunately whenever I try to access content on the first panel (during the same function call) I get an error stating that the panel handle is invalid (or something like that).  Basically, it seems as if I am restricted to the controls on the panel in which the callback function was called.  Here is the error message I get:

NON-FATAL RUN-TIME ERROR:   "index.c", line 328, col 5, thread id 0x0000087C:   Library function error (return value == -4 [0xfffffffc]). Panel, pop-up, or menu bar handle is invalid

thanks,

-JR

0 kudos
Mensaje 3 de 17
5.119 Vistas

Hello JR,

accessing controls on another panel should not be a problem. Is it possible to post (or attach) some of your code?

0 kudos
Mensaje 4 de 17
5.118 Vistas
It sounds like you are trying to use the panel parameter passed into the callback to control the panels. This is fine, but only for the panel from which the callback was actually generated. If you want to address a control in a different panel you must use the global panel handle for that panel, not the one passed into the callback.
 
JR (jr_2005)
0 kudos
Mensaje 5 de 17
5.114 Vistas

Below, you will see some code for where I have identical looking toggle switches on two DIFFERENT panels for a poker timer/payout program.  If one gets toggled, I want to make sure that both switches toggle to show the same value.

This shows exactly want you are trying to do.  Hope it helps.

=====================

  if ((mainpanelHandle = LoadPanel (0, "Timer.uir", mainPanel)) < 0)
    return -1;
  if ((paypanelHandle = LoadPanel (0, "Timer.uir", PayPANEL)) < 0)
    return -1;

...
...

int CVICALLBACK Handle_Rebuy_Switch (int panel, int control, int event,
    void *callbackData, int eventData1, int eventData2)
{
  switch (event)
  {
    case EVENT_COMMIT:
      GetCtrlVal(mainpanelHandle,mainPanel_Rebuy_SWITCH, &Rebuy1);    
      GetCtrlVal(paypanelHandle,PayPANEL_Rebuy_SWITCH, &Rebuy2);
     
      // if already activated then it was switched off
      if (Rebuy_Taken)
      {  // so set both to off
        SetCtrlVal(mainpanelHandle,mainPanel_Rebuy_SWITCH, 0);    
        SetCtrlVal(paypanelHandle,PayPANEL_Rebuy_SWITCH, 0);
        Rebuy_Taken = FALSE;
      }
      else
      {  // set both to on
        SetCtrlVal(mainpanelHandle,mainPanel_Rebuy_SWITCH, 1);    
        SetCtrlVal(paypanelHandle,PayPANEL_Rebuy_SWITCH, 1);
        Rebuy_Taken = TRUE;
      } 
      Calculate_Payouts();

      break;
  }
  return 0;
}

0 kudos
Mensaje 6 de 17
5.109 Vistas
I keep going over my code and I don't see anything wrong with it.  Here's the function causing the problems:
 
panel1 = LoadPanel(0,"index.uir",MAIN);
panel2 = LoadPanel(0,"index.uir",SPEC);
 
......
 
int CVICALLBACK updateCutOff(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
 double dummyVar;
 
 switch(event)
 {
  case EVENT_COMMIT:
  case EVENT_VAL_CHANGED:
   GetGraphCursor(panel2,SPEC_GRAPH_FREQ,1,&cutOffFreq,&dummyVar);
   SetCtrlVal(panel2,SPEC_NUM_CUTOFF,cutOffFreq);
  
   if(filteredDataGraphed == TRUE)
   {
    double fs = 256.0 / (timeSpan / 1000.0);
    if(cutOffFreq != 0.0)
    { Bw_LPF(normalizedData,256,fs,cutOffFreq,10,filteredData); }
    
    SetCtrlAttribute(panel1,MAIN_GRAPH_WAVE,ATTR_NUM_CURSORS,0);
    DeleteGraphPlot(panel1,MAIN_GRAPH_WAVE,wavePlotHandle,VAL_DELAYED_DRAW);
    wavePlotHandle = PlotWaveform(panel1,MAIN_GRAPH_WAVE,filteredData,256,VAL_DOUBLE,1.0,0.0,0.0,((double)timeSpan/(double)255),VAL_THIN_LINE,VAL_EMPTY_SQUARE,VAL_SOLID,1,VAL_RED);
   }
  
   return 1;
  default:
   return 0;
 }
}
 
 
Appreciate all the help 🙂
0 kudos
Mensaje 7 de 17
5.095 Vistas
JR,
 
Are you perhaps using a strip chart for your second graph?  If so, this could be your problem as strip charts uses PlotStripChart and ClearStripChart functions and not PlotWaveform and DeleteGraphPlot functions.
0 kudos
Mensaje 8 de 17
5.090 Vistas

Hi Dave.  Nope, not using a strip chart.  I must say that this is very confusing, as it seems to work just fine for everyone else 😛

BTW:  i forgot to mention that the problem occurs when panel1 is called

-JR

0 kudos
Mensaje 9 de 17
5.087 Vistas

I would use debugger and check the value of panel1 when it gets assigned via the loadpanel command.

Then check it where it is giving you problems.  It could be that it is not loading properly (right name used, etc.?)

and, therefore, not assigning a valid integer number to it.  When you first reference that invalid (in the CVI handle numbering scheme, not the invalid integer scheme) number, it bombs.

My thoughts for now.......

0 kudos
Mensaje 10 de 17
5.077 Vistas