UniPRT SDK v2.0.0.0
 
载入中...
搜索中...
未找到
BleComm.h
1#import <Foundation/Foundation.h>
2#import <CoreBluetooth/CoreBluetooth.h>
3#import <UniPRT/AComm.h>
4NS_ASSUME_NONNULL_BEGIN
5
34@interface BleComm : AComm <CBCentralManagerDelegate, CBPeripheralDelegate>
35
39@property (nonatomic, strong) CBCentralManager *centralManager;
40
44@property (nonatomic, strong) NSMutableArray<NSString *> *discoveredDevices;
45
49@property (nonatomic, strong) NSMutableArray<CBPeripheral *> *foundPeripherals;
50
54@property (nonatomic, strong) CBPeripheral *connectedPeripheral;
55
59@property (nonatomic, strong) NSMutableArray<CBCharacteristic *> *writeCharacteristics;
60
64@property (nonatomic, strong) NSMutableArray<CBCharacteristic *> *readCharacteristics;
65
69@property (nonatomic, strong) NSMutableData *receivedData;
70
87- (NSArray<NSString *> *)availableDevices;
88
105- (void)open:(NSString *)deviceName;
106
120@property (nonatomic, copy) void (^ _Nullable characteristicsReadyCallback)(void);
121
139
150- (void)close;
151
168- (void)write:(NSData *)text;
169
186- (NSData *)read;
187
204- (void)waitForDataWithTimeout:(NSTimeInterval)msTimeOut;
205
234- (NSData *)writeAndWaitForResponse:(NSData *)text
235 responseStartTimeOut:(NSTimeInterval)responseStartTimeOut
236 responseEndTimeOut:(NSTimeInterval)responseEndTimeOut
237 completionToken:(NSString *)completionToken;
238
267- (NSData *)writeAndWaitForResponseJson:(NSData *)text
268 responseStartTimeOut:(NSTimeInterval)responseStartTimeOut
269 responseEndTimeOut:(NSTimeInterval)responseEndTimeOut
270 completionToken:(NSString *)completionToken;
271
272@end
273
274NS_ASSUME_NONNULL_END
一个用于通信接口的基类,符合 IComm 协议。
定义 AComm.h:29
void open()
打开通信接口。
用於處理藍牙低功耗 (BLE) 連線的通訊類。
定义 BleComm.h:34
NSData * read()
讀取從 BLE 設備接收的數據。
NSArray< NSString * > * availableDevices()
獲取可用的 BLE 設備列表。
void close()
斷開當前的 BLE 連線。
NSMutableArray< CBCharacteristic * > * readCharacteristics
定义 BleComm.h:64
NSMutableArray< CBPeripheral * > * foundPeripherals
定义 BleComm.h:49
void(^ _Nullable)(void)
所有 BLE 特徵值準備完成後會觸發的 callback。 在呼叫 open: 之前設定,可確保後續可以安全地進行資料操作。
CBCentralManager * centralManager
定义 BleComm.h:39
NSMutableArray< CBCharacteristic * > * writeCharacteristics
定义 BleComm.h:59
bool isConnected()
檢查 BLE 連線是否當前有效。
NSMutableData * receivedData
定义 BleComm.h:69
CBPeripheral * connectedPeripheral
定义 BleComm.h:54
NSMutableArray< NSString * > * discoveredDevices
定义 BleComm.h:44