07-16-2009 03:00 AM
Hi,
I'm new to TestStand. I would like to be able to read an environment variable and place within a TestStand 3.5 'locals' variable
Can this be done? If so, how?
Thanks
Alan
07-17-2009 06:37 AM
Hi Alan
I have not used the enviroment variables before but am assuming you will use the windows api function GetEnvironmentVariable to return the value of the variable you want. This api call would be done in a code module from the IDE of your choice, with the variable string defined as an output of the module.
Make sure that you have created a new string variable in the locals container. The next step would be to insert an action step into your TestStand sequence with the code module refered to above specified. You do this by clicking 'Specify Module...' ontthe General tab of the action step properties.
Once the code module has been specified, TestStand will allow you to configure the parameters that define how the data is passed in and out of the code module.All you need to is enter "Locals.*name of your local variable*" in the 'Value for the parameter, this will tell TestStand to immediately store the value from your code module in the local variable. See the image below.
I hope this helps, let me know if you have any more questions.
Rich
NI | UK
07-17-2009 01:28 PM
It's actually even easier than that. You can call the Windows API directly from TestStand by calling into the dll that hosts the function you want to use. In this case, the dll is Kernel32.dll.
Simply use the C/C++ Adapter and point to that file. You will need to define the function prototype yourself, but if you find the Microsoft documentation for the API you want to use, this is usually easy.
Here's a step set up to read an environment variable, and return its value (up to 1024 characters).
One other note is that many Windows API functions have a post-fix of A or W. The A stands for ASCII and the W for Unicode. In Visual Studio, the compiler automatically chooses which one to use, but if you call into the DLL directly, you get the choice of which one to use. If your environment variable is ascii text, you can use the A version, but if it contains unicode text (for instance, on a non-english version of Windows) you should use the W version.
07-18-2009 12:25 AM