javascript - 使用 JavaScript 将十六进制命令发送到打印机

标签 javascript printing hex

我正在尝试将 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/

相关文章:

javascript - Next Js 结合外部 REST API 身份验证和授权

printing - 使用 Ghostscript 将 PCL 转换为 PostScript

javascript - 使用 JQuery 打开弹出窗口并打印

python - 为什么Python print 会打印一些表情符号而不打印其他表情符号?

swift - 如何在 Swift 中将十六进制转换为有符号 float ?对于正数工作正常,但对于负数不起作用

c++ - 在 C++ 中确定数字大小

javascript - Firefox 37 上 console.log() 的奇怪行为

JavaScript 术语表 : Value vs Expression?

c - 如何检查十六进制数是否等于特定的二进制数?

javascript - 为 JavaScript 提供按钮的 id