NI VeriStand

Showing results for 
Search instead for 
Did you mean: 

Passing values to model via Excel Sheet using the Veristand Python API

Hi, I am trying to pass values from an excel sheet to my model using the python API, when I tried to pass it directly, I got an error saying "Variables must be initialized with a valid Veristand datatype", so I tried to copy all values from excel to a list, and then create a DoubleValueArray inside the @nivs_rt_sequence and copy the values from my list to this variable, but I get an Index error when I do this. 


I have attached my code snippet. Can someone tell me what I'm doing wrong? Or If there is a better way to pass values/testcases from excel to my model in Veristand?


(Note: the excel workbook has 3 sheets named S1,S2,S3 with just 3 values each, this is a trial run.)


Thanks in advance.

0 Kudos
Message 1 of 11


Maybe solution would be to change excel format to to the  tdms and then to veristand.

(1) (2)  It might work.


0 Kudos
Message 2 of 11

To do that I think I would have to use npTDMS library, my main problem is I cannot use any other functions inside the veristand sequence. I cannot even use a list to store the values and use .append, I have to stick to just the basic comparator and arithmetic functions and whatever is in the veristand API.



0 Kudos
Message 3 of 11

Hi siddheshk,

 What you're trying to do involves a bit of metaprogramming... You'd need to generate your sequence files and then execute them.


 The reason is that Veristand sequences written in Python are then compiled to RT sequences format, not executed by any type of Python runtime. Thus they are composed of a limited set of Python constructs and don't have access to any libraries.


 If you're aiming at passing a sequence of values, then - as I mentioned - you'd need a metaprogrammning approach. Read out your values from the input file, then generate the sequence file using e.g. Jinja or other templating engine (or even directly, but Jinja is easier to handle 🙂 ) and then use the generated file to actually execute the test case.

Piotr F.
Hardware Engineer @ ZF
0 Kudos
Message 4 of 11


I am a beginner at veristand and also python maybe, let me just explain what I am trying to do so you have a better idea because I feel like I'm stuck looking at the same 4 errors for about a week now.


I have a couple Simulink models designed that I have converted to .dll files and uploaded them to ni veristand, I'm trying to run some tests automatically on these models using python. My aim is to pass model parameter values from an excel sheet or something similar and let the model run and then generate the report.


I am able to manually set values to the model parameters and control it via python but I'm trying to import values from a sheet so I can just run the program and it goes ahead and performs the simulations for different values for me. I cannot pass these excel sheets directly as I can only use veristand data types, which is limiting what I can do with this entire project.


I will go through jinja and see what I can understand. I appreciate you taking out time reading through this and replying to me.


0 Kudos
Message 5 of 11


 That wasn't so long 🙂 You're welcome - Veristand can be a tricky beast.


 I understand that what you're trying to achieve is an equivalent of running an RT sequence through Veristand Stimulus Profile Editor with time-value data read from an Excel file. Excel file contains, e g.:

0s 2000rpm

1s 3000rpm

5s 7000rpm

10s 0rpm


Step-by-step solution would be to:

1. Write a template procedure in Python using the RT sequence API, having placeholders for data where necessary (e.g. %TIME%, %RPM_VALUE%)

2. Read the time-value data from Excel

3. Read in the template, replace placeholders, write the resulting file out as a test case (this step can be handled by Jinja, Mako, or whatever you find the easiest)

4. Execute the resulting test case using run_py_as_rtseq


Templating engines are nice in that they can handle loops and conditions internally, resulting in easier file handling.

Piotr F.
Hardware Engineer @ ZF
0 Kudos
Message 6 of 11


Okay I understand what I have to do, I have been struggling with the step 3 as I've been trying to pass values either directly via sheets, or copying the values to a list and then trying to copy the list into a DoubleValueArray (Which is a veristand data type). I assume this is what you mean when you talk about place holders? Define variables with appropriate veristand datatypes so the values can be passed onto them? 


I am still a bit unclear with what I have to do with templates, Do I need to create a .nivsseq file using jinja/mako? Anything specific I should read into when it comes to jinja? Excuse me if these doubts are not that good. 


0 Kudos
Message 7 of 11


 A disclaimer at first - I haven't used that technique myself yet. I'm using code generation for other purposes, though, and it comes out very well.


 You can define, for example, a loop in a template.


{% for tm, val in loop_values %}

    In1.value = DoubleValue({ val })

    wait(DoubleValue({ tm }))

{% endfor %}


If you run this through Jinja passing loop_values that you read from Excel, you'll end up with n repetitions of that template code, e.g. let's assume loop_values= [(10, 100), (20, 300), (50, 0)]. What will end up in the output file is as follows:


    In1.value = DoubleValue(100)


    In1.value = DoubleValue(300)


    In1.value = DoubleValue(0)



As for Jinja - just read on it and understand what it does. In short, it replaces defined placeholders in text with actual values. Like you had an invoice to send to 100 clients. I suppose you wouldn't want to fill these 100 invoices manually - rather fetch client data from a database and fill in the template automatically 🙂

Piotr F.
Hardware Engineer @ ZF
0 Kudos
Message 8 of 11

This gives me a better idea and I think I know what to read/try. Thank you.
I just have one doubt, if I wasn't able to use things like .append on lists in the rt_sequence code, would I be able to use this method to pass values? As you said sequences written in python are compiled to RT sequences format so we only have a limited set of python constructs and no access to external libraries. So would this template approach work?

Again, this still gives me enough to work with, Thank you.


0 Kudos
Message 9 of 11


From the perspective of the RT sequence, values will be hardcoded. This is what code generation is for. This is also why you need a separate Python program to generate your test cases. They will be no longer in the same file, as in your previous example. Test cases will be separate files, your main script will only supervise running them.


You do all the data readout/manipulation, then run the code generation. The code generation process fills in the placeholders and generates test case scripts that have all the values hardcoded, so you can use only basic Python in there.

Piotr F.
Hardware Engineer @ ZF
0 Kudos
Message 10 of 11