Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PrintImageBleWriteDelegate.m 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // PrintImageBleWriteDelegate.m
  3. // RNBluetoothEscposPrinter
  4. //
  5. // Created by januslo on 2018/10/8.
  6. // Copyright © 2018年 Facebook. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "PrintImageBleWriteDelegate.h"
  10. @implementation PrintImageBleWriteDelegate
  11. - (void) didWriteDataToBle: (BOOL)success
  12. {NSLog(@"PrintImageBleWriteDelete diWriteDataToBle: %d",success?1:0);
  13. if(success){
  14. if(_now == -1){
  15. if(_pendingResolve) {_pendingResolve(nil); _pendingResolve=nil;}
  16. }else if(_now>=[_toPrint length]){
  17. // ASCII ESC M 0 CR LF
  18. // Hex 1B 4D 0 0D 0A
  19. // Decimal 27 77 0 13 10
  20. unsigned char * initPrinter = malloc(5);
  21. initPrinter[0]=27;
  22. initPrinter[1]=77;
  23. initPrinter[2]=0;
  24. initPrinter[3]=13;
  25. initPrinter[4]=10;
  26. [RNBluetoothManager writeValue:[NSData dataWithBytes:initPrinter length:5] withDelegate:self];
  27. _now = -1;
  28. [NSThread sleepForTimeInterval:0.01f];
  29. }else {
  30. [self print];
  31. }
  32. }else if(_pendingReject){
  33. _pendingReject(@"PRINT_IMAGE_FAILED",@"PRINT_IMAGE_FAILED",nil);
  34. _pendingReject = nil;
  35. }
  36. }
  37. -(void) print
  38. {
  39. @synchronized (self) {
  40. NSInteger sizePerLine = (int)(_width/8);
  41. // do{
  42. // if(sizePerLine+_now>=[_toPrint length]){
  43. // sizePerLine = [_toPrint length] - _now;
  44. // }
  45. // if(sizePerLine>0){
  46. NSData *subData = [_toPrint subdataWithRange:NSMakeRange(_now, sizePerLine)];
  47. NSLog(@"Write data:%@",subData);
  48. [RNBluetoothManager writeValue:subData withDelegate:self];
  49. //}
  50. _now = _now+sizePerLine;
  51. [NSThread sleepForTimeInterval:0.01f];
  52. }
  53. //}while(_now<[_toPrint length]);
  54. }
  55. @end