From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

VB.Net Integration

I'm new to TS.  I've developed board-testing automation using VB.Net.  I'd like to integrate what I already have into TS.  I tried something simple like below but got an "Object reference not set to an instance of an object" error as I should, since SequenceContext is an Interface type.  I took the DummyFunctionName function straight out of the dotnet.vb example from NI.  Any help/guidance is greatly appreciated.

 

Thx,

VuN

 

Imports NationalInstruments.TestStand.Interop.API

Imports System.Runtime.InteropServices

 

Public Class Form1

Private m_SC As SequenceContext

Private m_report As String

Private m_ERROR As Boolean

Private m_errCode As Integer

Private m_errorMsg As String

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

DummyFunctionName(m_SC, m_report, m_ERROR, m_errCode, m_errorMsg)

If m_ERROR Then

MsgBox("Error code: " & m_errCode & ". Error Message: " & m_errorMsg)

End If

End Sub

 

Public Sub DummyFunctionName(ByVal seqContext As NationalInstruments.TestStand.Interop.API.SequenceContext, ByRef reportText As String, ByRef errorOccurred As Boolean, ByRef errorCode As Integer, ByRef errorMsg As String)

Try

' INSERT YOUR SPECIFIC TEST CODE HERE

' The following code shows how to access properties and variables via the TestStand API

 Dim propertyObject As PropertyObject = seqContext.AsPropertyObject()

' Dim lastUserName As String = propertyObject.GetValString("StationGlobals.TS.LastUserName", 0)

 Dim stationName As String = propertyObject.GetValString("StationGlobals.StationName", 0)

MsgBox(stationName)

Catch ex As COMException

errorOccurred = True

errorMsg = ex.Message

errorCode = ex.ErrorCode

End Try

 End Sub

End Class

0 Kudos
Message 1 of 4
(2,936 Views)

I'm assuming you get the error when you try to execute your step in TS?  How do you have your step configured (what values are you passing for your parameters)?  SequenceContext is an interface yes, but you should be passing the object in from TS (just specify "ThisContext" for the value of that parameter on your .NET step in TS).

 

-Jeff

0 Kudos
Message 2 of 4
(2,932 Views)

What I did was compile the VB.Net code and have TS launch the .exe.  You're right, I need to have a way to instansiate the object but I'm not sure how to do that in my code.

0 Kudos
Message 3 of 4
(2,929 Views)

You should generally be creating a class library assembly (.dll), not an .exe. You can then call that from a step in a teststand sequence which uses the .NET adapter. Please be more specific about what you are trying to do if this is not what you are looking for. The way you have it written doesn't really make sense since you will just be calling your method will unintialized variables as the parameters. You should instead likely be calling your method from a TestStand sequence rather than the Load callback of your .exe.

 

If you are trying to write a user-interface application rather than a code module to be called from a sequence, you might want to start with the example VB.NET UI code installed with TestStand.

 

Hope this helps,

-Doug

0 Kudos
Message 4 of 4
(2,925 Views)