ListDevices.cs

/* ListDevices.cs - for LibTiePie 0.5+
 *
 * This example prints all the available devices to the screen.
 *
 * Find more information on http://www.tiepie.com/LibTiePie .
 */

using System;
using TiePie.LibTiePie;

class ListDevicesExample
{
    public static void Main()
    {
        // Print library information:
        PrintInfo.PrintLibraryInfo();

        // Update device list:
        DeviceList.Update();

        // Get the number of connected devices:
        UInt32 connectedDevices = DeviceList.Count;

        if (connectedDevices != 0)
        {
            for (UInt32 i = 0; i < connectedDevices; i++)
            {
                try
                {
                    DeviceListItem item = DeviceList.GetItemByIndex(i);

                    Console.WriteLine("  Name: " + item.Name);
                    Console.WriteLine("    Serial Number  : " + item.SerialNumber.ToString());
                    Console.WriteLine("    Available types: " + PrintInfo.DeviceTypeToStr(item.Types));
                }
                catch (System.Exception e)
                {
                    Console.WriteLine("Exception: " + e.Message);
                    Environment.Exit(1);
                }
            }
        }
        else
        {
            Console.WriteLine("No devices found!");
            Environment.Exit(1);
        }

        Environment.Exit(0);
    }
}