OscilloscopeCombineHS3HS4.cs

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

using System;
using System.Collections.Generic;
using TiePie.LibTiePie;

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

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

        // Try to open all HS3/HS4(D) oscilloscopes:
        ProductId[] allowedProductIDs = { ProductId.HS3, ProductId.HS4, ProductId.HS4D };
        List<Oscilloscope> scps = new List<Oscilloscope>();
        if (DeviceList.Count != 0)
        {
            for (UInt32 i = 0; i < DeviceList.Count; i++)
            {
                DeviceListItem item = DeviceList.GetItemByIndex(i);

                if (Array.IndexOf(allowedProductIDs, item.ProductId) > -1 && item.CanOpen(DeviceType.Oscilloscope))
                {
                    scps.Add(item.OpenOscilloscope());
                    Console.WriteLine("Found:" + item.Name + ", s/n: " + item.SerialNumber.ToString());
                }
            }
        }

        if (scps.Count > 1)
        {
            try
            {
                // Create and open combined instrument:
                Oscilloscope scp = (Oscilloscope)DeviceList.CreateAndOpenCombinedDevice(scps.ToArray());

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

                // Print combined oscilloscope info:
                PrintInfo.PrintDeviceInfo(scp);

                // Get serial number, required for removing:
                UInt32 serialNumber = scp.SerialNumber;

                // Close combined oscilloscope:
                scp.Dispose();
                scp = null;

                // Remove combined oscilloscope from the device list:
                DeviceList.RemoveDevice(serialNumber);
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                Environment.Exit(1);
            }
        }
        else
        {
            Console.WriteLine("Not enough HS3/HS4(D)\'s found, at least two required!");
            Environment.Exit(1);
        }

        Environment.Exit(0);
    }
}