GeneratorBurst.cs

/* GeneratorBurst.cs
 *
 * This example generates a 50 Hz sine waveform, 4 Vpp, 100 periods.
 *
 * Find more information on http://www.tiepie.com/LibTiePie .
 */

using System;
using System.Threading;
using TiePie.LibTiePie;

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

        // Enable network search:
        Network.AutoDetectEnabled = true;

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

        // Try to open a generator with burst support:
        Generator gen = null;

        for (UInt32 i = 0; i < DeviceList.Count; i++)
        {
            DeviceListItem item = DeviceList.GetItemByIndex(i);
            if (item.CanOpen(DeviceType.Generator))
            {
                gen = item.OpenGenerator();

                // Check for burst support:
                if ((gen.ModesNative & Constants.GM_BURST_COUNT) != 0)
                {
                    break;
                }
                else
                {
                    gen.Dispose();
                    gen = null;
                }
            }
        }

        if (gen != null)
        {
            try
            {
                // Set signal type:
                gen.SignalType = SignalType.Sine;

                // Set frequency:
                gen.Frequency = 50; // 50 Hz

                // Set amplitude:
                gen.Amplitude = 2; // 2 V

                // Set offset:
                gen.Offset = 0; // 0 V

                // Set burst mode:
                gen.Mode = GeneratorMode.BurstCount;

                // Set burst count:
                gen.BurstCount = 100; // 100 periods

                // Enable output:
                gen.OutputOn = true;

                // Print Generator info:
                PrintInfo.PrintDeviceInfo(gen);

                // Start signal generation
                gen.Start();

                // Wait for burst to complete:
                while (gen.IsBurstActive)
                {
                    Thread.Sleep(10); // 10 ms delay, to save CPU time.
                }

                // Disable output:
                gen.OutputOn = false;
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                Environment.Exit(1);
            }

            // Close generator:
            gen.Dispose();
            gen = null;
        }
        else
        {
            Console.WriteLine("No generator available with burst support!");
            Environment.Exit(1);
        }

        Environment.Exit(0);
    }
}