Click or drag to resize

10.4.4 GPIO Ports in Practice

Practical aspects of GPIO Ports.

Caution note  Caution

The physical pins of the SP-ICE-3 Card's various connectors are numbered starting at 1, while the corresponding bits in the port configurations are numbered from 0.

How to retrieve the Available Pin-Mappings

Demonstrates use of GpioAPIGetAvailableIOPinMappingList

C#
using ( ClientAPI client = new ClientAPI() )
{
client.Connect( myCardIP );    // <--- insert your card's IP address here!
client.System.ResetToDefaults();

IOPinMapping[] pinMapping = client.Gpio.GetAvailableIOPinMappingList();

foreach (IOPinMapping pm in pinMapping)
Console.WriteLine( pm.ToString() );
}

The output should be similar to:

'PortA' @0 (Input): GpInA.0 / / /
'PortA' @1 (Input): GpInA.1 / / /
'PortA' @2 (Input): GpInA.2 / / /
'PortA' @3 (Input): GpInA.3 / / / SPI0.DI
'PortA' @4 (Input): GpInA.4 / Start Mark / /
'PortA' @5 (Input): GpInA.5 / Abort Mark / /
'PortA' @6 (Input): GpInA.6 / Part Sensor / /
'PortA' @7 (Input): GpInA.7 / / / SPI1.DI
'PortA' @8 (Input): GpInA.8 / Start Mark / /
'PortA' @9 (Input): GpInA.9 / Abort Mark / /
'PortA' @10 (Input): GpInA.10 / Part Sensor / /
'PortA' @11 (Input): GpInA.11 / / / SPI0.DI
'PortA' @12 (Input): GpInA.12 / / /
'PortA' @13 (Input): GpInA.13 / / /
'PortA' @14 (Input): GpInA.14 / / /
'PortA' @15 (Input): GpInA.15 / / / SPI1.DI
'PortA' @0 (Output): GpOutA.0 / Power.0 / / Power.WR
'PortA' @1 (Output): GpOutA.1 / Power.1 / / SPI0.SYNC
'PortA' @2 (Output): GpOutA.2 / Power.2 / / SPI0.CLK
'PortA' @0 (Input): GpInA.0 / / /
'PortA' @3 (Output): GpOutA.3 / Power.3 / / SPI0.DO
'PortA' @4 (Output): GpOutA.4 / Power.4 / / MEB
'PortA' @5 (Output): GpOutA.5 / Power.5 / / SPI1.SYNC
'PortA' @6 (Output): GpOutA.6 / Power.6 / / SPI1.CLK
'PortA' @7 (Output): GpOutA.7 / Power.7 / / SPI1.DO
'PortA' @8 (Output): GpOutA.8 / Power.8 / Motf1.A /
'PortA' @9 (Output): GpOutA.9 / Power.9 / Motf1.B / SPI0.SYNC
'PortA' @10 (Output): GpOutA.10 / Power.10 / Motf1.I / SPI0.CLK
'PortA' @11 (Output): GpOutA.11 / Power.11 / / SPI0.DO
'PortA' @12 (Output): GpOutA.12 / Power.12 / Motf2.A / MEB
'PortA' @13 (Output): GpOutA.13 / Power.13 / Motf2.B / SPI1.SYNC
'PortA' @14 (Output): GpOutA.14 / Power.14 / Motf2.I / SPI1.CLK
'PortA' @15 (Output): GpOutA.15 / Power.15 / GpioA.WR / SPI1.DO

... etc., etc. for all the other ports.

How to configure an individual GPIO port

Demonstrates use of

C#
using ( ClientAPI client = new ClientAPI() )
{
client.Connect( myCardIP );    // <--- insert your card's IP address here!
client.System.ResetToDefaults();

// get the current (default) GPIO configuration for all ports
GpioConfig config = client.Gpio.GetConfig();

// reference the PortA configuration
PortConfig portAConfig = config.Ports[ IOPort.PortA ];

// select 5v logic level on PortA
portAConfig.IOLevel = IOVoltage.Five;

// set all of PortA's pin groups to be outputs
for( int groupIndex = 0; groupIndex < portAConfig.Directions.Length; groupIndex++ )
{
portAConfig.Directions[ groupIndex ] = IODirection.Output;
}

// and finally send the whole GPIO configuration,
// including PortA's configuration, back to the card.
client.Gpio.SetConfig( config );
}