问题描述
我正在编写一些与ESC / POS设备交谈的代码。为此,我需要向打印机发送一些十六进制命令。 我找到了这个库:https://github.com/song940/node-escpos,我正在将其转换为浏览器版本。
现在,我已经接触到使用Buffer()
的部分,该部分不能直接在浏览器中工作。
我在这里发现了一些问题,例如Browser buffer to string conversion is not same in browser and nodejs和Convert nodejs' Buffer to browsers' javascript,但是对于我来说如何实现这些解决方案还不是很清楚。如果可能的话,我不想实现browserfy lib,因为这是1函数的大量代码。 https://github.com/chrisdickinson/bops代码似乎不适用于新版本的浏览器。
barcodeHeight(height) {
return Buffer.from('1d68' + this.numToHexString(height),'hex')
}
codeLength (str) {
var buff = Buffer.from((str.length).toString(16),'hex')
return buff.toString()
}
numToHexString(value) {
value = +value
if (!isNaN(value)) {
value = (value).toString(16)
while(value.length % 2 !== 0) {
value = '0' + value
}
}
return value
}
我该如何重写这些功能以使其在浏览器中工作?例如使用TextEncoder()
吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)