Click or drag to resize

12.4.4 How to Connect to Multiple Cards

To make and maintain contact with several SP-ICE-3 Cards simultaneously, your application must instantiate an instance of the ClientAPI for each card.

Making simultaneous connections to several cards.

Assuming we have armed ourselves with the cards' addresses ( please refer to 5.5.2.3 How to obtain Card IP-Addresses the Hard Way ), we can attempt to make contact with them all like this:

Note  Note
  • Boilerplate code is omitted from this example for brevity: please refer to 12.3 Example Code in this Manual.

  • This example is deliberately simplistic (some might say simple minded) to illustrate a point.

    It is not intended as an example of good programming style, nor of good programming practice.

C#
ClientAPI[] clients = new ClientAPI[] { };

// Instantiate a separate ClientAPI for the connection to each card:
using ( clients[0] = new ClientAPI() )
using ( clients[1] = new ClientAPI() )
using ( clients[2] = new ClientAPI() )
{
    // NB: we assume the existence of an array called CardIP,
    // which contains the IP addresses of our cards.

    // Open a communications channel to each card:
    for ( int i = 0; i < clients.Length; i++ )
        clients[i].Connect( CardIP[i] );

    // Send a command to each card:
    for ( int i = 0; i < clients.Length; i++ )
        if ( clients[i].Connected )
        {
            string serialNumber = clients[i].System.GetCardSerialNumber();

            Console.WriteLine( "Connected to SN {0} at {1}", serialNumber, CardIP[i] );
        }

    // Close the communications channel for each card:
    for ( int i = 0; i < clients.Length; i++ )
        clients[i].Disconnect();
}