NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem to read values from configuration file and assign the value to FileGlobals in Teststand

I had hard time to read a configuration file and put the read values to the corresponding FileGlobals in Teststand. Does anyone guide me how to implement it?
 
I attached 4 files:
- one seq file which has FileGlobals.ip1, FileGlobals.ip2, etc defined as string. The sequence file reads the configuration file and tries to assign the read IP address to FileGlobals.ip1, FileGlobals.ip2, etc. FileGlobals.ip1 (etc) are defined as 135.x.x.x in the sequence file.
- two vi files to read key and corresponding values from the configuration file
- one configuration file, which includes a few IP addresses (ip1=135.39.62.16, ip2=135.39.62.17, etc)
 
In my example, I used the same name in FileGlobals and configuration file (ip1, ip2, ip3, ip4 and ip5 in both files), in order to use them as index to put their values to FileGlobals.
 
After I run the sequence, I expect to see that FileGlobals.ip1=135.39.62.16, but it is still 135.x.x.x, though test and test1 array got the values I expected.
 
Xuedong
P.S: I can not attach more than 3 files, but here is the content of station_config.txt file:
 
[Station_config_parameters]
ip1=135.39.62.16
ip2=135.39.62.17
ip3=135.39.62.18
ip4=135.39.62.19
ip5=135.39.62.20
 
0 Kudos
Message 1 of 11
(4,180 Views)

Hi,

Are you expecting the new values from your configuration files to be stored in the FileGlobals after you sequence has stopped executing?

If you are, then you are only changing the runtime version of the fileglobals.

You have to place them in the FileGlobalDefaults. Then set the change Increment to indicate that the sequencefile has changed.

Regards

Ray Farmer

Regards
Ray Farmer
Message 2 of 11
(4,175 Views)
Hi, Ray,
 
Thank you for your quick response and help. Maybe I did not describe my question clearly. Let me re-phrase my question.
 
I have Locals.INIFILE_Key=ip1, which is read from configuration file as the key of the 1st line. Also,
I have Locals.Script_INIFILE=135.39.62.16, which is read from configuration file as the value of the 1st line.
I want to use both Locals.INIFILE_Key and Locals.Script_INIFILE to set FileGlobals.ip1.
 
I know that I can use FileGlobals.ip1=Locals.INIFILE_Key to reach my goal. However, I am wondering if there is a certain way in Teststand to allow me to use Locals.INIFILE_Key as variable to set corresponding element of FileGlobals. Something like:
 
FileGlobals.(Locals.INIFILE_Key) = Locals.Script_INIFILE
 
As you can tell, I got error message for the above statement. If I could use the above statement (or modified statement), I would not need to make any changes in Teststand sequence, even though I modify (delete or add lines) the configuration file.
 
I am attaching one solution, and am wondering if this can be improved by using Locals.INIFILE_Key as variable to set corresponding element of FileGlobals.
 
Regards,
Xuedong
0 Kudos
Message 3 of 11
(4,153 Views)
Hey Xuedong,
 
You can't just create FileGlobals like that.  You need to have it created before you try to assign it a value. 
 
If you want to create the variable dynamically you would need to use the TestStand API and ActiveX steps to create it.
 
1. Choose ActiveX Adapter
2. Place an action step
3. Specify module
4. Type: FileGlobals as the Object Reference
5. Choose: NI TestStand API 3.X as your engine
6. Choose: PropertyObject as your Object Class
7. Choose: Method as your Action
8. Choose: NewSubProperty as your Method
9: Refer to the help for information about the parameters for this method call.
10. Your lookupString will be Locals.INIFILE_Key
 
Then in the next step you can assign it to a value.
 
NOTE: This variable will only be available during runtime as Ray mentioned above.
 
Hope this helps you get on the right path.
 
Regards,
jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 4 of 11
(4,139 Views)
Hi Xuedong,
 
I think Sam Is being a little harsh with you.
The information is he gave you is correct, but there is nothing wrong with your statement FileGlobals.ip1 = Locals.test1[Locals.loop_count++], it will work to change the value of your Runtime version (only).
If you actually want to change the static version of the variable you need to use RunState.SequenceFile.Data.FileGlobalDefaults.ip1 and also increment the value of RunState.SequenceFile.ChangeCount.
 
Whats wrong with the way you are doing things (FileGlobals.ip1 = Locals.test1[Locals.loop_count++]), when your count reaches 9 you will get an error because you can increase the size of you array with this statement. Likewise with your FileGlobals, you really need to create the variable dynamical as will.
It would have been better to start off with you arrrays empty and using the API call PropertyObject.SetValStringByOffset() with the option parameter set to 1 and using the loop count as the array offset for you Locals.test1 array.
Likewise you could have created your FileGlobals variable by creating your lookup string as "FileGlobals.ip"+Str(Locals.loop_counter) and using the PropertyObject.SetValString method again using the value of 1 for the options. With Options set to 1, this will create the property if it doesn't exist.
 
Hope this helps
Regards
Ray Farmer
Regards
Ray Farmer
Message 5 of 11
(4,134 Views)

Hi, Sam,

Thank you for your guidance.

I tried your suggestion, but am still not able to make it work. Checking your suggested procedure, I feel that maybe I did not put right parameters for the method call in your step 9. I am attaching the sequence I modified, and am wondering if you have any idea about what is wrong with it. I got the error message "the item name ip1 is invalid, because it is already in use" when runing the sequence.

To be honest, I am not sure if I understand the NewSubProperty. Do you know if there is any example for me to read? That would help me a lot to understand how to use NewSubProperty.

Also, you mentioned that "Then in the next step you can assign it to a value". How do I assign a value to it? Something like, FileGlobals.lookupString = Locals.Scripts_INIFILE?

Regards,

Xuedong

0 Kudos
Message 6 of 11
(4,126 Views)

Hi, Ray,

Thank you again for your help.

I do feel that I am lack of the knowledge for API/PropertyObject kind of things, after reading your suggestions. Let me study a little bit and see if I can follow what you suggested.

Regards,

Xuedong

0 Kudos
Message 7 of 11
(4,125 Views)

Thanks for keeping me honest Ray.

I misread the question.  I've attached your sequence with what I believe you are looking for. 

Basically I call an activex step like Ray described above that will allow you to select your variable dynamically. 

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 8 of 11
(4,116 Views)

Hi, Sam,

I am eager to read your attached file, but I can not. I got error message. I am using TS 3.1, which is incompatible with TS 3.5. Is there any way to allow me to read your sequence?

Regards,

Xuedong

0 Kudos
Message 9 of 11
(4,105 Views)

Sorry Xuedong,

Here are two images that show what I did.  Basically there is an ActiveX step in the loop that and then I show the specify module for that activex step.

Regards,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Download All
0 Kudos
Message 10 of 11
(4,100 Views)