11-05-2008 06:21 PM - edited 11-05-2008 06:28 PM
I have an array that I want to initialize from text file using a property loader step. I want the number of elements of the initialized array to be equal to the number of elements in the array in the text file. I tried to accomplish this by defining the TestStand array empty and importing all properties from the text file. This resulted in an error message for each property in the array - here's a snippet of the error messages:
Error evaluating expression:FileGlobals.Arinc629.Limits.Label[0].Address = (0xE90)
Property does not exist.
The text file I'm loading the properties from is attached. The properties are loaded successfully if I define the TestStand array with a size bigger or equal to the number of elements in the text file. But I want to have the text file to dictate how many elements are in the TestStand array. Is there a good way to do that?
Thanks,
Hans
11-05-2008 06:33 PM
Here's the limit file for the property loader step.
Hans
11-10-2008 08:07 AM
Hi,
The easiest way would be to have two property loads steps
One to load the size of the array.
Then set your array size using the SetNumberElements()
Then call the property loader again to load your data.
Regards
Ray Farmer
11-10-2008 02:57 PM
Thanks for the reply, Ray. I had thought of doing exactly that. There's a couple drawbacks though. First, I need a couple extra TestStand steps, not a huge deal. Second, whenever someone adds or deletes an array element in the limit file, they have to remember to update the array size. Seems like it could all be handled automatically by TestStand, which would make the user's code simpler and easier to maintain.
Hans
11-10-2008 03:51 PM - edited 11-10-2008 03:53 PM
Sorry, I accidently posted the same reply again.
Hans
11-10-2008 04:07 PM
No problem.
The other alternative would be to modify the PropertyLoader step type or generate a step type based on the PropertyLoader.
Regards
Ray
11-11-2008 10:20 AM
Thanks again for the reply Ray. You're on your way to 4000!
I could make my own step type, but it makes more sense for TestStand to automatically handle property loading a variable length array. Otherwise every user that wants to do that has to investigate and implement their own workaround. Better to have NI solve the problem once for everyone. Perhaps I'll submit a suggestion to NI.
Hans
11-11-2008 11:05 AM
11-11-2008 02:34 PM
Thank you John! I really appreciate NI looking into this enhancement and I bet other TestStand users will appreciate it as well.
Thanks again,
Hans
11-12-2008 10:44 AM
Hans,
What version of TestStand are you using?
Starting with TestStand 3.1 you can import/export arrays and containers as XML strings.
If
you want to be able to set the array bounds in the text file all you
have to do is to modify the LBound and HBound attributes in the
corresponding XML Prop tag and add the Value tags corresponding to the
elements you want to add.
For example.
Let's assume I have an numeric array local variable named MyArray (Locals.MyArray).
The first thing I would do is to use the Import/Export Properties tool to generate my text file.
1. Make sure that the Locals.MyArray variable is not empty (In my case Lower Bound =0 and Upper Bound= 9)
2. Go to Tools>>Import/Export Properties
3. Go to the Source/Destination tab and specify your text file location
4. Go to the properties tab and add Locals.MyArray to the selected properties list
5. Click the Export button
6. Open your text file and verify it looks as follows:
<Step Name>
<Locals> Variable Value
MyArray
<Prop Name='MyArray' Type='Array' LBound='[0]' HBound='[9]'
ElementType='Number'><Value ID='[0]'>0</Value><Value
ID='[1]'>0</Value><Value
ID='[2]'>0</Value><Value
ID='[3]'>0</Value><Value
ID='[4]'>0</Value><Value
ID='[5]'>0</Value><Value
ID='[6]'>0</Value><Value
ID='[7]'>0</Value><Value
ID='[8]'>0</Value><Value
ID='[9]'>0</Value></Prop>
<FileGlobals> Variable Value
<StationGlobals> Variable Value
7. In my case I only exported the Locals.MyArray variable
8. Notice that the Value of the Locals.MyArray variable is a XML string that contains a Value tag for each element in the array.
9. If I want to change the number of elements in the array next time I import the text file, I only have tp modify the LBound and HBound attributes and add or remove the value tags for the array elements.
10. Let's say that I want my array to have only one element, then I need to set the value of HBound to 0 and get rid of the Value tags corresponding to the rest of the elements.
<Step Name>
<Locals> Variable Value
MyArray
<Prop Name='MyArray' Type='Array' LBound='[0]' HBound='[0]'
ElementType='Number'><Value
ID='[0]'>0</Value></Prop>
<FileGlobals> Variable Value
<StationGlobals> Variable Value
11. Modify your text file and use the Import/Export Properties tool or the property loader step to import the text file
12 . Verify that the array bounds are modified
You could use this technique to initialize an empty array using the property loader.
Hope it helps.
Regards.