seven365-zyprinter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/Package.swift +43 -0
  2. package/README.md +186 -0
  3. package/Seven365Zyprinter.podspec +27 -0
  4. package/android/build.gradle +58 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/mycompany/plugins/example/Example.java +342 -0
  7. package/android/src/main/java/com/mycompany/plugins/example/ExamplePlugin.java +161 -0
  8. package/android/src/main/res/.gitkeep +0 -0
  9. package/dist/docs.json +229 -0
  10. package/dist/esm/definitions.d.ts +56 -0
  11. package/dist/esm/definitions.js +2 -0
  12. package/dist/esm/definitions.js.map +1 -0
  13. package/dist/esm/index.d.ts +4 -0
  14. package/dist/esm/index.js +7 -0
  15. package/dist/esm/index.js.map +1 -0
  16. package/dist/esm/web.d.ts +49 -0
  17. package/dist/esm/web.js +40 -0
  18. package/dist/esm/web.js.map +1 -0
  19. package/dist/plugin.cjs.js +54 -0
  20. package/dist/plugin.cjs.js.map +1 -0
  21. package/dist/plugin.js +57 -0
  22. package/dist/plugin.js.map +1 -0
  23. package/ios/Seven365Zyprinter.podspec +28 -0
  24. package/ios/Sources/Plugin/ZyprintPlugin.swift +161 -0
  25. package/ios/Sources/Plugin/ZywellSDK.swift +358 -0
  26. package/ios/Sources/Seven365Zyprinter-Umbrella.h +16 -0
  27. package/ios/Sources/module.modulemap +12 -0
  28. package/ios/Sources/sources/BLEManager.h +658 -0
  29. package/ios/Sources/sources/BLEManager.m +2842 -0
  30. package/ios/Sources/sources/GCD/Documentation.html +47 -0
  31. package/ios/Sources/sources/GCD/GCDAsyncSocket.h +1226 -0
  32. package/ios/Sources/sources/GCD/GCDAsyncSocket.m +8560 -0
  33. package/ios/Sources/sources/GCD/GCDAsyncUdpSocket.h +1036 -0
  34. package/ios/Sources/sources/GCD/GCDAsyncUdpSocket.m +5632 -0
  35. package/ios/Sources/sources/GCD/PrinterManager.h +91 -0
  36. package/ios/Sources/sources/GCD/PrinterManager.m +513 -0
  37. package/ios/Sources/sources/GCD/WifiManager.h +91 -0
  38. package/ios/Sources/sources/GCD/WifiManager.m +510 -0
  39. package/ios/Sources/sources/ImageTranster.h +38 -0
  40. package/ios/Sources/sources/ImageTranster.m +389 -0
  41. package/ios/Sources/sources/POSBLEManager.h +759 -0
  42. package/ios/Sources/sources/POSBLEManager.m +834 -0
  43. package/ios/Sources/sources/POSSDK.h +93 -0
  44. package/ios/Sources/sources/POSWIFIManager.h +116 -0
  45. package/ios/Sources/sources/POSWIFIManager.m +260 -0
  46. package/ios/Sources/sources/POSWIFIManagerAsync.h +745 -0
  47. package/ios/Sources/sources/POSWIFIManagerAsync.m +1847 -0
  48. package/ios/Sources/sources/PosCommand.h +633 -0
  49. package/ios/Sources/sources/PosCommand.m +1019 -0
  50. package/ios/Sources/sources/TscCommand.h +723 -0
  51. package/ios/Sources/sources/TscCommand.m +566 -0
  52. package/ios/Tests/ExamplePluginTests/ExamplePluginTests.swift +15 -0
  53. package/package.json +339 -0
@@ -0,0 +1,91 @@
1
+ ////
2
+ //// PrinterManager.h
3
+ //// Printer
4
+ ////
5
+ //// Created by ding on 2021/12/14.
6
+ //// Copyright © 2021 Admin. All rights reserved.
7
+ ////
8
+ //
9
+ //#import <Foundation/Foundation.h>
10
+ //#import "GCDAsyncSocket.h"
11
+ //#import "BLEManager.h"
12
+ //NS_ASSUME_NONNULL_BEGIN
13
+ //
14
+ //@interface PrinterManager : NSObject
15
+ //#pragma mark - 基本属性
16
+ ////打印机类型
17
+ //typedef enum {
18
+ // WifiPrinter=0,
19
+ // BlePrinter
20
+ //} PrinterType;
21
+ ////打印机状态
22
+ //typedef enum {
23
+ // Normal=0,
24
+ // Error,
25
+ // Printing,
26
+ // Busy,
27
+ // CashDrawerOpened,
28
+ // CoverOpened,
29
+ // PaperNearEnd,
30
+ // NoPaper,
31
+ // CutPaper,
32
+ // FeedPaper,
33
+ // PrintCompleted,
34
+ // Disconnected
35
+ //} PrinterStatus;
36
+ ////主机地址
37
+ //@property (nonatomic,copy) NSString *ip;
38
+ ////端口
39
+ //@property (nonatomic,assign) UInt16 port;
40
+ ////是否连接成功
41
+ //@property (nonatomic,assign) BOOL isConnected;
42
+ ////接收到的数据
43
+ //@property(nonatomic,copy)NSData* receivedData;
44
+ ////是否成功监控打印机的状态
45
+ //@property (nonatomic,assign) BOOL isReceivedData;
46
+ ////打印机类型
47
+ //@property(nonatomic,assign)NSUInteger printerType;
48
+ ////打印机状态
49
+ //@property(nonatomic,assign)int printerStatus;
50
+ //@property(strong,nonatomic) NSTimer *timer;
51
+ ////监控端口号
52
+ //@property(nonatomic,assign)int monitorPort;
53
+ ////打印端口号
54
+ //@property(nonatomic,assign)int printPort;
55
+ ////打印是否成功
56
+ //@property(nonatomic,assign)bool printSucceed;
57
+ ////是否自动重连
58
+ //@property(nonatomic,assign)bool isAutoRecon;
59
+ ////是否是用户主动断开连接
60
+ //@property(nonatomic,assign)bool isUserDiscon;
61
+ //@property(nonatomic,assign)bool isFirstRece;
62
+ ////是否是2022/3/28以后出厂的机器
63
+ //@property(nonatomic,assign)bool isNewPrinter;
64
+ //#pragma mark - 基本方法
65
+ ////+ (instancetype)shareManager:(int)printerType;
66
+ //+ (instancetype)shareManager:(int)printerType threadID:(NSString*)thread;
67
+ ////连接wifi打印机
68
+ //-(bool)ConnectWifiPrinter:(NSString *)ip port:(UInt16)port;
69
+ ////开启打印机监控
70
+ //-(void)StartMonitor;
71
+ ////退出禁止打印状态
72
+ //-(NSData*)exitForbidPrinting;
73
+ ////免丢单指令
74
+ //-(void)freeLostOrder;
75
+ ////连接ble打印机
76
+ //-(void)ConnectBlePrinter:(CBPeripheral *)peripheral;
77
+ //// 断开打印机连接
78
+ //- (void)DisConnectPrinter;
79
+ ////发送指令到打印机
80
+ //-(bool)SendDataToPrinter:(NSData *)data;
81
+ ////发送订单到打印机,有打印机状态判断
82
+ //-(bool)SendReceiptToPrinter:(NSData *)data;
83
+ ////读取打印机返回的数据
84
+ //-(void)ReadDataFromPrinter;
85
+ ////获取打印机当前状态
86
+ //-(NSString*)GetPrinterStatus;
87
+ ////打印是否完整判断
88
+ //-(BOOL)IsPrintCompletely;
89
+ //@end
90
+ //
91
+ //NS_ASSUME_NONNULL_END
@@ -0,0 +1,513 @@
1
+ ////
2
+ //// PrinterManager.m
3
+ //// Printer
4
+ ////
5
+ //// Created by ding on 2021/12/14.
6
+ //// Copyright © 2021 Admin. All rights reserved.
7
+ ////
8
+ //
9
+ //#import "PrinterManager.h"
10
+ //
11
+ //static PrinterManager *shareManager = nil;
12
+ //@interface PrinterManager ()<GCDAsyncSocketDelegate,BLEManagerDelegate>
13
+ ////连接的wifi socket对象
14
+ //@property (nonatomic,strong) GCDAsyncSocket *wifiPrinter;
15
+ //@property (nonatomic,strong) GCDAsyncSocket *wifiPrinterMonitor;
16
+ ////ble打印机对象
17
+ //@property (nonatomic,strong) BLEManager *blePrinter;
18
+ //@end
19
+ //@implementation PrinterManager
20
+ //+ (instancetype)shareManager:(int)printerType threadID:(NSString*)thread{
21
+ // shareManager = [[PrinterManager alloc] init:printerType threadID:thread];
22
+ // return shareManager;
23
+ //}
24
+ //
25
+ //- (instancetype)init:(int)printerType threadID:(NSString*)thread{
26
+ // if (self = [super init]) {
27
+ // _isConnected=false;
28
+ // _printerType=printerType;
29
+ // _printerStatus=Disconnected;
30
+ // _printSucceed=false;
31
+ // _monitorPort=9100;
32
+ // _printPort=9100;
33
+ // _isAutoRecon=false;
34
+ // _isFirstRece=true;
35
+ // _isReceivedData=false;
36
+ // _isNewPrinter=false;
37
+ // switch (printerType) {
38
+ // case WifiPrinter:
39
+ // {
40
+ // dispatch_queue_t queue = dispatch_queue_create([thread UTF8String], DISPATCH_QUEUE_SERIAL);
41
+ // _wifiPrinter=[[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:queue];
42
+ // if(_monitorPort==4000){
43
+ // dispatch_queue_t queue2 = dispatch_queue_create("com.printer.monitor", DISPATCH_QUEUE_SERIAL);
44
+ // _wifiPrinterMonitor=[[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:queue2];
45
+ // }
46
+ // }
47
+ // break;
48
+ // case BlePrinter:
49
+ // {
50
+ //
51
+ // }
52
+ // break;
53
+ // default:
54
+ // break;
55
+ // }
56
+ // }
57
+ // return self;
58
+ //}
59
+ ////连接wifi打印机
60
+ //-(bool)ConnectWifiPrinter:(NSString *)ip port:(UInt16)port{
61
+ // if(!_isConnected){
62
+ // _ip=ip;
63
+ // _port=port;
64
+ // NSError *err = nil;
65
+ // _isFirstRece=true;
66
+ // _isUserDiscon=false;
67
+ // _isReceivedData=false;
68
+ // _isNewPrinter=false;
69
+ // _isConnected=[_wifiPrinter connectToHost:ip onPort:port withTimeout:-1 error:&err];
70
+ // if(!_isConnected){
71
+ // _isConnected=false;
72
+ // _printerStatus=Disconnected;
73
+ // _isUserDiscon=true;
74
+ // NSLog(@"connect failed\n");
75
+ // }else{
76
+ // _isConnected=true;
77
+ // //NSLog(@"connect success\n");
78
+ // _printerStatus=Normal;
79
+ // }
80
+ // if(_monitorPort==4000&&_isConnected){
81
+ // [_wifiPrinterMonitor connectToHost:ip onPort:4000 error:&err];
82
+ // }
83
+ // NSDate* tmpStartData = [NSDate date];
84
+ // while(_isFirstRece){
85
+ // double timeout = [[NSDate date] timeIntervalSinceDate:tmpStartData];
86
+ // if(timeout>2){//连接超时
87
+ // _isConnected=false;
88
+ // _printerStatus=Disconnected;
89
+ // _isUserDiscon=true;
90
+ // NSLog(@"connect timeout,connect failed\n");
91
+ // break;
92
+ // }
93
+ // }
94
+ // if(!_isFirstRece){
95
+ // _isConnected=true;
96
+ // NSLog(@"didconnect,connect success\n");
97
+ // _printerStatus=Normal;
98
+ // [self exitForbidPrinting];
99
+ // }
100
+ // }
101
+ // return _isConnected;
102
+ //}
103
+ //-(void)StartMonitor{
104
+ // //开启免丢单功能,发送监控指令,通过timer获取打印机的状态
105
+ // //设置一个timer,定时执行OnclickStart方法
106
+ // //timer需要增加到当前子线程中
107
+ // _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(ReadDataFromPrinter) userInfo:nil repeats:YES];
108
+ // NSRunLoop *runloop = [NSRunLoop currentRunLoop];
109
+ // // [runloop addTimer:_timer forMode:NSDefaultRunLoopMode];
110
+ // [runloop addTimer:_timer forMode:NSRunLoopCommonModes];
111
+ // if(_monitorPort==_printPort&&_isConnected){
112
+ // //free lost order,需要先设置一次,重启打印机有效
113
+ // Byte free[]={0x1B, 0x73, 0x42, 0x45, 0x92, 0x9A, 0x01, 0x00, 0x5F, 0x0A};
114
+ // //9100端口监控指令
115
+ // Byte b[]={0x1d,0x61,0x1f};
116
+ // [_wifiPrinter writeData:[[NSData alloc]initWithBytes:b length:3] withTimeout:-1 tag:1];
117
+ // //2022/7/5 DING 增加获取固件版本的功能
118
+ // //NSLog(@"获取打印机固件版本");
119
+ // [_wifiPrinter writeData:[self GetFirmwareVersion] withTimeout:-1 tag:2];
120
+ // [_wifiPrinter readDataWithTimeout:-1 tag:2];
121
+ // }
122
+ // [runloop run];
123
+ //}
124
+ //-(NSData*)exitForbidPrinting{
125
+ // Byte exitForbidPrinting[]={0x1b,0x41};//退出禁止打印状态
126
+ // return [[NSData alloc] initWithBytes:exitForbidPrinting length:sizeof(exitForbidPrinting)];
127
+ //}
128
+ //-(void)freeLostOrder{
129
+ // Byte freeLostOrder[]={0x1B, 0x73, 0x42, 0x45, 0x92, 0x9A, 0x01, 0x00, 0x5F, 0x0A};//免丢单指令
130
+ // [_wifiPrinter writeData:[[NSData alloc]initWithBytes:freeLostOrder length:freeLostOrder] withTimeout:-1 tag:0];
131
+ //}
132
+ //-(bool)ReconWifiPrinter:(NSString *)ip port:(UInt16)port{
133
+ // if(!_isConnected){
134
+ // _ip=ip;
135
+ // _port=port;
136
+ // NSError *err = nil;
137
+ // _isFirstRece=true;
138
+ // _isConnected=[_wifiPrinter connectToHost:ip onPort:port withTimeout:-1 error:&err];
139
+ // if(!_isConnected){
140
+ // _isConnected=false;
141
+ // _printerStatus=Disconnected;
142
+ // //NSLog(@"connect failed\n");
143
+ // }else{
144
+ // _isConnected=true;
145
+ // //NSLog(@"connect success\n");
146
+ // _printerStatus=Normal;
147
+ // }
148
+ // }
149
+ // return _isConnected;
150
+ //}
151
+ ////连接ble打印机
152
+ //-(void)ConnectBlePrinter:(CBPeripheral *)peripheral{
153
+ //
154
+ //}
155
+ //// 断开打印机连接
156
+ //- (void)DisConnectPrinter{
157
+ // NSLog(@"disconnect printer");
158
+ // _isUserDiscon=true;
159
+ // switch (_printerType) {
160
+ // case WifiPrinter:
161
+ // {
162
+ // [_wifiPrinter disconnect];
163
+ // }
164
+ // break;
165
+ // case BlePrinter:
166
+ // {
167
+ //
168
+ // }
169
+ // break;
170
+ // default:
171
+ // break;
172
+ // }
173
+ //}
174
+ ////发送数据到打印机
175
+ //-(bool)SendReceiptToPrinter:(NSData *)data{
176
+ // switch (_printerType) {
177
+ // case WifiPrinter:
178
+ // {
179
+ // //区分新旧打印机的打印流程,旧的打印机不做状态查询的处理
180
+ // _printSucceed=false;
181
+ // if(_isNewPrinter){//新机发送流程
182
+ // if((_printerStatus==Normal||_printerStatus==PrintCompleted)&&_isConnected){
183
+ // NSMutableData* dataM=[[NSMutableData alloc] init];
184
+ // Byte init[]={0x1b,0x40};
185
+ // [dataM appendBytes:init length:sizeof(init)];
186
+ // [dataM appendData:data];
187
+ // Byte cutPaper[]={0x1D,0x56,0x42,0x00,0x0A,0x0A,0x00};//切纸指令需要在订单指令前
188
+ // Byte b[]={0x1D,0x28,0x48,0x06,0x00,0x30,0x30,0x30,0x30,0x30,0x31};//订单号,会在打印完数据后返回到客户端
189
+ // [dataM appendBytes:cutPaper length:sizeof(cutPaper)];
190
+ // [dataM appendBytes:b length:sizeof(b)];
191
+ // [_wifiPrinter writeData:dataM withTimeout:-1 tag:0];
192
+ // NSDate* tmpStartData = [NSDate date];
193
+ // while(!_printSucceed){
194
+ // double timeout = [[NSDate date] timeIntervalSinceDate:tmpStartData];
195
+ // if(timeout>60||_printerStatus==CoverOpened||_printerStatus==NoPaper||_printerStatus==Error||_printerStatus==Disconnected){//打印数据超时,默认为1分钟;出现错误状况打印失败
196
+ // Byte exitForbidPrinting[]={0x1b,0x41};//退出禁止打印状态
197
+ // [_wifiPrinter writeData:[[NSData alloc]initWithBytes:exitForbidPrinting length:2] withTimeout:-1 tag:0];
198
+ // NSLog(@"timeout,cost time = %f seconds", timeout);
199
+ // _printSucceed=false;
200
+ // if (_printerStatus==Normal) {
201
+ // _isConnected=false;
202
+ // _printerStatus=Disconnected;
203
+ // }
204
+ // break;
205
+ // }
206
+ // }
207
+ // }else{
208
+ // Byte exitForbidPrinting[]={0x1b,0x41};//退出禁止打印状态
209
+ // [_wifiPrinter writeData:[[NSData alloc]initWithBytes:exitForbidPrinting length:2] withTimeout:-1 tag:0];
210
+ // _printSucceed=false;
211
+ // NSLog(@"Printer status %@\n",[self statusToString:_printerStatus]);
212
+ // }
213
+ // }else{
214
+ // [self SendDataToPrinter:data];
215
+ // }
216
+ // }
217
+ // break;
218
+ // case BlePrinter:
219
+ // {
220
+ //
221
+ // }
222
+ // break;
223
+ // default:
224
+ // break;
225
+ // }
226
+ // return _printSucceed;
227
+ //}
228
+ ////旧机发送流程
229
+ //-(bool)SendDataToPrinter:(NSData *)data{
230
+ // switch (_printerType) {
231
+ // case WifiPrinter:
232
+ // {
233
+ // _printSucceed=true;
234
+ // if((_printerStatus==Normal)&&_isConnected){
235
+ // //NSMutableData* dataM=[[NSMutableData alloc] initWithData:data];
236
+ // //[_wifiPrinter writeData:dataM withTimeout:-1 tag:0];
237
+ // NSMutableData* dataM=[[NSMutableData alloc] init];
238
+ // Byte init[]={0x1b,0x40};
239
+ // [dataM appendBytes:init length:sizeof(init)];
240
+ // [dataM appendData:data];
241
+ // Byte cutPaper[]={0x1D,0x56,0x42,0x00,0x0A,0x0A,0x00};
242
+ // [dataM appendBytes:cutPaper length:sizeof(cutPaper)];
243
+ // [_wifiPrinter writeData:dataM withTimeout:-1 tag:0];
244
+ // NSDate* tmpStartData = [NSDate date];
245
+ // while(!_isReceivedData){
246
+ // double timeout = [[NSDate date] timeIntervalSinceDate:tmpStartData];
247
+ // if(timeout>3||_printerStatus==CoverOpened||_printerStatus==NoPaper||_printerStatus==Error||_printerStatus==Disconnected){//打印数据超时,默认为3秒钟;出现错误状况打印失败
248
+ // Byte exitForbidPrinting[]={0x1b,0x41};//退出禁止打印状态
249
+ // [_wifiPrinter writeData:[[NSData alloc]initWithBytes:exitForbidPrinting length:sizeof(exitForbidPrinting)] withTimeout:-1 tag:0];
250
+ // NSLog(@"timeout,cost time = %f seconds", timeout);
251
+ // _printSucceed=false;
252
+ // if (_printerStatus==Normal) {
253
+ // _isConnected=false;
254
+ // _printerStatus=Disconnected;
255
+ // }
256
+ // break;
257
+ // }
258
+ // }
259
+ // }else{
260
+ // Byte exitForbidPrinting[]={0x1b,0x41};//退出禁止打印状态
261
+ // [_wifiPrinter writeData:[[NSData alloc]initWithBytes:exitForbidPrinting length:sizeof(exitForbidPrinting)] withTimeout:-1 tag:0];
262
+ // _printSucceed=false;
263
+ // NSLog(@"Printer status %@\n",[self statusToString:_printerStatus]);
264
+ // }
265
+ // }
266
+ // break;
267
+ // case BlePrinter:
268
+ // {
269
+ //
270
+ // }
271
+ // break;
272
+ // default:
273
+ // break;
274
+ // }
275
+ // return _printSucceed;
276
+ //}
277
+ ////读取打印机返回的数据
278
+ //-(void)ReadDataFromPrinter{
279
+ // _receivedData=nil;
280
+ // if(_monitorPort==4000){
281
+ // //4000端口监控指令,需要在每次读取打印机状态时进行发送
282
+ // Byte b[]={0x1b,0x76};
283
+ // [_wifiPrinterMonitor writeData:[[NSData alloc]initWithBytes:b length:2] withTimeout:-1 tag:1];
284
+ // //调用读取函数,通过didread返回
285
+ // [_wifiPrinterMonitor readDataWithTimeout:-1 tag:1];
286
+ // }else{
287
+ // //调用读取函数,通过didread返回
288
+ // [_wifiPrinter readDataWithTimeout:-1 tag:1];
289
+ // }
290
+ //}
291
+ ////获取打印机当前状态
292
+ //-(NSString*)GetPrinterStatus{
293
+ // if(!_isReceivedData){
294
+ // _printerStatus=Error;
295
+ // }
296
+ // return [self statusToString:_printerStatus];
297
+ //}
298
+ ////打印是否完整判断
299
+ //-(BOOL)IsPrintCompletely{
300
+ // return false;
301
+ //}
302
+ ////打印机状态字符串
303
+ //- (NSString*)statusToString:(PrinterStatus)printerStatus {
304
+ // NSString *result = nil;
305
+ // switch(printerStatus) {
306
+ // case Normal:
307
+ // result = @"Normal";
308
+ // break;
309
+ // case Error:
310
+ // result = @"Error";
311
+ // break;
312
+ // case Printing:
313
+ // result = @"Printing";
314
+ // break;
315
+ // case Busy:
316
+ // result = @"Busy";
317
+ // break;
318
+ // case CashDrawerOpened:
319
+ // result = @"CashDrawerOpened";
320
+ // break;
321
+ // case CoverOpened:
322
+ // result = @"CoverOpened";
323
+ // break;
324
+ // case PaperNearEnd:
325
+ // result = @"PaperNearEnd";
326
+ // break;
327
+ // case NoPaper:
328
+ // result = @"NoPaper";
329
+ // break;
330
+ // case CutPaper:
331
+ // result = @"CutPaper";
332
+ // break;
333
+ // case FeedPaper:
334
+ // result = @"FeedPaper";
335
+ // break;
336
+ // case PrintCompleted:
337
+ // result=@"PrintCompleted";
338
+ // break;
339
+ // case Disconnected:
340
+ // result=@"Printer Disconnected";
341
+ // break;
342
+ // default:
343
+ // [NSException raise:NSGenericException format:@"Unexpected status."];
344
+ // }
345
+ //
346
+ // return result;
347
+ //}
348
+ ////2022/7/5 DING 获取打印机的固件版本 只有9100端口有效
349
+ //-(NSData*)GetFirmwareVersion{
350
+ // Byte data[] = {0x1d,0x49,0xd9};
351
+ // return [[NSData alloc] initWithBytes:data length:sizeof(data)];
352
+ //}
353
+ //#pragma mark wifi
354
+ //- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port{
355
+ // if(sock.isConnected){
356
+ // //NSLog(@"didconnect to host");
357
+ // _isConnected=true;
358
+ // _printerStatus=Normal;
359
+ // _isFirstRece=false;
360
+ // }
361
+ //}
362
+ //- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag{
363
+ // if(sock.connectedPort==_monitorPort||sock.connectedPort==_printPort){
364
+ // // NSLog(@"data=%@,tag=%ld", data,tag);//tag不准确
365
+ // _receivedData=data;
366
+ // _isReceivedData=true;
367
+ // Byte b[data.length];
368
+ // bool printCompelte=false;
369
+ // Byte jobID[]={0x37,0x22,0x30,0x30,0x30,0x31,0x00};
370
+ // for (int i = 0 ; i < data.length; i++) {
371
+ // NSData *idata = [data subdataWithRange:NSMakeRange(i, 1)];
372
+ // b[i] =((Byte*)[idata bytes])[0];
373
+ // }
374
+ // //打印机的订单号可能会跟状态一起返回,所以需要判断子串比较准确
375
+ // for(int i=0,j=0;i<data.length&&data.length>=7&&j<sizeof(jobID);i++){
376
+ // if(b[i]==jobID[j]){
377
+ // j++;
378
+ // if(j==sizeof(jobID)){
379
+ // printCompelte=true;
380
+ // _printSucceed=true;
381
+ // _printerStatus=PrintCompleted;
382
+ // }
383
+ // }
384
+ // }
385
+ // if(data.length>=29){//获取打印机的固件版本
386
+ // //要先去掉字符串中可能包含的订单号和状态值
387
+ // NSString* printerInfo=[[NSString alloc] initWithData: [data subdataWithRange:NSMakeRange(data.length-29,29)] encoding:NSASCIIStringEncoding];
388
+ // NSString* printerDate=[printerInfo substringToIndex:6];
389
+ // //NSLog(@"打印机版本:%@",printerInfo);
390
+ // //NSLog(@"打印机版本:%@",printerDate);
391
+ // if(printerDate!=nil && [printerDate compare:@"220401"]!=NSOrderedAscending){//2022.4.01 以后的机器
392
+ // NSLog(@"Printers after 2022.4.01");
393
+ // _isNewPrinter=true;
394
+ // }else{
395
+ // NSLog(@"Printers before 2022.4.01");
396
+ // _isNewPrinter=false;
397
+ // }
398
+ // }
399
+ // if(data.length==4){
400
+ // //0x1400602f 状态下面不能打印
401
+ // Byte nomralBytes[]={0x14,0x00,0x00,0x0f};
402
+ // if(data.bytes==nomralBytes){
403
+ // _printerStatus=Normal;
404
+ // }
405
+ // else{
406
+ // //first byte
407
+ // if ((b[0] & (0x04)) != 0) {//cash
408
+ // _printerStatus=CashDrawerOpened;
409
+ // _printerStatus=Normal;
410
+ // } else {
411
+ // //n
412
+ // }
413
+ // if ((b[0] & (0x08)) != 0) {// busy
414
+ // _printerStatus=Busy;
415
+ // } else {
416
+ // //n
417
+ // }
418
+ // if ((b[0] & (0x20)) != 0) { // cover
419
+ // _printerStatus=CoverOpened;
420
+ // } else {
421
+ // //n
422
+ // }
423
+ // if (((b[0] & (0x40)) != 0)){//feedpaper
424
+ // _printerStatus=FeedPaper;
425
+ // } else {
426
+ // //n
427
+ // }
428
+ // //second byte
429
+ // if ((b[1] & (0x08)) != 0) {//cutpaper
430
+ // _printerStatus=CutPaper;
431
+ // NSLog(@"Printer status %@\n",[self statusToString:_printerStatus]);
432
+ // } else {
433
+ // //n
434
+ // }
435
+ // if ((b[1] & (0x20)) != 0) {//fatal
436
+ // _printerStatus=Error;
437
+ // } else {
438
+ // //n
439
+ // }
440
+ // if ((b[1] & (0x40)) != 0) {//autorestor
441
+ // //y
442
+ // } else {
443
+ // //n
444
+ // }
445
+ //
446
+ // //third byte
447
+ // if ((b[2] & (0x03)) != 0) {//papernearend
448
+ // _printerStatus=PaperNearEnd;
449
+ // } else {
450
+ // //n
451
+ // }
452
+ //
453
+ // if ((b[2] & (0x0C)) != 0) {//nopaper
454
+ // _printerStatus=NoPaper;
455
+ // } else {
456
+ // //n
457
+ // }
458
+ //
459
+ // if ((b[2] & (0x40)) != 0) {//printpaper
460
+ // _printerStatus=Printing;
461
+ // _printerStatus=Normal;
462
+ // } else {
463
+ // //n
464
+ // }
465
+ // }
466
+ // }
467
+ //
468
+ // }
469
+ //}
470
+ //- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag{
471
+ // if(sock.isDisconnected){
472
+ // _isConnected=false;
473
+ // _printerStatus=Disconnected;
474
+ // }
475
+ //}
476
+ //- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(nullable NSError *)err{
477
+ // if(sock.isDisconnected){
478
+ // _isConnected=false;
479
+ // _printerStatus=Disconnected;
480
+ // // NSLog(@"printer disconnected");
481
+ // if(_isAutoRecon&&!_isUserDiscon){
482
+ // //如果重新连接失败就不重复
483
+ // _isAutoRecon=[self ReconWifiPrinter:_ip port:_port];
484
+ // if(_isAutoRecon){
485
+ // //NSLog(@"reconnect success");
486
+ // }else{
487
+ // NSLog(@"reconnect failed,check printer ip or power");
488
+ // }
489
+ // }
490
+ // }
491
+ //}
492
+ //#pragma mark ble
493
+ //- (void)BLEManagerDelegate:(BLEManager *)BLEmanager connectPeripheral:(CBPeripheral *)peripheral {
494
+ //
495
+ //}
496
+ //
497
+ //- (void)BLEManagerDelegate:(BLEManager *)BLEmanager didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
498
+ //
499
+ //}
500
+ //
501
+ //- (void)BLEManagerDelegate:(BLEManager *)BLEmanager didWriteValueForCharacteristic:(CBCharacteristic *)character error:(NSError *)error {
502
+ //
503
+ //}
504
+ //
505
+ //- (void)BLEManagerDelegate:(BLEManager *)BLEmanager disconnectPeripheral:(CBPeripheral *)peripheral isAutoDisconnect:(BOOL)isAutoDisconnect {
506
+ //
507
+ //}
508
+ //
509
+ //- (void)BLEManagerDelegate:(BLEManager *)BLEmanager updatePeripheralList:(NSArray *)peripherals RSSIList:(NSArray *)RSSIArr {
510
+ //
511
+ //}
512
+ //
513
+ //@end