# How to Use the SDK {#add-sdk} ## Adding the SDK ### TARGET -> Build Phases -> Link Binary With Libraries Add the SDK frameworks to your project. ![](../media/SDK-01.png) ### Select "Add Other..." ![](../media/SDK-02.png) Use the file browser to select the SDK framework files. ### Add AsReaderDockSDK.framework and AsReaderBLESDK.framework Add these two framework files to your project. ![](../media/SDK-03.png) ### After Adding Confirm that the frameworks have been properly added to the project’s linked libraries list. ![](../media/SDK-04.png) ## Add AsReader Protocols Add the following protocols to the `Supported external accessory protocols` entry in your plist file. - ASX - 510R, 520R: `jp.co.asx.asreader.barcode` - ASR - 010D, 020D, 022D, M24D: `jp.co.asx.asreader.6dongle.barcode` - ASX - 300R, ASX - 301R: `jp.co.asx.asreader.rfid` - ASR - 030D, ASR - 031D: `jp.co.asx.asreader.6dongle.rfid` - ASR - 0230D, ASR - 0240D: `jp.co.asx.asreader.0230D`, `jp.co.asx.asreader.0240D` - ASR-M30S: `jp.co.asx.asreader.slim` For example: ![](../media/SDK-05.png) ## Using the SDK in Your Class Import the header file in the class where you use the SDK. ```objectivec #import "AsReaderDevice.h" ``` ## Notes - To use Dock SDK4, your code must support C++. Either change your `.m` file that references SDK header files to `.mm`, or import the `libc++` library to build successfully. - When sending commands continuously, make sure to wait for the response of the previous command before sending the next one. Sending commands before receiving a response may cause unexpected behavior. ## Using the SDK ### Creating and Initializing AsReaderRFIDDevice (Singleton Pattern) ```objectivec AsReaderRFIDDevice *asReaderRFIDDevice = [AsReaderRFIDDevice sharedInstance]; ``` ### Setting Delegates ```objectivec [AsReaderRFIDDevice sharedInstance].delegateDevice = self; [AsReaderRFIDDevice sharedInstance].delegateRFID = self; ``` ### Receiving Device Connection State ```objectivec - (void)plugged:(BOOL)plug { if (plug) { AsReaderInfo *info = [AsReaderInfo sharedInstance]; if (!info.isEnginePowerAlwaysOn) { // ASR-030D requires power-on [[AsReaderRFIDDevice sharedInstance] setReaderPower:YES beep:YES vibration:YES batteryGaugeLed:YES barcodeAimer:YES barcodePowerOnBeep:YES mode:1]; } else { // ASR-M30, ASR-M24D do not require power-on } } } ``` ### Powering On the AsReader Device ```objectivec [[AsReaderRFIDDevice sharedInstance] setReaderPower:YES beep:YES vibration:YES batteryGaugeLed:YES barcodeAimer:YES barcodePowerOnBeep:YES mode:1]; ``` ### Receiving Device Power State ```objectivec - (void)readerConnected:(int)status { if (status == 0xFF) { // Power on successful } else { // Power on failed or already off } } ``` ### Starting Scan ```objectivec [[AsReaderRFIDDevice sharedInstance] startScan:0 readUntilInSec:0 repeatCycle:0]; ``` ### Starting RFID Tag Scan (with RSSI) ```objectivec [[AsReaderRFIDDevice sharedInstance] startReadTagsAndRssiWithTagNum:0 maxTime:0 repeatCycle:0]; ``` ### Receiving Scan Start Status ```objectivec - (void)startedReadScan:(int)status { if (status == 0x00) { // Scan started successfully } else { // Failed to start scan } } ``` ### Stopping RFID Tag Scan ```objectivec [[AsReaderRFIDDevice sharedInstance] stopScan]; ``` ### Receiving Scan Stop Status ```objectivec - (void)stopReadScan:(int)status { if (status == 0x00) { // Scan stopped successfully } else { // Failed to stop scan } } ``` ### Receiving Tag Data with RSSI ```objectivec - (void)pcEpcRssiReceived:(NSData *)pcEpc rssi:(int)rssi { // pcEpc: PCEPC data of the tag // rssi: RSSI value of the tag } ```