printing - Make a bytes packet and send to External accessory Device for print using Bluetooth in iOS -


i working print image using external accessory in ios have problem send request printer.
here, attached image in packet need send printer. don't know how make packet , send packet printer.

packet data

here, attached sample code make packet , send external accessory device (printer) using objective c language.

- (void)printimage:(uiimage *)image     {         nsmutabledata* imagedata = [uiimagejpegrepresentation(image, 0.0) mutablecopy];      nsmutabledata *requestdata=[[nsmutabledata alloc]init];      nsstring *bitseries = @"";     nsdata *data = [[nsdata alloc]init];     //    1     bitseries = @"00011011";     data=[self stringtodata:bitseries];     nslog(@"1 : %@", data);     [requestdata appenddata:data];     //    2     bitseries = @"00101010";     data=[self stringtodata:bitseries];     nslog(@"2 : %@", data);     [requestdata appenddata:data];     //    3     bitseries = @"01000011";     data=[self stringtodata:bitseries];     nslog(@"3 : %@", data);     [requestdata appenddata:data];     //    4     bitseries = @"01000001";     data=[self stringtodata:bitseries];     nslog(@"4 : %@", data);     [requestdata appenddata:data];     //    5     bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"5 : %@", data);     [requestdata appenddata:data];     //    6     bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"6 : %@", data);     [requestdata appenddata:data];     //    7     bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"7 : %@", data);     [requestdata appenddata:data];     //    8     bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"8 : %@", data);     [requestdata appenddata:data];     //    9      nsmutablearray *arrstr = [self inttobinary:(int)[imagedata length]];      bitseries = [arrstr objectatindex:0];     data=[self stringtodata:bitseries];     nslog(@"9 : %@", data);     [requestdata appenddata:data];      bitseries = [arrstr objectatindex:1];     data=[self stringtodata:bitseries];     nslog(@"9 : %@", data);     [requestdata appenddata:data];      bitseries =[arrstr objectatindex:2];     data=[self stringtodata:bitseries];     nslog(@"9 : %@", data);     [requestdata appenddata:data];      //    10     bitseries = @"00000001";     data=[self stringtodata:bitseries];     nslog(@"10 : %@", data);     [requestdata appenddata:data];     //    11     bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"11 : %@", data);     [requestdata appenddata:data];     //    12     bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"12 : %@", data);     [requestdata appenddata:data];      bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"12 : %@", data);     [requestdata appenddata:data];      //    13     bitseries = @"00000000";     data=[self stringtodata:bitseries];     nslog(@"13 : %@", data);     [requestdata appenddata:data];      nslog(@"final data : %@", requestdata);       if (imagedata !=nil)     {         sessiondata *obj=[sessiondata sharedinstance];         obj.imagedata=imagedata;         obj.requestdata = requestdata;         [obj setupsessionmanager];     }     else     {         [[[uialertview alloc]initwithtitle:@"error" message:@"please select image." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil] show];     } }  -(nsdata *)stringtodata : (nsstring *)bitseries {     uint8_t value = strtoul([bitseries utf8string], null, 2);     nslog(@"bitseries : %@ -------> value : %u",bitseries, value);     nsdata *data = [nsdata datawithbytes:&value length:sizeof(value)];     return data; }  - (nsmutablearray *)inttobinary:(int)number {     int bits =  sizeof(number) * 8;     int bitcnt=bits;      nsmutablearray *arrstr=[[nsmutablearray alloc]init];     nsmutablestring *binarystr = [nsmutablestring string];      (; bits > 0; bits--, number >>= 1)     {         [binarystr insertstring:((number & 1) ? @"1" : @"0") atindex:0];     }      if (bitcnt == 32)     {         binarystr=[[binarystr substringfromindex:8] mutablecopy];     }     else if(bitcnt ==16)     {         binarystr = [[@"00000000" stringbyappendingstring:binarystr] mutablecopy];     }     else if (bitcnt == 8)     {         binarystr = [[@"0000000000000000" stringbyappendingstring:binarystr] mutablecopy];     }     [arrstr addobject:[binarystr substringtoindex:8]];     [arrstr addobject:[binarystr substringwithrange:nsmakerange(8, 8)]];     [arrstr addobject:[binarystr substringfromindex:16]];      nslog(@"%@",arrstr);      return arrstr; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -