我已经为此苦苦挣扎了一段时间。
我正在尝试使用ESC / POS命令直接打印到热敏打印机。
我正在使用node-printer模块从node发送数据:
https://www.npmjs.com/package/printer
或ipp模块
https://www.npmjs.com/package/ipp
两者都给我完全相同的行为,这就是我发送的前几个命令似乎被完全忽略了。
为了进行测试,我使用了本教程中的命令:
https://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-commands-from-Javascript/
例如,在我的节点程序中,我可以拥有:
stop_words = ["and","lang","naman","the","sa","ko","na",
"yan","n","yang","mo","ung","ang","ako","ng",
"ndi","pag","ba","on","un","Me","at","to",
"is","sia","kaya","I","s","sla","dun","po","b","pro"
]
newdata = pd.DataFrame({'Verbatim':['I love my lang','the boss come to me']})
pat = '|'.join(r"\b{}\b".format(x) for x in stop_words)
newdata['Verbatim1'] = newdata['Verbatim'].str.replace(pat, '')
top_words = set(stop_words)
f = lambda x: ' '.join(w for w in x.split() if not w in stop_words)
newdata['Verbatim2'] = newdata['Verbatim'].apply(f)
print (newdata)
Verbatim Verbatim1 Verbatim2
0 I love my lang love my love my
1 the boss come to me boss come me boss come me
然后将这些命令直接发送到打印机。使用node-printer(直接取自他们的print_raw示例):
let esc = '\x1B'; //ESC byte in hex notation
let newLine = '\x0A'; //LF byte in hex notation
let cmds = esc + "@"; //Initializes the printer (ESC @)
cmds += esc + '!' + '\x38'; //Emphasized + Double-height + Double-width mode selected (ESC ! (8 + 16 + 32)) 56 dec => 38 hex
cmds += 'BEST DEAL STORES'; //text to print
cmds += newLine + newLine;
cmds += esc + '!' + '\x00'; //Character font A selected (ESC ! 0)
cmds += 'COOKIES 5.00';
cmds += newLine;
cmds += 'MILK 65 Fl oz 3.78';
cmds += newLine + newLine;
cmds += 'SUBTOTAL 8.78';
cmds += newLine;
cmds += 'TAX 5% 0.44';
cmds += newLine;
cmds += 'TOTAL 9.22';
cmds += newLine;
cmds += 'CASH TEND 10.00';
cmds += newLine;
cmds += 'CASH DUE 0.78';
cmds += newLine + newLine;
cmds += esc + '!' + '\x18'; //Emphasized + Double-height mode selected (ESC ! (16 + 8)) 24 dec => 18 hex
cmds += '# ITEMS SOLD 2';
cmds += esc + '!' + '\x00'; //Character font A selected (ESC ! 0)
cmds += newLine + newLine;
cmds += '11/03/13 19:53:17';
或使用ipp:
let printer = require("printer");
this.printer.printDirect({data: cmds
, type: 'RAW' // type: RAW, TEXT, PDF, JPEG, .. depends on platform
, success:function(jobID: any){
console.log("sent to printer with ID: "+jobID);
}
, error:function(err: any){console.log(err);}
});
由于这两种技术,出于某种原因,打印仅从“ FL oz”(假收据上的牛奶项目)开始。之前的所有命令(包括对齐或字体选择)都将被完全忽略。
现在,如果我在此之前添加一堆命令,则使用类似的
const ipp = require('ipp');
const uri = "ipp://localhost/printers/myPrinter";
let msg = {
"operation-attributes-tag": {
"requesting-user-name": "William",
"job-name": "My Test Job",
"document-format": "text/plain"
},
data: new Buffer(cmds)
};
const rawPrinter = ipp.Printer(uri);
rawPrinter.execute("Print-Job", msg, function(err: any, res: any){
console.log(res);
});
然后我将整个收据打印出来。但是,这感觉让人感到恐惧,几乎肯定会再次困扰我。我还需要发送其他信息给打印机以使其从头开始读取命令吗?也许我需要以更好的方式格式化命令?
我正在Ubuntu上运行此打印机,并且该打印机是Bixolon热敏打印机350III,其命令可以在此处找到:
http://www.bixolon.com/upload/download/unified%20command%20manual_rev_1_01.pdf
很显然,我对此很陌生,我非常希望我缺少明显的东西。