/* 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.Hardware;
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 (var i = 0u; i < DeviceList.Count; i++)
{
using (var 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}");
}
}
}
}
if (scps.Count > 1)
{
try
{
// Create and open combined instrument:
var 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:
var serialNumber = scp.SerialNumber;
// Close combined oscilloscope:
scp.Dispose();
scp = null;
// Remove combined oscilloscope from the device list:
DeviceList.RemoveDevice(serialNumber, false);
}
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);
}
}