Simcenter Testing Solutions Simcenter Testlab Automation: Measurement Example

2020-10-23T01:38:39.000-0400
Simcenter Testlab

Summary


Details


Direct YouTube link: https://youtu.be/ZdJNbiUW_Gc



This article documents a Simcenter Testlab Automation example program for automating a measurement and viewing its status.

In the program, the following is performed:
  • The state of the measurement is displayed on the Visual Basic form and updated when the state changes in Simcenter Testlab
  • The program provides an interface to start and stop the measurement in Simcenter Testlab through the Visual Basic form
A picture of the program running with Simcenter Testlab is shown in Figure 1.
 
User-added image
Figure 1: Example Simcenter Testlab Automation program (top, center) used to control measurement.

The example program illustrated uses Visual Basic.

Program Overview

As the form loads, the program connects to the running instance of Simcenter Testlab, opening Signature Acquisition if no instance is running.  The program then checks the “Measure” sheet of the active Simcenter Testlab application.  If this sheet is disabled, the program raises a customized error; otherwise, it brings the “Measure” sheet to the front.

The program accesses the “Overload” and “Measure_Acquisition_State” DataWatches from the ActiveBook.  By declaring these DataWatches as WithEvents, the ValueChanged event can be used as a handle for a subprogram.  This event is raised any time that the value on the DataWatch port changes.

The “Overload” DataWatch has a System.Boolean as its Data property; True if there is an overload, False otherwise.

The “Measure_Acquisition_State” has a LMSTestLabAutomation.Enumerate as its Data property; the LocalValue of the Enumerate matches the text in the measure state display in Simcenter Testlab.  These LocalValues do not exactly match the text displayed in Simcenter Testlab, but instead yield the names assigned to the particular Enumerate values in the internal programming.  Screenshots comparing the LocalValues to the Simcenter Testlab display are provided in Figure 2.
 
User-added image
Figure 2: LocalValues from program versus Simcenter Testlab status.

A subprogram to evaluate the value on each DataWatch is executed each time the ValueChanged event is raised by their associated DataWatch.  Because ValueChanged events run on a different thread than the main process, delegate subs are used to avoid cross-thread exceptions when changing the text values of the form’s labels.

To start and stop the measurements, a LmsHq::DataModelI::DataArch::CBufferICommand IData is created and placed on the ports “Start_Measurement” and “Stop_Measurement.”  Placing an IData of this type on any DataWatch that represents a button in Simcenter Testlab is equivalent to clicking the button; similarly, the “Signature/Measure/ArmDisarm” DataWatch, which represents a singular button that toggles the measurement state between on-line and offline, is “clicked” each time the command-type IData is placed on its port, rather than having a Boolean value setting or needing a different procedure to “arm” than to “disarm.”

Program Code

The Visual Basic code of the example is provided below; Visual Basic keywords are in dark blue, object classes/types are in light blue, string values are in red, and comments are in green.

Option Strict Off
Option Explicit On

Friend Class Main_Form
    Inherits System.Windows.Forms.Form

    Dim WithEvents gv_Overload As LMSTestLabAutomation.DataWatch
    Dim WithEvents gv_AcqState As LMSTestLabAutomation.DataWatch
    Dim TL As New LMSTestLabAutomation.Application

    Private Sub Main_Form_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        If TL.Name = "" Then ' Simcenter Testlab is not yet started -> start it yourself
            TL.Init(("-w SignatureRealTimeAcquisitionFSStandard"))
            ' If the template "ExampleAcq" is to be used, use the following line!
            ' TL.Init ("-w SignatureAcquisitionFSStandard -t ExampleAcq.tpl")

        End If


        Dim sheet As LMSTestLabAutomation.ISheet
        sheet = TL.ActiveBook.Sheets.Item("Measure")
        If sheet.Enabled = 1 Then
            TL.ActiveBook.SheetOnTop = "Measure"
            ' create the DataWatches
            gv_Overload = TL.ActiveBook.FindDataWatch("Overload")
            gv_AcqState = TL.ActiveBook.FindDataWatch("Measure_Acquisition_State")

            ' read them out the first time
            'Call DisplayOverload(gv_Overload.Data)
            'Call DisplayState(gv_AcqState.Data)

        Else
            Err.Clear()
            Err.Description = "'Measure' sheet is not enabled. Please check your setup in Simcenter Testlab"
            Err.Raise(-1)
        End If
    End Sub


    Private Sub btnStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnStart.Click
        ' Create an IData Command object
        Dim data_StartCommand As LMSTestLabAutomation.IData
        Dim attrmap_arguments As LMSTestLabAutomation.AttributeMap
        attrmap_arguments = TL.CreateAttributeMap()
        data_StartCommand = TL.CreateObject("LmsHq::DataModelI::DataArch::CBufferICommand", attrmap_arguments)

        ' Put the command into the "Start_Measurement" DataWatch;
        ' equivalent to manually pressing the start button

        Dim datawatch_Start As LMSTestLabAutomation.DataWatch
        datawatch_Start = TL.ActiveBook.FindDataWatch("Start_Measurement")
        datawatch_Start.Data = data_StartCommand
    End Sub

    Private Sub btnStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnStop.Click
        ' Create an IData Command object
        Dim data_StopCommand As LMSTestLabAutomation.IData
        Dim attrmap_arguments As LMSTestLabAutomation.AttributeMap
        attrmap_arguments = TL.CreateAttributeMap()
        data_StopCommand = TL.CreateObject("LmsHq::DataModelI::DataArch::CBufferICommand", attrmap_arguments)

        ' Put the command into the "Stop_Measurement" DataWatch;
        ' equivalent to manually pressing the stop button

        Dim datawatch_Stop As LMSTestLabAutomation.DataWatch
        datawatch_Stop = TL.ActiveBook.FindDataWatch("Stop_Measurement")
        datawatch_Stop.Data = data_StopCommand
    End Sub

    Private Sub buttonArm_Click(sender As System.Object, e As System.EventArgs) Handles buttonArm.Click
        ' Create an IData Command object
        Dim data_ArmCommand As LMSTestLabAutomation.IData
        Dim attrmap_arguments As LMSTestLabAutomation.AttributeMap
        attrmap_arguments = TL.CreateAttributeMap()
        data_ArmCommand = TL.CreateObject("LmsHq::DataModelI::DataArch::CBufferICommand", attrmap_arguments)

        ' Put the command into the "Signature/Measure/ArmDisarm" DataWatch;
        ' equivalent to manually pressing the Arm/Disarm button

        Dim datawatch_Arm As LMSTestLabAutomation.DataWatch
        datawatch_Arm = TL.ActiveBook.FindDataWatch("Signature\/Measure\/ArmDisarm")
        datawatch_Arm.Data = data_ArmCommand
    End Sub

    Private Sub gv_AcqState_ValueChanged(ByVal NewValue As Object) Handles gv_AcqState.ValueChanged
        'Get the name of the current Enumerate state
        Dim lv_enumState As LMSTestLabAutomation.Enumerate
        lv_enumState = NewValue
        AcquisitionState = lv_enumState.LocalValue
        ' Use a delegate sub to avoid cross-thread exceptions
        Call DisplayState()
    End Sub

    Private AcquisitionState As String
    Private Delegate Sub D_DisplayState()
    Private Sub DisplayState()
        If Me.InvokeRequired Then
            Me.Invoke(New D_DisplayState(AddressOf DisplayState))
        Else
            txtRunStatus_Value.Text = AcquisitionState
        End If
    End Sub

    Private Sub gv_Overload_ValueChanged(ByVal NewValue As Object) Handles gv_Overload.ValueChanged
        ' Put the new value where it can be accessed by the delegated sub
        HasOverload = NewValue
        ' Use a delegate to avoid cross-thread exceptions
        Call DisplayOverload()
    End Sub

    Private HasOverload As Boolean
    Private Delegate Sub D_DisplayOverload()
    Private Sub DisplayOverload()
        If Me.InvokeRequired Then
            Me.Invoke(New D_DisplayOverload(AddressOf DisplayOverload))
        Else
            If HasOverload = False Then
                ' If there is no overload
                txtOverloadInfo_Value.ForeColor = System.Drawing.ColorTranslator.FromOle(&H0)
                txtOverloadInfo_Value.BackColor = System.Drawing.ColorTranslator.FromOle(&HC000)
                txtOverloadInfo_Value.Text = "No overload"
            Else
                ' If there is an overload
                txtOverloadInfo_Value.BackColor = System.Drawing.ColorTranslator.FromOle(&HFF)
                txtOverloadInfo_Value.ForeColor = System.Drawing.ColorTranslator.FromOle(&H0)
                txtOverloadInfo_Value.Text = "Overload"
            End If
        End If

    End Sub
End Class



Simcenter Testlab Automation resources:

KB Article ID# KB000040599_EN_US

Contents

SummaryDetails

Associated Components

Simcenter Testlab Digital Image Correlation Testlab Environmental Testlab Acoustics Testlab Data Management Testlab Desktop Testlab Durability Testlab General Acquisition Testlab General Processing & Reporting Testlab Rotating Machinery & Engine Testlab Sound Designer Testlab Structural Dynamics Testlab Turbine