NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand freezes when calling user interface

Solved!
Go to solution

Hi,

 

I've done a bit of seraching but the problem I'm having is to intermittant for any of the posts I've found to be helpful. I have a user interface built in CVI that is called as the edit-time portion of a step type. When I call the user interface multiple times in a row (same step over and over) TestStand eventually freezes. Sometimes I get error messages, most of the time it just locks up. When it does throw and error it is usually a .NET one. I've gotten this message before "object reference not set to an instance of an object", as well as system level exceptions. I'm unable to figure out exactly what is causing it. I've posted my code below. If I comment out either one of the two bold sections no error occurs. Also, if I don't change the selected parameter in the user interface between calls to the UI I never have it freeze. So it definitley has something to do with populating/setting the ring control or else reading the "ThisContext.Step.ConfigProperties.ParameterID" property from TestStand. If I get any more descriptive errors I will update this post.

 

Code:

----------------------------------------------------------------------------------------------------------------------------------------------------

void __declspec(dllexport) __stdcall ReadParameterTSEdit(CAObjHandle seqContextCVI, char reportText[1024], short *errorOccurred, long *errorCode, char errorMsg[1024])
{
    ErrMsg errMsg = {'\0'};
 int hpanel;
 int run;
 int index;
 int count;
 int numParams;
 char paramIDs[100][64];
 char param[64];
 char indexparam[64];
 char *ActCntrlTLA = NULL;
 char *temp = NULL;
 char activecntlr[23] = "Active Controller: ";
 VBOOL CntrlExists;
 TSObj_Property paramids = NULL;
 TSObj_PropertyObjectFile propObjFile;
 CAObjHandle seqfileobj;
   
    //Check that the system has been initialized and a profile has been loaded!
 TS_PropertyExists (seqContextCVI,NULL,"ThisContext.FileGlobals.ActCntrlTLA", 0,&CntrlExists);
 if(!CntrlExists)
 {
   MessagePopup("Read Parameter", "No profile has been loaded for this sequence!");
   goto Error;
 }
 TS_PropertyGetValString(seqContextCVI,NULL,"ThisContext.FileGlobals.ActCntrlTLA",0,&ActCntrlTLA);
 // Initializes Read Parameter UI 
 hpanel = LoadPanelEx(0, "ReadParamUI.uir", READ_PARAM,__CVIUserHInst );
 
 TS_PropertyGetPropertyObject(seqContextCVI,NULL,"ThisContext.FileGlobals.ParamIDs",0,&paramids);
 TS_PropertyGetNumElements (paramids,NULL,&numParams);
 
 for(count = 0; count < numParams; count++)
 {
     TS_PropertyGetValStringByOffset (paramids,NULL, count, 0, &temp);
     strcpy(param,temp);
     InsertListItem(hpanel,READ_PARAM_PARAMETERS,count,param,count);
 }

 // Build active controller string
 strcat(activecntlr,ActCntrlTLA);
 SetCtrlVal(hpanel,READ_PARAM_ACTIVETLA,activecntlr);
 
 TS_PropertyGetValString(seqContextCVI,NULL,"ThisContext.Step.ConfigProperties.ParameterID",0,&temp);
 strcpy(param,temp);
 for(count = 0; count < numParams; count++)
 {
  GetLabelFromIndex(hpanel,READ_PARAM_PARAMETERS,count,temp);
  strcpy(indexparam,temp);
  if(strcmp(indexparam,param) == 0)
  {
   SetCtrlIndex(hpanel,READ_PARAM_PARAMETERS,count);
   goto Done;
  }
 }
Done:  
 
 // Display the panel and run the UI
 // Does not return until from RunUserInterface until
 // the "done" button is pressed
    DisplayPanel (hpanel);
    run = RunUserInterface ();
 // Get index of selected parameter
 if(run < 1)
 {
  GetCtrlIndex(hpanel,READ_PARAM_PARAMETERS,&index);
  GetLabelFromIndex(hpanel,READ_PARAM_PARAMETERS,index,param);
  TS_PropertySetValString(seqContextCVI,NULL,"ThisContext.Step.ConfigProperties.ParameterID",0,param);
 }
 
Exit:
    /* Free resources and return */
    DiscardPanel (hpanel);
 TS_PropertyGetPropertyObject(seqContextCVI,NULL,"ThisContext.RunState.SequenceFile",0,&seqfileobj);
 TS_SeqFileAsPropertyObjectFile (seqfileobj, NULL, &propObjFile);
 TS_PropertyObjectFileIncChangeCount (propObjFile,NULL);
 if(&ActCntrlTLA)
 {
  CA_FreeMemory(ActCntrlTLA);
 }
 if(&temp)
 {
  CA_FreeMemory(temp);
 }
  if(&paramids)
 {
  CA_DiscardObjHandle(paramids);
 }
 CA_DiscardObjHandle(propObjFile);
 CA_DiscardObjHandle(seqfileobj);
 
Error:
}


/*---------------------------------------------------------------------------*/
/* Callback functions                                  */
/*---------------------------------------------------------------------------*/

int  CVICALLBACK Done(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
 if (event == EVENT_COMMIT)
 {
  QuitUserInterface (0);
 }
 return 0;
}

int  CVICALLBACK CLOSEPANEL(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)  
 {
  if (event == EVENT_COMMIT)
 {
  QuitUserInterface (1);
 }
 return 0;
 }

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Thanks,

 

Josh

0 Kudos
Message 1 of 3
(3,535 Views)

Also should mention that the most frequent error I get is complaining about trying to write to protected memory, will try to get the exact text.

 

 

0 Kudos
Message 2 of 3
(3,532 Views)
Solution
Accepted by topic author JoshM77

The problem was with this line:

 GetLabelFromIndex(hpanel,READ_PARAM_PARAMETERS,count,temp);

 

I should not have been passing it temp to write the label to as I had previously been using temp with TS API functions. Should have caught that before posting...but it's been a long day.

 

0 Kudos
Message 3 of 3
(3,530 Views)