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 |
---|
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 |
---|
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.
|
IPAddress lastIPAddress = cardConfiguration.RetrieveIPAddressOrNullIfUnknown();
string serialNumber = cardConfiguration.RetrieveSerialNumber();
CardInfo cardInfo = new CardInfo( lastIPAddress ?? IPAddress.IPv6Any, serialNumber );
using ( ClientAPI client = new ClientAPI() )
{
client.Connect( cardInfo );
if ( client.Connected )
{
cardConfiguration.StoreIPAddress( client.Address );
string serialNumberFromCard = client.System.GetCardSerialNumber();
Console.WriteLine( "Using SN {0}, connected to SN {1} at {2}", serialNumber, serialNumberFromCard, client.Address );
client.Disconnect();
}
}
See Also