Click or drag to resize

12.4.1 How to Connect to a Card using Discovery

This procedure for making contact with a particular SP-ICE-3 Card from your application assumes that the card is already installed (internally or externally) and is currently running.

Please refer to 5.5.2.1 How Card Discovery works.

Making contact with a card via Discovery.

To communicate with a particular card, an application program on the Host-PC needs to know at least one of the card's IP-Addresses.

The SP-ICE-3 Card implements a variant of the UPnP Discovery mechanism to make it possible to obtain such an address programmatically.

The ClientLib function ClientAPIDiscover can be used to discover internally and externally installed SP-ICE-3 Cards automatically, and returns various interesting properties of the cards, including their IP-Addresses.

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#
// Discover all the available cards:
CardInfo[] cards = ClientAPI.Discover();

using ( ClientAPI client = new ClientAPI() )
{
    foreach ( var card in cards )
        // Select one particular card:
        if ( card.SerialNumber.Contains( "SP300042" ) ) // for instance.
        {
            string cardIP = card.IP.ToString();

            // Open a communications channel to the card:
            client.Connect( cardIP );
            if ( !client.Connected )
                continue;

            // Send a command to the card:
            string serialNumber = client.System.GetCardSerialNumber();

            // NB: obviously, in this case, we expect this command
            // to return the same serial number that we selected above!

            Console.WriteLine( "Connected to SN {0} at {1}", serialNumber, cardIP );

            // Close the communications channel to the card:
            client.Disconnect();
        }
}
See Also