Skip to content

Commit 329ca80

Browse files
daveleeelsongdev
authored andcommitted
added STAR printer essential milestone and its example
1 parent 6f57a5e commit 329ca80

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

examples/star_printer_index.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const escpos = require('..');
3+
4+
// const device = new escpos.USB(0x0416, 0x5011);
5+
// const device = new escpos.RawBT();
6+
const device = new escpos.Network('STARPrinterIPAddress');
7+
// const device = new escpos.Serial('/dev/usb/lp0');
8+
const printer = new escpos.Printer(device);
9+
10+
device.open(function(err){
11+
printer
12+
.font('a')
13+
.align("STAR_CA")
14+
.style('bu')
15+
.size(1, 1)
16+
.emphasize()
17+
.text('The quick brown fox jumps over the lazy dog')
18+
.cancelEmphasize()
19+
.align("STAR_LA")
20+
.text('敏捷的棕色狐狸跳过懒狗')
21+
.align("STAR_RA")
22+
.barcode('1234567', 'EAN8')
23+
.qrimage('https://github.com/song940/node-escpos', function(err){
24+
this.fullCut()
25+
this.close();
26+
});
27+
});

packages/printer/src/commands.ts

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const PAPER = {
8888
PAPER_PART_CUT: '\x1d\x56\x01', // Partial cut paper
8989
PAPER_CUT_A: '\x1d\x56\x41', // Partial cut paper
9090
PAPER_CUT_B: '\x1d\x56\x42', // Partial cut paper
91+
STAR_FULL_CUT: '\x1B\x64\x02' , // STAR printer - Full cut
9192
};
9293

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

104107
TXT_CUSTOM_SIZE: function(width: number, height: number) { // other sizes
105108
width = width > 8 ? 8 : width;
@@ -155,6 +158,10 @@ export const TEXT_FORMAT = {
155158
TXT_ALIGN_LT: '\x1b\x61\x00', // Left justification
156159
TXT_ALIGN_CT: '\x1b\x61\x01', // Centering
157160
TXT_ALIGN_RT: '\x1b\x61\x02', // Right justification
161+
162+
STAR_TXT_ALIGN_LA: '\x1B\x1D\x61\x00', // STAR printer - Left alignment
163+
STAR_TXT_ALIGN_CA: '\x1B\x1D\x61\x01', // STAR printer - Center alignment
164+
STAR_TXT_ALIGN_RA: '\x1B\x1D\x61\x02', // STAR printer - Right alignment
158165
};
159166

160167
/**

packages/printer/src/index.ts

+27
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,33 @@ export class Printer<AdapterCloseArgs extends []> extends EventEmitter {
901901
});
902902
});
903903
}
904+
905+
/**
906+
* STAR printer - Paper cut instruction
907+
* @return {[Printer]} printer [the escpos printer instance]
908+
*/
909+
starFullCut() {
910+
this.buffer.write(_.PAPER.STAR_FULL_CUT);
911+
return this;
912+
};
913+
914+
/**
915+
* STAR printer - Select emphasized printing
916+
* @return {[Printer]} printer [the escpos printer instance]
917+
*/
918+
emphasize() {
919+
this.buffer.write(_.TEXT_FORMAT.STAR_TXT_EMPHASIZED);
920+
return this;
921+
};
922+
923+
/**
924+
* STAR printer - Cancel emphasized printing
925+
* @return {[Printer]} printer [the escpos printer instance]
926+
*/
927+
cancelEmphasize() {
928+
this.buffer.write(_.TEXT_FORMAT.STAR_CANCEL_TXT_EMPHASIZED);
929+
return this;
930+
}
904931
}
905932

906933
export default Printer;

0 commit comments

Comments
 (0)