Note: The code on this page is for tutorial purposes only. It shows how to call the SDK and is not production-ready: it leaves out error handling, threading and app lifecycle management. Review and adapt it before you use it in your app.
Overview
Opens a communication session between the SDK and an available RFID reader, using srfidEstablishCommunicationSession.
Details
Before you connect, the reader must be paired with the iOS device and visible to the SDK as an available reader. Get the list of readers, and the reader ID of the one you want, as shown in Get Available Readers. Then pass that reader ID to srfidEstablishCommunicationSession.
- (void)connectRfidReader:(int)selectedReaderID {
readerID = selectedReaderID;
SRFID_RESULT result = [apiInstance srfidEstablishCommunicationSession:readerID];
if (SRFID_RESULT_SUCCESS != result) {
NSLog(@"Could not connect to reader %d", readerID);
}
}
The call only starts the connection. The SDK reports that the session is open through srfidEventCommunicationSessionEstablished: of your delegate, so subscribe to SRFID_EVENT_SESSION_ESTABLISHMENT and wait for that callback before you send commands to the reader. Commands that read or change the reader (software version, capabilities, configuration and so on) also need the ASCII connection that the delegate page opens in that callback with srfidEstablishAsciiConnection.
Keep the reader ID: the other tutorials pass it as readerID to every call. To close the session, see Disconnect.