NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to set the TestStand Step Result Error from a call to .NET method made from the step?

I am trying to figure out an efficient way to pass exception information from .NET back to its calling sequence step in TestStand. Using the code snippet below, I am able to change the value of 'Code' property of the Error Object. However, the changed value does not seem to be reflected in the TestStand step result. Public Shared Function ClearErrorObject(ByVal sequenceContext As NationalInstruments.TestStand.Interop.API.SequenceContext) As Boolean Dim errorObject As PropertyObject = sequenceContext.Execution.ErrorObject() errorObject.SetValBoolean("Occurred", 0, False) errorObject.SetValString("Msg", 0, "") errorObject.SetValNumber("Code", 0, -1) Dim code As Integer = CInt(errorObject.GetValNumber("Code", 0)) Return True End Function
0 Kudos
Message 1 of 5
(4,575 Views)

Are you trying to clear the error or set it?

 

You should be setting the error of the step, not the execution. You can even pass step.error.occurred, step.error.msg, and step.error.code as output parameters, though you can also do it programmatically similar to what you posted. Also, if you don't want the error to terminate the sequence, then you should set setting the "Ignore Errors" setting on the step.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 5
(4,566 Views)

Thanks Doug.

 

Sorry how my last post was garbled -- I was blocking Lithium.com so the editor did not show in full.

 

Either way, the sample code I included

 

    Public Shared Function ClearErrorObject(ByVal sequenceContext As NationalInstruments.TestStand.Interop.API.SequenceContext) As Boolean
        Dim errorObject As PropertyObject = sequenceContext.Execution.ErrorObject()
        errorObject.SetValBoolean("Occurred", 0, False)
        errorObject.SetValString("Msg", 0, "")
        errorObject.SetValNumber("Code", 0, -1)
        Dim code As Integer = CInt(errorObject.GetValNumber("Code", 0))
        Return True
    End Function 

 

was inteded to test changing the error object. Once I have that tested, I would pass an execption to a call to set the step error. 

 

However, I am at a loss attempting to grab reference to the step error object. 

 

Could you share a code snippett with me showing how to get reference to the step error object?

 

Thanks.

 

David

 

 

 

 

0 Kudos
Message 3 of 5
(4,558 Views)

Doug,

 

Got it. This works. 

 

 

    Public Shared Function SetStepResultError(ByVal sequenceContext As NationalInstruments.TestStand.Interop.API.SequenceContext) As Boolean
        Dim errorObject As PropertyObject = sequenceContext.Execution.ErrorObject()
        Dim stepResult As NationalInstruments.TestStand.Interop.API.Step = sequenceContext.Step()
        stepResult.AsPropertyObject.SetValBoolean("Result.Error.Occurred", 0, True)
        stepResult.AsPropertyObject.SetValString("Result.Error.Msg", 0, "Error occurred")
        stepResult.AsPropertyObject.SetValNumber("Result.Error.Code", 0, -1)
        Dim code As Integer = CInt(stepResult.AsPropertyObject.GetValNumber("Result.Error.Code", 0))
        Return True
    End Function

 

 

0 Kudos
Message 4 of 5
(4,556 Views)

Looks good. Glad I could help. You could also pass those properties as byref parameters if you prefer. For example (not sure this is correct syntax, my VB knowledge is a bit rusty, but hopefully it's close enough):

 

Public Shared Function SetStepResultError(ByRef errorOccurred As Boolean, ByRef errorMessage As String, ByRef errorCode as Integer)
errorOccurred = True
errorMessage = "my error message"
errorCode = -1
End Function

Hope this helps,

-Doug

0 Kudos
Message 5 of 5
(4,542 Views)