Click or drag to resize

4.1.5 Trigger Configuration Tutorial

The Trigger Configuration tutorial shows a sample use case in which the data acquisition trigger is set using the PDA API.

The trigger is configured to start data acquisition with the start of the laser process detected by Gate On. Gate Off is set as stop trigger. Additionally, a trigger-off-delay is configured, which will allow to trigger on again within a set time after trigger off. This way, a laser process with multiple gate activations can be recorded as single process and is not split into multiple layers.

Complete Source Code
Trigger Configuration example
//---------------------------------------------------------------------------------------
// This example demonstrates how to configure an acquisition trigger using the PDA API.
//---------------------------------------------------------------------------------------

using RAYLASE.PDA.API;
using System.Diagnostics;
using System.Net;

public class Program
{
    public static async Task<int> Main( string[] args )
    {
        Console.WriteLine( "\n\nTrigger Configuration sample\n------------------\n\n" );

        if ( args.Length < 1 )
        {
            Console.WriteLine( "This tutorial requires a valid card IP address as argument" );
            return -1;
        }

        var cardIP = args[0];
        if ( !IPAddress.TryParse( cardIP, out _ ) )
        {
            Console.WriteLine( "The supplied IP address argument is not a valid IP address" );
            return -1;
        }

        // Default installation path of the ProcessDataAnalyzer.Service.exe
        var defaultServiceExePath = @$"{Environment.ExpandEnvironmentVariables( "%ProgramFiles%" )}\RAYLASE\ProcessDataAnalyzer\bin\ProcessDataAnalyzer.Service.exe";

        // Check if a different path was specified in the arguments.
        var serviceExePath = args.Length <= 1 ? defaultServiceExePath : args[1];

        // Get the API which auto-starts the PDA Server and is valid for this (Main()) scope.
        using ( var api = new RAYLASE.PDA.ClientLib.Api( serviceExePath ) )
        {

            // Set the trigger configuration.
            var triggerConfig = new TriggerConfig()
            {
                OnSignal = TriggerOnSignal.TonsGateOn, // Trigger on gate on
                OnValue = 1, // Gate value is true
                OffSignal = TriggerOffSignal.ToffsGateOff, // Stop acquisition on gate off
                OffValue = 0, // Gate value is false
                TriggerOffDelay = 500_000, // Trigger off if no additional gate on is received within 0.5 seconds after gate off
                Mode = TriggerMode.TmSingle,
                PreTrigger = 0, // Start recording directly with trigger event
                PostTrigger = 0, // Stop recording directly with trigger event
                StopAfterTriggerOff = 0 // If another gate on is received within 3 seconds after trigger off, continue recording
            };

            api.Acquisition.Connect(cardIP);
            api.Configuration.SetPdaConfig( triggerConfig );

            // Start a recording with the new trigger settings
            Console.WriteLine( "Starting acquisition (blocking until timeout reached)" );
            var clock = Stopwatch.StartNew();
            // Do not set AutoStopSeconds or set it to 0 to acquire indefinitely.
            var acquisitionReply = api.Acquisition.Start( new AcquisitionStartRequest { WaitForStop = true } );
            clock.Stop();
            Console.WriteLine( $"Acquisition took {clock.Elapsed.ToString( "mm\\:ss" )}" );

            // Some commands return a status in their reply which can transport a "soft" error without throwing.
            // In case of the Acquisition, if ADC signals are configured and the license can not be found,
            // The ADC signals will be excluded from acquisition and a warning is returned.
            // It might be a good idea to check the status code if available:
            if ( acquisitionReply.Status.Code != RAYLASE.PDA.API.Error.StatusCode.Ok )
            {
                Console.WriteLine( $"Acquisition encountered an error: {acquisitionReply.Status}" );
                return -1;
            }

            // Export the acquired data to a .csv file.
            // Please note that this path is as seen from the service.exe. If you set a relative path, it will
            // be relative to the PDA installations bin folder.
            Console.WriteLine( "Exporting acquired data to .csv" );
            clock.Restart();
            var serviceRelativeExportPath = @"..\TriggerConfiguration_Export.csv";
            api.Acquisition.Export( new( serviceRelativeExportPath, useDecimalPoint: true ) );
            clock.Stop();
            Console.WriteLine( $"Export took {clock.Elapsed.ToString( "mm\\:ss" )}" );
        }
        return 0;
    }
}