add iconv module and change print method
This commit is contained in:
parent
748c021ff2
commit
2462c92c9b
@ -2,7 +2,7 @@ const EventEmitter = require('events')
|
|||||||
const escpos = require('escpos')
|
const escpos = require('escpos')
|
||||||
const config = require('./config.json')
|
const config = require('./config.json')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const iconv = require('iconv-lite')
|
||||||
// const device = new escpos.Serial(config.printer.serial)
|
// const device = new escpos.Serial(config.printer.serial)
|
||||||
|
|
||||||
// const printer = new escpos.Printer(device)
|
// const printer = new escpos.Printer(device)
|
||||||
@ -16,6 +16,11 @@ class PrinterDevice {
|
|||||||
this._type = null // type = serial or console
|
this._type = null // type = serial or console
|
||||||
}
|
}
|
||||||
|
|
||||||
|
encodeStr(str){
|
||||||
|
if(!str || typeof str != 'string') return false
|
||||||
|
return iconv.encode(str, 'big5')
|
||||||
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
let chkSerial = await new Promise((resolve, reject) => {
|
let chkSerial = await new Promise((resolve, reject) => {
|
||||||
fs.access(config.printer.serial, err => {
|
fs.access(config.printer.serial, err => {
|
||||||
@ -66,11 +71,13 @@ class PrinterDevice {
|
|||||||
let size = tmp.substring(2)
|
let size = tmp.substring(2)
|
||||||
let sarr = size.trim().split(',')
|
let sarr = size.trim().split(',')
|
||||||
if (sarr != 2) break
|
if (sarr != 2) break
|
||||||
|
if(!isFinite(sarr[0]) || !isFinite(sarr[1])) break
|
||||||
|
sarr = sarr.map(t => Math.floor(t))
|
||||||
this._printer.size(sarr[0], sarr[1])
|
this._printer.size(sarr[0], sarr[1])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this._printer.text(tmp, 'big5')
|
this._printer.print(this.encodeStr(tmp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bleno": "^0.4.2",
|
"bleno": "^0.4.2",
|
||||||
"escpos": "^2.4.3",
|
"escpos": "^2.4.3",
|
||||||
|
"iconv-lite": "^0.4.18",
|
||||||
"uuid": "^3.1.0"
|
"uuid": "^3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user