pombreda / python-escpos

Automatically exported from code.google.com/p/python-escpos
GNU General Public License v3.0
0 stars 0 forks source link

Barcode would not print reliably on TM81 #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Just couldn't get barcodes to print reliably or completely on the TM81.  
Looking at the docs 
http://nicholas.piasecki.name/blog/wp-content/uploads/2009/12/ESC-POS-Command-Gu
ide.pdf  printing a barcode 
to print 

1. ASCII GS k md1...dk NUL 
 Hex. 1D 6B md1...dk NUL 
 Decimal 29 107 md1...dk NUL 
2. ASCII GS k m nd1...dk 
 Hex. 1D 6B m nd1...dk 
 Decimal 29 107 m nd1...dk

1. 0 ≤ m ≤ 6 The definition region of k and d differ according to the bar 
code type. 
 2. 65 ≤ m ≤ 73 The definition region of n and d differ according to the bar code type.

Which boils down to the character string being printed if you use option 1, 
needs a NULL terminator.  Option 2 the leading byte says how long the string 
will be.

I opted for option 1, and include NUL  '\x00' at the end of the string.

Original issue reported on code.google.com by zutes...@gmail.com on 31 May 2013 at 4:13

GoogleCodeExporter commented 9 years ago
We encountered the same problem... Adding '\x00' to the end of string does 
print the barcode - however, it also adds another '0' to the end of the 
bar-code itself and to the barcode number itself altering it slightly ( for 
example, a barcode of 123456 would become 1234560 )

Original comment by kremb...@gmail.com on 24 Dec 2014 at 11:29

GoogleCodeExporter commented 9 years ago
Hmm I didn't get that outcome.  Bar codes print fine for me.

I comepletely replaced the code for the limited barcodes I needed.

I ended up with 

  def  barcode(self,code,bc=constants.BARCODE_CODE39,w=1,h=72,pos=constants.BARCODE_TXT_BLW,font=None,align=constants.TXT_ALIGN_CT):
        self._raw(align)
        self._raw(''.join((constants.BARCODE_WIDTH,chr(w))))
        self._raw(''.join((constants.BARCODE_HEIGHT,chr(h))))
        self._raw(''.join((bc,code,'\x00')))

Original comment by zutes...@gmail.com on 24 Dec 2014 at 1:52