NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

NI teststand 2017 - Python Integration

Hi,

 

I've just started working with some simple Python Integration using Teststand 2017. I have tried using a couple of different ways to do this.

 

1. Using the Call executable to call the python function and pass arguments to it. I have a few queries about this option.

  • One of these python functions is returning several values and I'm struggling to display each one of these. Only the last one in the list is displayed

Example:

In expressions under Properties I have added some result structure:

 

Locals.ID =
Val(
Mid(
Step.StdOutput.Text,
Find(Step.StdOutput.Text, "ID: ") + Len("ID: "),
Find(Step.StdOutput.Text, "\n", Find(Step.StdOutput.Text, "ID: "))
- (Find(Step.StdOutput.Text, "ID: ")) + Len("ID")
)
),
Locals.Sup =
Val(
Mid(
Step.StdOutput.Text,
Find(Step.StdOutput.Text, "Sup: ") + Len("Sup: "),
Find(Step.StdOutput.Text, "\n", Find(Step.StdOutput.Text, "Sup: "))
- (Find(Step.StdOutput.Text, "Sup: ")) + Len("Sup")
)
)

In the standard Output/Error, I have selected Store in Variable/Property and Set the Output to Step.StdOutput.Text.

In the Additional Results section I have added Standard Output and Custom placeholders for ID and Sup. As I said I only get Sup being populated. Is there any way to have Standard Output placeholders for each value returned from the function?

 

2. I have also tried Adding Python step action and running the script this way. I can't seem to find a way to reload the Python function after changes have been made. The Sequence file still seems to run the function as before and hasn't picked up on the changes made. Also, are there any good working examples of the different python options available to give a better understanding of how they work: Python Step - Action, Python - String Value Test etc.

 

Apologies on the long winded post!

Any help would be greatly appreciated

 

Regards.

0 Kudos
Message 1 of 7
(3,568 Views)

SLat105,

I will be focusing only on your second question in this reply.

 

When you use python step types in TestStand 2017, the default option of the interpreter session to execute the python code is 'Global'. Global means the, the lifetime of the session is determined by the lifetime of the process itself (unless you explicitly unload it). Also, in python, once you import a module, even if you make changes to the file, if you try to import the same module again, python will use the already imported module.

 

With the above information, I can see two ways of making sure that whenever you execute sequence file, latest changes for your python module are taken:

  • For all the python steps, choose the python interpreter session to 'Per Execution'. This will ensure that all the python modules are imported in a session which is created per TestStand's execution. OR
  • Before starting your execution, use File >> Unload All Modules to make sure that next time you use 'Global' interpreter session, a new session will be used.

 

Python custom step types installs examples under <TestStand_Public>\Examples\Custom Step Types\Python directory. You can use those to have better understanding of python custom step types.

 

Note: TestStand 2019 has introduced Python adapter which has better python integration with TestStand, compared to python custom step types. I suggest you to evaluate TestStand 2019 too.

 

-Shashidhar

Message 2 of 7
(3,496 Views)

Hi,

 

Thanks for the suggestions. I'm now running on teststand 2019. I'm still however having an issue with returning more than one value from my python function.

 

When I run the python function just using command line, I can see both results being returned successfully. When I run the python function through teststand, I only get the first value displayed. I have tried configuring my Locals as containers and adding a numeric value for each one. I've also tried setting the return value of the python function as a tuple. Here I added both Locals and left a comma in between. Are there any other things I need to configure on the teststand side? 

 

Thanks.

 

 

0 Kudos
Message 3 of 7
(3,472 Views)

You don't need to do any other configuration for that to work properly. I have attached an example which shows the following:

  • Pass a container (containing three number) to python as tuple
  • Return a tuple (containing three number) from python and store it in a container

In Python adapter options (Configure >> Adapters >> Python), make sure you have enabled 'Display Console for Intepreter Sessions' before executing the sequence file because the container which is passed to python as tuple will be displayed in the console.

 

I couldn't reproduce the case where you are returning multiple values (inside a tuple) and its not reflected in TestStand. Can you share an example of that.

 

-Shashidhar

Message 4 of 7
(3,455 Views)

Hi Shashidhar,

 

Thanks for your suggestions. I used your example which worked well and now I've been able to use a similar layout in my sequence by returning integer values into a container which I can then do numeric limit tests on. Super job!

 

Do you think there's need for me to post my particular example here as your tuple example seems to cover this well.

 

Best Regards.

0 Kudos
Message 5 of 7
(3,438 Views)

Thanks. Also, if your intention is to do numeric limit test for each of those numbers, other alternative is to return an array of numbers from python, which can be stored as array of number in TestStand, and you can use one multi-numeric limit step.

 

Regarding posting your example:

If you think that there is an issue with TestStand because of which data was not being returned properly, then I request you to post your example so that, I can file a bug.

 

-Shashidhar

0 Kudos
Message 6 of 7
(3,423 Views)

Hi Guys,

 

I am facing difficulty in storing of return List from python function which contains Number, String, Float etc in different order using NI TesSTand 2019 local variable. I tried to create container of having same type of data type inside in TestStand 2019 but couldn't succeed. Can anyone please help me in this regard?

 

Basically i want to store python function return contains number, string , float in random order and store in TestStand 2019  local variable.

 

Regards.

Prakash Choudhary

0 Kudos
Message 7 of 7
(2,888 Views)