我正在尝试将 ESC 序列发送到收据打印机以触发钱箱打开。我是 Javascript 新手,所以我只是想检查一下我做得是否正确。尽管我可能发送了错误的代码序列,但打印机/钱箱没有任何反应。 我知道抽屉确实打开了,因为我可以使用打印机测试软件触发它打开。
这是 JavaScript。
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'CloseTillPrint' + uniqueName.getTime();
var PrintWindow = window.open(windowUrl, windowName, 'left=300,top=100,width=200,height=900');
PrintWindow.document.open('text/plain')
PrintWindow.document.write(0x1B);
PrintWindow.document.write(0x70);
PrintWindow.document.write(0x30);
PrintWindow.document.write(0x37);
PrintWindow.document.write(0x79);
PrintWindow.document.close();
PrintWindow.focus();
PrintWindow.print();
PrintWindow.close();
如果您可以确认我上面的代码没有犯任何错误,我将假设我发送了错误的十六进制序列。 谢谢
最佳答案
您正在打印数字,而不是字符。使用它代替您的 write()
命令:
PrintWindow.document.write(String.fromCharCode(0x1B, 0x70, 0x30, 0x37, 0x79));
关于javascript - 使用 JavaScript 将十六进制命令发送到打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41892675/