0

I am working on ESC-POS printing systems, I can print the message using below code but it's not printing entire text.

NSMutableData* commandData = [[NSMutableData alloc] init];
[commandData appendBytes:"ESC" "@" length:0];
[commandData appendBytes:"ESC" "!" "0" length:0];
[commandData appendBytes:"ESC" "d" "20" length:0];

NSString *text = @"\nUnderline exceptions\n- Does not underline 90°/270° rotation\n- Does not underline horizontal tabs\n- Underline thickness";
NSData* data = [text dataUsingEncoding:NSUTF8StringEncoding];
[commandData appendData:data];

NSString *text1 = @"\nThis command resets the left and right margins\n- Left margin set by :ref:`Left Margin<1d4c>`\n- Right margin set by :ref:`Print Area Width<1d57>`\nFor each of the underline, italic, bold modes:\n- These can be issued by their respective ESC commands or this command\n- The last received command is the effective command.;\nThis command resets the left and right margins\n- Left margin set by :ref:`Left Margin<1d4c>`\n- Right margin set by :ref:`Print Area Width<1d57>`\nFor each of the underline, italic, bold modes:\n- These can be issued by their respective ESC commands or this command\n- The last received command is the effective command.;";
NSData* data1 = [text1 dataUsingEncoding:NSUTF8StringEncoding];
[commandData appendData:data1];

const void* sendBuffer = (unsigned char*)[commandData bytes];
NSUInteger sendLength =commandData.length;

if(sendLength==7){
    sendLength=7;//for Test
}

if (self.discoveredCharacteristic != nil){
    [self.discoveredPeripheral writeValue:[NSData dataWithBytes:sendBuffer length:sendLength] forCharacteristic:self.discoveredCharacteristic type:CBCharacteristicWriteWithResponse];
}

let me know where I am doing the mistake.

Thanks in advance.

Thukaram
  • 1,085
  • 2
  • 13
  • 33
  • Why you do `writeValue:[NSData dataWithBytes:sendBuffer length:sendLength]` and not `writeValue:commandData` instead? – Larme Feb 20 '18 at 14:41
  • @Larme, writeValue:commandData is not available. If possible post the code. – Thukaram Feb 20 '18 at 14:45
  • I meant: `[self.discoveredPeripheral writeValue:commandData forCharacteristic:self.discoveredCharacteristic type:CBCharacteristicWriteWithResponse];` instead of `[self.discoveredPeripheral writeValue:[NSData dataWithBytes:sendBuffer length:sendLength] forCharacteristic:self.discoveredCharacteristic type:CBCharacteristicWriteWithResponse];` Because you are doing `NSData` => `Byte` => `NSData`, that's unecessary. – Larme Feb 20 '18 at 14:51
  • @Larme, still same issue. – Thukaram Feb 21 '18 at 11:36

0 Answers0