Click or drag to resize

4.2.9 Programming Example - How to Configure the Laser Mode

Code samples showing how to configure the laser mode (Pulsed / CW) on a TruPulse Nano / SPI Laser.

Write SPI per list.
C#
using ( ClientAPI client = new ClientAPI( CardIP ) )
{
    try
    {
        //Configure SPI module
        int moduleID = 2;
        SpiConfig spiConfig = client.Sfio.Spi.GetConfig();
        spiConfig.Modules[moduleID] = new SpiModule
        {
            Enabled = true,
            BitOrder = Order.MsbFirst,
            PreDelay = 0.25,
            PostDelay = 0.25,
            FrameDelay = 0.0,
            SpiSyncMode = SyncMode.SyncPerWord,
            ClockPeriod = 0.15,
            BitsPerWord = 32,
            OutputSource = DataSource.SpiListCommand
        };
        client.Sfio.Spi.SetConfig( spiConfig );

        //Set pulsed / CW mode per list
        CommandList list = new CommandList();
        uint laserMode = 0; // pulsed = 0, cw = 1
        uint laserModeSelectionWord = laserMode << 26;
        list.AppendSpiWrite( moduleID, laserModeSelectionWord );

        // 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() );
    }
}
Write SPI per command.
C#
using ( ClientAPI client = new ClientAPI( CardIP ) )
{
    try
    {
        //Configure SPI module
        int moduleID = 2;
        SpiConfig spiConfig = client.Sfio.Spi.GetConfig();
        spiConfig.Modules[moduleID] = new SpiModule
        {
            Enabled = true,
            BitOrder = Order.MsbFirst,
            PreDelay = 0.25,
            PostDelay = 0.25,
            FrameDelay = 0.0,
            SpiSyncMode = SyncMode.SyncPerWord,
            ClockPeriod = 0.15,
            BitsPerWord = 32,
            OutputSource = DataSource.SpiListCommand
        };
        client.Sfio.Spi.SetConfig( spiConfig );

        //Set pulsed / CW mode per command
        uint laserMode = 0; // pulsed = 0, cw = 1
        uint laserModeSelectionWord = laserMode << 26;
        uint[] message = { laserModeSelectionWord };
        client.Sfio.Spi.Transmit( moduleID, message, async: false );
    }
    catch ( Exception ex )
    {
        Console.WriteLine( "Uhhh, Houston? We've had a problem...{0}", ex.ToString() );
    }
}