Skip to content

Commit

Permalink
added STAR printer essential milestone and its example
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleee authored and song940 committed Aug 4, 2022
1 parent 6f57a5e commit 329ca80
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/star_printer_index.js
@@ -0,0 +1,27 @@
'use strict';
const escpos = require('..');

// const device = new escpos.USB(0x0416, 0x5011);
// const device = new escpos.RawBT();
const device = new escpos.Network('STARPrinterIPAddress');
// const device = new escpos.Serial('/dev/usb/lp0');
const printer = new escpos.Printer(device);

device.open(function(err){
printer
.font('a')
.align("STAR_CA")
.style('bu')
.size(1, 1)
.emphasize()
.text('The quick brown fox jumps over the lazy dog')
.cancelEmphasize()
.align("STAR_LA")
.text('敏捷的棕色狐狸跳过懒狗')
.align("STAR_RA")
.barcode('1234567', 'EAN8')
.qrimage('https://github.com/song940/node-escpos', function(err){
this.fullCut()
this.close();
});
});
7 changes: 7 additions & 0 deletions packages/printer/src/commands.ts
Expand Up @@ -88,6 +88,7 @@ export const PAPER = {
PAPER_PART_CUT: '\x1d\x56\x01', // Partial cut paper
PAPER_CUT_A: '\x1d\x56\x41', // Partial cut paper
PAPER_CUT_B: '\x1d\x56\x42', // Partial cut paper
STAR_FULL_CUT: '\x1B\x64\x02' , // STAR printer - Full cut
};

/**
Expand All @@ -100,6 +101,8 @@ export const TEXT_FORMAT = {
TXT_2HEIGHT: '\x1b\x21\x10', // Double height text
TXT_2WIDTH: '\x1b\x21\x20', // Double width text
TXT_4SQUARE: '\x1b\x21\x30', // Double width & height text
STAR_TXT_EMPHASIZED: '\x1B\x45', // STAR printer - Select emphasized printing
STAR_CANCEL_TXT_EMPHASIZED: '\x1B\x46', // STAR printer - Cancel emphasized printing

TXT_CUSTOM_SIZE: function(width: number, height: number) { // other sizes
width = width > 8 ? 8 : width;
Expand Down Expand Up @@ -155,6 +158,10 @@ export const TEXT_FORMAT = {
TXT_ALIGN_LT: '\x1b\x61\x00', // Left justification
TXT_ALIGN_CT: '\x1b\x61\x01', // Centering
TXT_ALIGN_RT: '\x1b\x61\x02', // Right justification

STAR_TXT_ALIGN_LA: '\x1B\x1D\x61\x00', // STAR printer - Left alignment
STAR_TXT_ALIGN_CA: '\x1B\x1D\x61\x01', // STAR printer - Center alignment
STAR_TXT_ALIGN_RA: '\x1B\x1D\x61\x02', // STAR printer - Right alignment
};

/**
Expand Down
27 changes: 27 additions & 0 deletions packages/printer/src/index.ts
Expand Up @@ -901,6 +901,33 @@ export class Printer<AdapterCloseArgs extends []> extends EventEmitter {
});
});
}

/**
* STAR printer - Paper cut instruction
* @return {[Printer]} printer [the escpos printer instance]
*/
starFullCut() {
this.buffer.write(_.PAPER.STAR_FULL_CUT);
return this;
};

/**
* STAR printer - Select emphasized printing
* @return {[Printer]} printer [the escpos printer instance]
*/
emphasize() {
this.buffer.write(_.TEXT_FORMAT.STAR_TXT_EMPHASIZED);
return this;
};

/**
* STAR printer - Cancel emphasized printing
* @return {[Printer]} printer [the escpos printer instance]
*/
cancelEmphasize() {
this.buffer.write(_.TEXT_FORMAT.STAR_CANCEL_TXT_EMPHASIZED);
return this;
}
}

export default Printer;
Expand Down

0 comments on commit 329ca80

Please sign in to comment.