(Note)
- Use the iOS library (OPHBluetoothService.framework) / iOS method.
-
You need to register with Apple Developer to develop iOS applications.
For more information, click the following link to visit the Apple Developer website. -
After registration, you can download Xcode.
To download Xcode, click the following link to check the Xcode website. -
If you want to transfer the created app to the actual iOS device and check the operation, you need to register it in the iOS Developer Program.
For more information, click the following link to visit the iOS Developer Program website.
The following example explains the procedure from the state where the project "FirstApp" is created on Xcode. To create an Xcode project, Please check Apple developer documentation website.
In addition, this usage procedure explains the procedure when using the development language Objective-C and the development environment Xcode 12.5.OPHBluetoothService.framework
- Download the OPHBluetoothService.framework zip file from the following link.
Procedure for using the development environment
It is necessary to support the following two points in the development environment.
- Add ExternalAccessory.framework and OPHBluetoothService.framework from [Frameworks, Libraries, and Embedded Content] on the [General] tab of TARGETS of the project.
・ExternalAccessory.framework is added from the Xcode library by clicking [+] on the [Frameworks, Libraries, and Embedded Content] screen.
For more information on ExternalAccessory.framework, please see the ExternalAccessory website.
・OPHBluetoothService.framework is added from [Add Other] by clicking [+] on the [Frameworks, Libraries, and Embedded Content] screen.
- Add Supported external accessory protocols to Info.plist and specify jp.opto.opnprotocol .
Use of communication API
We will explain how to use the main API using sample code.
In addition, import is required to use the framework.
sample
#import <OPHBluetoothService/OPHBluetoothService.h>
- Generate / acquire OPHBluetoothService
All Bluetooth communication with OPH-5000i is done via OPHBluetoothService class.
You can create and get an instance by executing the sharedController () method of OPHBluetoothService.
Since there is only one instance of OPHBluetoothService running, it will be returned after it is created if it has not been created yet, and it will be returned if it has already been created.sampleOPHBluetoothService * sessionController = [OPHBluetoothService sharedController];
- Connect with OPH-5000i
You can connect to OPH-5000i by executing the setupControllerForAccessory () method of OPHBluetoothService.
In this sample, the accessory and protocol string, which are the arguments required to execute the setupControllerForAccessory () method, are acquired and connected.sampleNSArray *accessoryList = [[NSMutableArray alloc] initWithArray:[EAAccessoryManager sharedAccessoryManager] connectedAccessories]]; if(accessoryList == nil || accessoryList.count == 0) return NO; EAAccessory *accessory = [accessoryList lastObject]; OPHBluetoothService *service = [OPHBluetoothService sharedController]; NSArray *protocolStrings = [accessory protocolStrings]; if(protocolStrings == nil || [protocolStrings count]==0) return NO; NSString *protocolString = [protocolStrings objectAtIndex:0]; [service setupControllerForAccessory:accessory withProtocolString:protocolString];
- Open a session
If you are already connected, you can open a session with OPH-5000i by executing the openSession () method of OPHBluetoothService.sampleOPHBluetoothService * sessionController = [OPHBluetoothService sharedController]; [sessionController openSession];
- Close session
You can open a session with OPH-5000i by executing the closeSession () method of OPHBluetoothService.sampleOPHBluetoothService * sessionController = [OPHBluetoothService sharedController]; [sessionController closeSession];
- Check if it is connected to OPH-5000i
You can check if you are connected to OPH-5000i by checking the isConnected property of EAAccessory, which is the accessory property of OPHBluetoothService. If YES, you are connected.sampleisConnected = [[[ OPHBluetoothService sharedController] accessory] isConnected];
- Send to OPH-5000i
When sending to OPH-5000i, you can send to OPH-5000i by executing the writeData () method of OPHBluetoothService.
According to the accessory interface specifications, the maximum length of External Accessory Protocol messages that OPH-5000i (MFi accessory) can receive from iOS devices is 2036 bytes.sample-(IBAction)sendStringButtonClick:(id)sender { NSData *writeData = [@"TestSting" dataUsingEncoding:NSUTF8StringEncoding]; if(_service.isConnected){ //Send data to OPH-5000i [_service writeData: writeData]; } }
- Receive from OPH-5000i
In order to process the communication result between OPHBluetoothService and OPH-5000i, First, the class that processes the communication result must adopt the OPHBluetoothServiceDelegate protocol.
In this sample, the ViewController class uses this protocol.sample@interface ViewController & lt; OPHBluetoothServiceDelegate & gt { }
sampleOPHBluetoothService * sessionController = [OPHBluetoothService sharedController]; [service setDelegate: self];
sample- (void)bluetoothService:(OPHBluetoothService *)service receivedData:(NSData *)data { NSLog(@"receivedData: %@", data); }
Related matters
Last updated: 2022/05/09