Click or drag to resize

10.3.4 SPI Programming for Scanner Data Monitoring

SPI Modules can be configured programmatically to automatically output data from the scanhead return channel(s) by calling the appropriate RAYLASE.SPICE3.ClientLibSpiAPI and ScannerCommunicationAPI methods.

Please refer to: 10.3.1 SPI Data Transfer Modes

Programming Example
Monitoring Scanner Current Position via SPI.
using ( ClientAPI client = new ClientAPI( CardIP ) )
{
    client.System.ResetToDefaults();

    // 
    // Configure Port A to output SPI Module 0 signals.
    // 

    IODirection[] directions = client.Gpio.GetDirections( IOPort.PortA );
    directions[0] = IODirection.Output;
    directions[1] = IODirection.Input;
    client.Gpio.SetDirections( IOPort.PortA, directions );

    client.Gpio.SetIOLevel( IOPort.PortA, IOVoltage.ThreePointThree );

    Polarity[] polarities = client.Gpio.GetPolarities( IOPort.PortA );
    polarities[1] =
    polarities[2] =
    polarities[3] =
    polarities[11] = Polarity.ActiveHigh;
    client.Gpio.SetPolarities( IOPort.PortA, polarities );

    int[] functions = client.Gpio.GetFunctions( IOPort.PortA );
    functions[1] =     // SPI0.SYNC
    functions[2] =     // SPI0.CLK
    functions[3] =     // SPI0.DO
    functions[11] = 3; // SPI0.DI
    client.Gpio.SetFunctions( IOPort.PortA, functions );

    // 
    // (Re-)Configure the SPI Module 0 signal parameters.
    // 
    int module = 0;
    SpiConfig sc = client.Sfio.Spi.GetConfig();
    SpiModule sm = sc.Modules[module];

    sm.Enabled = true;
    sm.OutputSource = DataSource.ScannerCommunication;
    sm.BitsPerWord = 8;
    sm.SpiSyncMode = SyncMode.SyncPerFrame;
    sm.ClockPeriod = 0.09;
    sm.PostDelay = 0.1;
    sm.PreDelay = 0.1;
    sm.FrameDelay = 0.1;

    sc.Modules[module] = sm;
    client.Sfio.Spi.SetConfig( sc );

    // 
    // This Enhanced Protocol command will configure a scanner
    // to output its current position (as measured) over the return channel.
    // 
    uint command =
        (uint)RAYLASE.SPICE3.ScannerEnhancedProtocol.CommandCode.SetDataSource +
        ( uint )RAYLASE.SPICE3.ScannerEnhancedProtocol.DataSource.CurrentPosition;

    // For this example, we are using the same command on all three axes.
    uint[] commands = new uint[3];
    commands[0] = command; // Copy command for X axis
    commands[1] = command; // Copy command for Y axis
    commands[2] = command; // Copy command for Z axis

    // 
    // Send the enhanced protocol command to the scanhead
    // 
    client.ScannerCommunication.TransmitEnhanced(
        0, // Scanhead 0 uses SPI Modules 0 and 2
        RAYLASE.SPICE3.Axes.XYZ,
        commands,
        100
    );

}
See Also