Device list example

View on GitHub

' ListDevices.vb
'
' This example prints all the available devices to the screen.
'
' Find more information on http://www.tiepie.com/LibTiePie .

Imports System
Imports TiePie.LibTiePie

Module ListDevicesExample

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

        ' Enable network search:
        Network.AutoDetectEnabled = True

        ' Update device list:
        DeviceList.Update()

        ' Get the number of connected devices:
        Dim connectedDevices As UInt32 = DeviceList.Count

        If connectedDevices <> 0 Then
            Console.WriteLine()
            Console.WriteLine("Available devices:")

            For i As UInt32 = 0 To connectedDevices - 1
                Try
                    Dim item As DeviceListItem = DeviceList.GetItemByIndex(i)

                    Console.WriteLine("  Name: " + item.Name)
                    Console.WriteLine("    Serial Number  : " + item.SerialNumber.ToString)
                    Console.WriteLine("    Available types: " + DeviceTypeToStr(item.Types))
                    If item.HasServer Then
                        Dim server As Server = item.Server
                        Console.WriteLine("    Server         : " + server.URL + " (" + server.Name + ")")
                    End If
                Catch e As System.Exception
                    Console.WriteLine("Exception: " + e.Message)
                    Environment.Exit(1)
                End Try
            Next
        Else
            Console.WriteLine("No devices found!")
            Environment.Exit(1)
        End If

        Environment.Exit(0)
    End Sub

End Module