Click or drag to resize

12.4.5 How to make Multiple Connections to a single Card

To make and maintain several connections to a single SP-ICE-3 Cards simultaneously, your application must instantiate an instance of the ClientAPI for each connection.

Making several simultaneous connections to a single card.

Assuming we have armed ourselves with the card's address ( please refer to 5.5.2.3 How to obtain Card IP-Addresses the Hard Way ), we can attempt to make multiple connections to it 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 each connection to the card:
using ( clients[0] = new ClientAPI() )
using ( clients[1] = new ClientAPI() )
using ( clients[2] = new ClientAPI() )
{
    // NB: we assume the existence of a variable called CardIP,
    // which contains the IP address of our card.

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

    // Send the same command via each connection:
    for ( int i = 0; i < clients.Length; i++ )
        if ( clients[i].Connected )
        {
            string serialNumber = clients[i].System.GetCardSerialNumber();

            // NB: obviously, in this case, we expect the command
            // to return the same serial number on all connections!

            Console.WriteLine( "Connection {0} to SN {1} at {2}", i, serialNumber, CardIP );
        }

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