nodejs 打印标签
背景
公司有需求, 打印一些小票
- 直接搜索 node-printer 或者 node-thermal-printer 都太古老了。
- windows 自带的打印命令 不好调试
- 这里分享下使用 TSPL指令 在 条码打印机 的一些解决方案
TSPL
示例
1 | SIZE 60 mm,40 mm\r\n |
文档
https://open.jolimark.com/files/tspl.pdf
步骤
- 找到设备端口
1 | const usb = require('usb'); |
- 连接设备
1 | let device = usb.findByIds(1137, 85) |
- [选填] windows 需要刷新设备的驱动,可以参考 usb 的文档
On Windows, if you get LIBUSB_ERROR_NOT_SUPPORTED when attempting to open your device, it’s possible your device doesn’t have a WinUSB driver for libusb to use.
You can install one using Zadig or another approach is to use the UsbDK Backend of libusb by immediately calling usb.useUsbDkBackend().
Note that you cannot use multiple drivers on Windows as they get exclusive access to the device. So if you want to switch between drivers (e.g. using a printer with this software or the system), you will need to uninstall/install drivers as required.
For further info, check How to use libusb on Windows in the libusb’s wiki.
刷后的效果
完整代码
1 | const usb = require('usb'); |