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.
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 |
---|
|
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(); }