Reading of SMB values from TwinCAT I/O driver

Download

Language / IDE

Extract the sample program

Visual C#

-

Visual Basic (for .NET Framework)

Sample10.exe

Delphi Prism (Embarcadero Prism XE2, Oxygene for .NET)

-

Delphi for .NET (Borland Developer Studio 2006)

-

 

TX1000 | TwinCAT CP (royalty-free) is a product containing drivers for the Beckhoff Control Panels respectively Control Panel-PC's of the CP6xxx und CP7xxx series, the industrial human machine interfaces from Beckhoff.
It gets typically used if there is no full TwinCAT version considered but basic functions of the Control Panel or Control Panel-PC need to get accessed via application software (like pushbutton extensions or the named SMB (System Management Bus) on supported Motherboards, etc...
TwinCAT CP is a subset of the full TwinCAT suite, means all contained drivers are binary identical to those in the other TwinCAT levels available. Written application software doesn't need to get touched in any way, if TwinCAT CP gets upgraded to a full TwinCAT version later.

Even if only TwinCAT-CP is installed on the controller or HMI device, the SMB device can get accessed by the ADS client (i.e. from a Visual Basic or similar DLL-, Active X- or .NET-capable application).

The visualization allows a continuous supervision of operation temperatures, fan speeds or even the different power supply voltages. That way,  the crossing of a critical threshold value can be detected (i.e. if an implementation of an advanced maintenance system is considered). The following example shows a possible implementation under Visual Basic.NET.

Order options:

TwinCAT-CP | License for using the I/O driver for Beckhoff Control Panels for communication between generic Windows applications (alternatively, any other level of  TwinCAT of course)

Required software:

Visual Basic (for .NET Framework) program

 

Example: Temperature

1. Add Reference

At first, a Reference  to the necessary  TwinCAT.Ads.dll  needs to be added. The TwinCAT.ADS.NET component gets added via right mouse-click on ProjectAdd Reference.
 

2. Determination of device address (here) : Index-Group


Private Sub MotherboardDiagnosis_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
    Try
        'Create a new instance of class TcAdsClient
                    tcClient = New TwinCAT.Ads.TcAdsClient()
        
        'Connect to local PLC - Runtime 1 - Port 300
        tcClient.Connect(300)
                
        'Gets the device count of devices appended to active configuration if
        'TwinCAT is in run mode
        Dim state = tcClient.ReadState.AdsState
        
        If Not state = AdsState.Run Then
            txtCurrent.Text = "Bad TwinCAT state ("& state.ToString() &").
            Please restart application."
        Else
            Dim deviceCount As UInt32
            deviceCount = tcClient.ReadAny(&H5000, &H2,
            deviceCount.GetType())
            
                            
            'Gets the device count of devices appended to active
            'configuration as zero-based index
            'and gets the device ID's of all active devices for the
            'remaining indices (inverted sort)
            Dim arrayDeviceIDs(deviceCount) As UInt16
            arrayDeviceIDs = tcClient.ReadAny(&H5000, &H1,
            arrayDeviceIDs.GetType(), New Integer() {deviceCount + 1})
            For i As Integer = 1 To (deviceCount)
                'gets the device identification number (Motherboard
                'System Management Bus(SMB) => 32)
                Dim devIdent = tcClient.ReadAny(arrayDeviceIDs(i) +
                &H5000, &H7, arrayDeviceIDs(i).GetType)
    
                        
                'checks if the device type is a SMB-Type
                If devIdent = 32 Then
                    _iIndexGroup = &H9000 + arrayDeviceIDs(i)
            Exit For
        End If
    
        Next
        'Enable timer to start monitoring with determined IGroup
        tmrTimer1.Enabled = True
    End If
    
    Catch ex As Exception
        txtCurrent.Text = ex.Message
    End Try
End Sub

 

3. Determination of the Variable address (here:  ) Index-Offset

To determine the Index-Offset of the variable, it's very comfortable to use TwinCAT System Manager . By selecting the required Input  in the left tree-view, the related window on the right shows the whished address in hexa-decimal notation.

Reading of SMB values from TwinCAT I/O driver 1:

 

4. Cyclic read update of the value in your application


Private Sub tmrTimer1_Tick(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles tmrTimer1.Tick
    Try
        'IOffset may be adjusted to monitor different inputs e.g. fan-speeds
        'or voltages
        _iTemp = tcClient.ReadAny(_iIndexGroup, 0, _iTemp.GetType())
        ProgressBar1.Value = _iTemp
        lblCurrent.Text = ("Current: " + (Convert.ToString(_iTemp)) + "°C")
        
        Catch ex As Exception
            'Catches if certain circumstances turned TwinCAT to offline mode.
            'Restarts monitoring if configuration remains unchanged and TwinCat
            'is turned online again.
            If ex.Message = "Ads-Error 0x12 : Port is disabled." Then
                lblCurrent.Text = "Ports are disabled. TwinCAT may be in
                offline mode."
                ProgressBar1.Value = 0
            Else
                MessageBox.Show(ex.Message)
            End If
    End Try
End Sub

 

Example: Resulting Message box when exceeding a temperature threshold value

Reading of SMB values from TwinCAT I/O driver 2: