From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add a type to the type palette through the sequence

I'm using teststand 3.1 and CVI 7. I need to load a custom ini file to the type palette from my Root directory and probably need to have the sequence file call this action also. How can I do this?
 
I noticed the calls SetTypePaletteFileList and LoadTypePaletteFilesEx . I think these functions will do what I want but have no clue how to use them. I tried using them in CVI, but ran into problems with the data types.
 
HRESULT CVIFUNC TS_EngineGetTypePaletteFileList (CAObjHandle objectHandle,
                                                 ERRORINFO *errorInfo,
                                                 SAFEARRAY **typePaletteFiles);
How can I accomplish the simple task of having the palette read an ini file from my root directory? Thanks.
 
 
 
 
0 Kudos
Message 1 of 6
(3,980 Views)
The easiest way is to just add the type palette in your Sequence Editor.  Once you save this list, it will automatically load this type palette and save it when you close TestStand.
 
If you wish to create a sequence programatically and need the type palette, you can call LoadTypePaletteFilesEx.
 
If you need to add the file programatically, you will need to call, Engine.NewPropertyObjectFile(FileType_TypePaletteFile), PropertyObjectFile.Path = pathToIniFile, Engine.GetTypePaletteFileList, add the PropertyObjectFile you created to the list that is returned, and then call Engine.SetTypePaletteFileList.  You then can call LoadTypePaletteFilesEx.
 
In CVI, the file list is returned to you as a SAFEARRAY *.  To manipulate it, you can use the CA_SafeArray functions in CVI.  The type of the array will be CAVT_OBJHANDLE.  You can use the CA_SafeArrayTo1DArrayEx method to convert this to an array of CAObjHandle (CAObjHandle *).  You will then need to create a new CAObjHandle array that consists of all of the previous elements plus the PropertyObjectFile you created.  Then you can build a new SAFEARRAY using CA_Array1DToSafeArray, and pass this back to TestStand.
 
Adding the file programatically is quite a bit of extra work in CVI, so if you can just add it in the SequenceEditor, it will be done for you.  Otherwise, you can use the method described above.
 
 
Allen P.
NI
0 Kudos
Message 2 of 6
(3,974 Views)
Allen,
 
"If you need to add the file programatically, you will need to call, Engine.NewPropertyObjectFile(FileType_TypePaletteFile), PropertyObjectFile.Path = pathToIniFile, Engine.GetTypePaletteFileList, add the PropertyObjectFile you created to the list that is returned, and then call Engine.SetTypePaletteFileList.  You then can call LoadTypePaletteFilesEx."
 
How do I do this step
PropertyObjectFile.Path = pathToIniFile
When I try doing it through activex I only have the parameter newValue. How do I specify which object I am setting the value for one? How do I append it to the array obtained from Engine.GetTypePaletteFileList?
 
Would you have an example that I might be able to download? Thanks.
 
Steve
 
 
 
0 Kudos
Message 3 of 6
(3,950 Views)

Here is a TestStand Sequence to show the concepts.  In CVI, if you are creating the engine from scratch, you will need to call Engine.LoadTypePaletteFilesEx before you call GetTypePalleteList.

For the following property: PropertyObjectFile.Path, you can do this in CVI by:

 TS_PropertyObjectFileSetPath (newFile, NULL, "c:\\test.ini");

To append the array, you will have to allocate a new array that is large enough to contain all of the elements, copy each element over, and append yours to the end of the list.

Hope this helps!

Allen P.

NI

0 Kudos
Message 4 of 6
(3,921 Views)

Here is some very crude CVI code that does the same thing.  I am not checking for memory leaks or other considerations, but it should show you the basic method that you will need to follow:

 int error = 0;
 int i = 0;
 ERRORINFO errorInfo;
 ErrMsg errMsg;
 unsigned int numElems;
 LPDISPATCH dispatchElem; 
 LPDISPATCH * newFileListAsHandle;
 CAObjHandle * fileListAsHandle;
 SAFEARRAY *fileList;
 CAObjHandle engine, newFile;
 
 errChk (TS_NewEngine ("", &engine));
 tsErrChk (TS_EngineLoadTypePaletteFilesEx (engine, &errorInfo,
          TS_ConflictHandler_Error, 0));
 tsErrChk (TS_EngineNewPropertyObjectFile (engine, &errorInfo, 2,
         &newFile));
         
 tsErrChk (TS_PropertyObjectFileSetPath (newFile, &errorInfo, "c:\\test.ini"));
 tsErrChk (TS_EngineGetTypePaletteFileList (engine, &errorInfo, &fileList));
 errChk (CA_SafeArrayTo1DArrayEx (&fileList, CAVT_OBJHANDLE, 0,
        &fileListAsHandle, &numElems));
 newFileListAsHandle = malloc(sizeof(LPDISPATCH) * (numElems + 1));
 for(i = 0; i < numElems; i++)
 {
 
  CA_GetDispatchFromObjHandle (fileListAsHandle[i], &dispatchElem);     
  newFileListAsHandle[i] = dispatchElem;

 }

 CA_GetDispatchFromObjHandle (newFile, &dispatchElem);     
 newFileListAsHandle[numElems] = dispatchElem;   
 errChk (CA_Array1DToSafeArray (newFileListAsHandle, CAVT_DISPATCH, numElems+1,
           &fileList));
 tsErrChk (TS_EngineSetTypePaletteFileList (engine, &errorInfo, fileList));
 tsErrChk (TS_EngineUnloadTypePaletteFiles (engine, &errorInfo));
 tsErrChk (TS_EngineLoadTypePaletteFilesEx (engine, &errorInfo,
              TS_ConflictHandler_Error, 0));
 tsErrChk (TS_EngineShutDown (engine, &errorInfo, VTRUE));
       

0 Kudos
Message 5 of 6
(3,915 Views)

In case someone need an TestStand sequence, that programatically adds Type Palettes - check the attachment.

 

0 Kudos
Message 6 of 6
(3,048 Views)