Commit 68cf9135 authored by lujunye's avatar lujunye

读取状态

parent c61c367e
...@@ -30,4 +30,7 @@ ...@@ -30,4 +30,7 @@
#import "HLBLEManager.h" #import "HLBLEManager.h"
#import "SVProgressHUD.h" #import "SVProgressHUD.h"
#import "BtViewController.h" #import "BtViewController.h"
#import "HLPrinter.h"
#import "UIWebView+UIImage.h"
#endif /* Bridge_Header_h */ #endif /* Bridge_Header_h */
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#import "HLPrinter.h" #import "HLPrinter.h"
#import "UIWebView+UIImage.h" #import "UIWebView+UIImage.h"
#import "Bt_Cell.h" #import "Bt_Cell.h"
@interface BtViewController ()<UITableViewDelegate,UITableViewDataSource> @interface BtViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView; @property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic)NSMutableArray *deviceArray; /**< 蓝牙设备个数 */ @property (strong, nonatomic)NSMutableArray *deviceArray; /**< 蓝牙设备个数 */
...@@ -26,6 +28,20 @@ ...@@ -26,6 +28,20 @@
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
/** 接收到数据回调 */
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
NSData *data = characteristic.value; //获取到的数据
NSLog(@"bbb-----%@----",data); //打印出来应该是<01a5>这样的数据,可以通过下面的方式去判断一些自己想要的逻辑
Byte * resultByte = (Byte *)[data bytes];
if(data.length>=1){
if(resultByte[0]==16){ //16代表前两位的值
NSLog(@"---打印机打开---");
}else if (resultByte[0]==1){ //01
NSLog(@"----打印机缺纸-----");
}
}
//下面的处理方式我没处理过,大家可以试试
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view from its nib. // Do any additional setup after loading the view from its nib.
...@@ -128,8 +144,10 @@ ...@@ -128,8 +144,10 @@
CBPeripheral *peripheral = dict[@"peripheral"]; CBPeripheral *peripheral = dict[@"peripheral"];
[self.selectArray addObject:peripheral]; [self.selectArray addObject:peripheral];
[self loadBLEInfo]; [self loadBLEInfo];
[tableView reloadData]; [tableView reloadData];
}else{ }else{
[_manager cancelPeripheralConnection]; [_manager cancelPeripheralConnection];
} }
...@@ -218,6 +236,7 @@ ...@@ -218,6 +236,7 @@
CBPeripheral *perpheral = _selectArray.firstObject; CBPeripheral *perpheral = _selectArray.firstObject;
HLBLEManager *manager = [HLBLEManager sharedInstance]; HLBLEManager *manager = [HLBLEManager sharedInstance];
_manager = manager; _manager = manager;
[manager connectPeripheral:perpheral [manager connectPeripheral:perpheral
connectOptions:@{CBConnectPeripheralOptionNotifyOnDisconnectionKey:@(YES)} connectOptions:@{CBConnectPeripheralOptionNotifyOnDisconnectionKey:@(YES)}
stopScanAfterConnected:YES stopScanAfterConnected:YES
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment