OscilloscopeCombineHS3HS4.vb

' OscilloscopeCombineHS3HS4.vb
'
' This example demonstrates how to create and open a combined instrument of all found Handyscope HS3, Handyscope HS4 and/or Handyscope HS4 DIFF's.
'
' Find more information on http://www.tiepie.com/LibTiePie .

Imports System
Imports System.Collections.Generic
Imports TiePie.LibTiePie

Module OscilloscopeCombineHS3HS4Example

    Sub Main()
        ' Print library information:
        PrintLibraryInfo()

        ' Update device list:
        DeviceList.Update()

        ' Try to open all HS3/HS4(D) oscilloscopes:
        Dim allowedProductIDs() As ProductId = {ProductId.HS3, ProductId.HS4, ProductId.HS4D}
        Dim scps As New List(Of Oscilloscope)
        If DeviceList.Count <> 0 Then
            For i As UInt32 = 0 To DeviceList.Count - 1
                Dim item As DeviceListItem = DeviceList.GetItemByIndex(i)

                If Array.IndexOf(allowedProductIDs, item.ProductId) > -1 And item.CanOpen(DeviceType.Oscilloscope) Then
                    scps.Add(item.OpenOscilloscope())
                    Console.WriteLine("Found:" + item.Name + ", s/n: " + item.SerialNumber.ToString)
                End If
            Next
        End If

        If scps.Count > 1 Then
            Try
                ' Create and open combined instrument:
                Dim scp As Oscilloscope = DeviceList.CreateAndOpenCombinedDevice(scps.ToArray)

                ' Remove HS3/HS4(D) objects, not required anymore:
                scps.Clear()

                ' Print combined oscilloscope info:
                PrintDeviceInfo(scp)

                ' Get serial number, required for removing:
                Dim serialNumber As UInt32 = scp.SerialNumber

                ' Close combined oscilloscope:
                scp.Dispose()
                scp = Nothing

                ' Remove combined oscilloscope from the device list:
                DeviceList.RemoveDevice(serialNumber)
            Catch e As System.Exception
                Console.WriteLine("Exception: " + e.Message)
                Environment.Exit(1)
            End Try
        Else
            Console.WriteLine("Not enough HS3/HS4(D)\'s found, at least two required!")
            Environment.Exit(1)
        End If

        Environment.Exit(0)
    End Sub

End Module