GeneratorGatedBurst.cs

/* GeneratorGatedBurst.cs
 *
 * This example generates a 10 kHz square waveform, 10 Vpp when the external trigger input is active.
 *
 * Find more information on http://www.tiepie.com/LibTiePie .
 */

using System;
using TiePie.LibTiePie;

class GeneratorGatedBurstExample
{
    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 gated 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 gated burst support:
                if ((gen.ModesNative & Constants.GM_GATED_PERIODS) != 0 && gen.TriggerInputs.Count > 0)
                {
                    break;
                }
                else
                {
                    gen.Dispose();
                    gen = null;
                }
            }
        }

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

                // Set frequency:
                gen.Frequency = 10e3; // 10 kHz

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

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

                // Set mode:
                gen.Mode = GeneratorMode.GatedPeriods;

                // Locate trigger input:
                TriggerInput triggerInput = gen.TriggerInputs.GetById(Constants.TIID_EXT1);

                if (triggerInput == null)
                {
                    throw new System.Exception("Unknown trigger input!");
                }

                // Enable trigger input:
                triggerInput.Enabled = true;

                // Enable output:
                gen.OutputOn = true;

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

                // Start signal generation
                gen.Start();

                // Wait for keystroke:
                Console.WriteLine("Press Enter to stop signal generation...");
                Console.ReadLine();

                // Stop generator:
                gen.Stop();

                // 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 gated burst support!");
            Environment.Exit(1);
        }

        Environment.Exit(0);
    }
}