Click or drag to resize

12.4.6 How to Re-connect to a Card whose IP address has changed

This procedure for re-establishing contact with a particular SP-ICE-3 Card from your application assumes that you (or your application) already know the card's Serial Number.

Important note  Important
  • This procedure is equally applicable to cards which are installed Internally, Externally/DHCP, and Peer-to-Peer.

  • The cards may be addressed via IPv4 or IPv6.

  • RAYLASE GmbH recommends the use of IPv6 for all connections to SP-ICE-3 Cards, since their IPv6 addresses are predictable from the cards' serial numbers under all normal circumstances.

    Unfortunately, however, the Interface Identifier part of an IPv6 address, which is assigned by the Operating System and is typically displayed as "%nn" at the right-hand end of the address, is NOT guaranteed to remain unchanged over time.

Re-establishing contact with a card whose IP address has changed.

Assuming we know at least the Serial Number of the card, we can attempt to re-establish contact with 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#
// NB: for this example, we assume that our application provides a class containing
// configuration information for a given card.
// We also assume that the class provides the following methods:
//  1) RetrieveIPOrNullIfUnknown(), which returns the last known IPAddress of the card, if any.
//  2) RetrieveSerialNumber(), which returns the serial number of the card.

IPAddress lastIPAddress = cardConfiguration.RetrieveIPAddressOrNullIfUnknown();
string serialNumber = cardConfiguration.RetrieveSerialNumber();

// If we don't know the last IP address of the card, we can instead use IPv6Any (or IPAny ) to
// force (re-)discovery of the card.
CardInfo cardInfo = new CardInfo( lastIPAddress ?? IPAddress.IPv6Any, serialNumber );

using ( ClientAPI client = new ClientAPI() )
{
    client.Connect( cardInfo );

    if ( client.Connected )
    {
        // Keep the card's IP address for next time...
        cardConfiguration.StoreIPAddress( client.Address );

        // Now make sure that we are indeed in contact with the correct card!
        string serialNumberFromCard = client.System.GetCardSerialNumber();
        Console.WriteLine( "Using SN {0}, connected to SN {1} at {2}", serialNumber, serialNumberFromCard, client.Address );

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