VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Iron Python

Solved!
Go to solution

Is there somebody that is trying to use Iron Python scripting language with VeriStand?

My problem is that VeriStand has not an his own interpreter and I didn't find the way to run the scripts.

Thanks to all

0 Kudos
Message 1 of 10
(10,156 Views)

You might want to download and install IronPython 2.6.0. I remember that we had some issues with 2.6.1 but I can't tell what it was...

 

Once ipy is installed, the following script gets you at least started. It deploys a system definition file, launches the workspace and interacts with some channels.

 

 

import NIVeriStand

wks = NIVeriStand.Workspace() #Load the WS
wks.RunWorkspaceFile(SYSDEFINITION,0,1,60000,"","") #Deploy the SDF

blahblah = wks.GetSingleChannelValue("abc") #That's an alias
blahblah1 = wks.GetSingleChannelValue("Controller/Simulation Models/Models/sinewave/Outports/channel0")

ListOfNodes = ('Controller/User Channels/Ch1','Controller/User Channels/Ch2')
List = wks.GetMultipleSystemNodesData(nodes)

wks.StopWorkspaceFile("") #Stop the WS

 

 

Back in the days I've created an export of properties and functions of the SystemDefinitionAPI (unfortunately I haven't done that for all the exposed APIs) and right now I can't find the script. But I will catch up on that.

 

Thanks,

Tom

 

 

0 Kudos
Message 2 of 10
(10,152 Views)

NI VeriStand ships with a python library designed to be used in IronPython that wraps the execution API. Look in the <Public Documents>\National Instruments\NI VeriStand 2010\IronPython folder. This file contains the functions you can use to automate NI VeriStand.

 

Make sure you have the latest stable version of IronPython installed (2.6.2), and make sure you install the version for the 2.0 .NET CLR (not 4.0).

 

To get started, import the NIVeriStand.py file. Then open a connection to VeriStand as follows:

 

# Connects to an instance of NI VeriStand running on the local computer

wks = NIVeriStand.Workspace2("localhost")

 

You can use this Workspace object to deploy System Definitions, get and set channel values, and so on.

 

# Deploy a system definition referenced by the string SYSDEFINITION

wks.ConnectToSystem(SYSDEFINITION,1,60000)

 

# Get the value of the channel with the alias name Time and store it in result

result = wks.GetSingleChannelValue("Time")

 

# Set the channel Gain to value 2

wks.SetSingleChannelValue("Targets/Controller/User Channels/Gain", 2)

 

Other objects allow you to control stimulus profiles, do faulting, etc.

stim = NIVeriStand.Stimulus()

 

# Runs a stimulus profile

stim.RunStimulusProfile(TESTFILE,LOGDIR,60000,1,1)

 

 

Jarrod S.
National Instruments
0 Kudos
Message 3 of 10
(10,149 Views)

Attached you can find a python script that interacts with the sinewave delay example project (that ships with NIVS).

 

There is a readme for how to set it up.

 

This is the code:

 

import sys
import time
import NIVeriStand
from NIVeriStand import NIVeriStandException

APPDATADIR = r"C:\Users\Public\Documents\National Instruments\NI VeriStand 2010"
SINEPROJECTDIR = APPDATADIR + '\\Projects\\Example'
SINESDF = SINEPROJECTDIR + '\\Sinewave Delay.nivssdf'
TBLPROF = SINEPROJECTDIR + '\\Stimulus Profiles\\Table Profile\\Table Profile.nivstest'
LOGGINGDIR = SINEPROJECTDIR + '\\Logs'

TIMECHAN = 'Targets/Controller/System Channels/System Time'
SINECHAN = 'Targets/Controller/Simulation Models/Models/sinewave/Outports/Out1'

def sleep():
	time.sleep(1)

wks = NIVeriStand.Workspace2()
try:
	print "Running %s" % SINESDF
	wks.ConnectToSystem(SINESDF,1,60000)
	print "NI VeriStand Running and Client Connected!"
	
	stimTest1 = NIVeriStand.Stimulus2()
	
	print "\nMaking sure stimulus profile manager is ready for action..."
	state = stimTest1.GetStimulusProfileManagerState()
	if (state != 0):
		print "Error! Test state not expected!"

	stimTest1.ReserveStimulusProfileManager()
	print "Reserving stimulus test 1"
		
	print "\nRunning %s" % TBLPROF
	stimTest1.RunStimulusProfile(TBLPROF,LOGGINGDIR,60000,1,1)
	sleep()
	state = stimTest1.GetStimulusProfileManagerState()
	if (state != 2):
		print "Error! Test expected to started already"
	file = stimTest1.GetStimulusProfileFile()
	if(file != TBLPROF):
		print "Error! Test file are not expected"

	SysTime = wks.GetSingleChannelValue(TIMECHAN)
	SineVal = wks.GetSingleChannelValue(SINECHAN)
	while (state == 2):
		state = stimTest1.GetStimulusProfileManagerState()
		print "System Time: %fS\tSine Value: %f" % (SysTime,SineVal)
		SysTime = wks.GetSingleChannelValue(TIMECHAN)
		SineVal = wks.GetSingleChannelValue(SINECHAN)
		sleep()
	
	result = stimTest1.GetStimulusProfileResult()
	stimTest1.UnreserveStimulusProfileManager()
	
	if (result['Result'] == 1):
		textresult = "PASSED"
	elif (result['Result'] == 2):
		textresult = "FAILED"
	else:
		textresult = "SYSTEM ERROR"
	
	print "Test %s!" %textresult
	print ""
	raw_input("\n\nPress the enter key to exit.")
	
except NIVeriStandException, e:
	TEST_COMMENT = "Unexpected Exception " + e.message()
	print TEST_COMMENT
	time.sleep(10)
except:
	print sys.exc_info()
	time.sleep(10)
finally:
	wks.DisconnectFromSystem("",1)

 

 

Stephen B
Message 4 of 10
(10,146 Views)

Great, it works!

Thank you very much!

Now I can start my experiments Smiley Very Happy

have a good job

 

sorry for my "wild english"

0 Kudos
Message 5 of 10
(10,126 Views)

Hi All,

thanks to you now I can create my "testing automation" using IronPython but..... I've one more problem!

 

I can read and write every kind of variable and channel except Parameters (for example CAL = 'Controller/Simulation Models/Models/Test_Model/Parameters/Calibration_1').

In particular I can read Parameters using  "cal_value = workspace.GetSingleChannelValue(CAL)" but I'm not able to write it.

When I try to set a Parameter I've the following errors :

 

1. Trying to set the Parameter using the "workspace.SetSingleChannelValue(CAL,0)" occurs the error number 0xfffb4e2f:

 

2. Trying to set the Parameter using the "model.SetSingleParameterValue(CAL,0)" occurs the error number 0xfffb4e32:

 

What am I doing wrong?

Thanks to all

 

 

0 Kudos
Message 6 of 10
(10,023 Views)
Solution
Accepted by topic author scmm

Parameters cannot be set with the set channel values function. They must be set with the set or load file calls in the model manager class:

 

Untitled.png

 

I don't remember exactly why, but I think there is some extra logic in the back end of NI VeriStand to handle updating all the values of parameters at the same time if you use these calls. That way if you're setting a bunch of parameters, they all get applied at the same time. The same can't be said for the set channel value calls.

 

So #2 (as you listed) is the way to go.  The error you're getting is "node doesn't exist", so the path you have in CAL isn't corresponding to something NI VeriStand recognizes. You can use the GetParametersList call to make sure your path is right.

Stephen B
0 Kudos
Message 7 of 10
(10,019 Views)

I followed the second method and the problem was actually in the correct identification of the variable to be written.

 

was sufficient to write "model.SetSingleParameterValue('CAL',0)" and everything worked fine.

thanks a lot Stephen

0 Kudos
Message 8 of 10
(9,995 Views)

Hi Rif,

I am trying to run my stimulus profile through IronPython script but I am not able to do so can any one tell me where I am lagging ? Here below is my code:

 

import NIVeriStand

import clr

clr.AddReference("NationalInstruments.VeriStand, Version=2017.0.0.0, Culture=neutral, PublicKeyToken=a6d690c380daa308")

clr.AddReference("NationalInstruments.VeriStand.ClientAPI, Version=2017.0.0.0, Culture=neutral, PublicKeyToken=a6d690c380daa308"

 

import NationalInstruments.VeriStand.ClientAPI

from NationalInstruments.VeriStand.ClientAPI import Factory

 

Method1: directly from API

factory = NationalInstruments.VeriStand.ClientAPI.Factory()

stimulus = factory.GetIStimulus()

stimulus.RunStimulusProfile(r"C:\Users\Public\Documents\National Instruments\NI VeriStand 2017\Projects\Digital\digital.nivsstimprof", r"C:\Users\Public\Documents\National Instruments\NI VeriStand 2017\Projects\Digital\logs", 60000,1,1)

 

Method two from NIVeriStand.py

stimulus = NIVeriStand.Stimulus()

stimulus.RunStimulusProfile(r"C:\Users\Public\Documents\National Instruments\NI VeriStand 2017\Projects\Digital\digital.nivsstimprof", r"C:\Users\Public\Documents\National Instruments\NI VeriStand 2017\Projects\Digital\logs", 60000,1,1)

 

when I execute above code I am getting below error I am not sure how to get rid of it. Can any 1 help me on this ????

 

error:

NIVeriStand.NIVeriStandException: Consult NI VeriStand help for error code 0xfffb4d37 error message

0 Kudos
Message 9 of 10
(4,360 Views)

I have created a veristand project to send CAN signals for Cluster Ignition ON using XNET ,Accessing DIO ports using DAQ ,and Accessing PWM Duty cycle using FPGA.

 

but i am unable to access these hardware ports using Iron Python for Veristand.

As new in NI hardware and software, I need help regarding Iron python for accessing NI hardware ports under Hardware->Chassis->DAQ or XNET or FPGA?

0 Kudos
Message 10 of 10
(4,310 Views)