Click or drag to resize

4.2.8 Programming Example - How to Select the Waveform

Code samples showing how to select the waveform on a TruPulse Nano / SPI Laser.

Asynchronous waveform selection.
C#
using ( ClientAPI client = new ClientAPI( CardIP ) )
{
    uint waveformSelectionValue = 5; // We assume that your application will supply an appropriate value.

    try
    {
        // With the SPI-Laser Adapter, waveform selection is performed by bits 8..15 of PortD:
        uint WaveformSelectionWord = waveformSelectionValue << 8;
        client.Gpio.Write( IOPort.PortD, PinAction.Write, WaveformSelectionWord );
    }
    catch ( Exception ex )
    {
        Console.WriteLine( "Uhhh, Houston? We've had a problem...{0}", ex.ToString() );
    }
}
Waveform selection within a command list.
C#
using ( ClientAPI client = new ClientAPI( CardIP ) )
{
    uint waveformSelectionValue = 5; // We assume that your application will supply an appropriate value.

    try
    {
        CommandList list = new CommandList();

        // Potentially lots of list.AppendBlah(...) elided here for brevity.

        // With the SPI-Laser Adapter, waveform selection is performed by bits 8..15 of PortD:
        uint WaveformSelectionWord = waveformSelectionValue << 8;
        list.AppendGpioValue( IOPort.PortD, PinAction.Write, WaveformSelectionWord );

        // Possibly even more list.AppendBlah(...) elided here.

        // Now we can execute the list.
        int listID = 0;
        client.List.Set( listID, list );

        client.Laser.ArmLaser( true );

        client.List.Execute( listID );

        // Obviously, the timeout has to be appropriate for the marking speed, etc.
        int timeoutMs = 1000;

        int? doneID;
        if ( !client.List.WaitForListDone( out doneID, timeoutMs ) )
        {
            throw new ListException( "Timed out waiting for ListDone." );
        }
        if ( doneID != listID )
        {
            throw new ListException( "Got ListDone for wrong listID!" );
        }
    }
    catch ( Exception ex )
    {
        Console.WriteLine( "Uhhh, Houston? We've had a problem...{0}", ex.ToString() );
    }
}