Skip to content

Instantly share code, notes, and snippets.

@wppurking
Created March 20, 2019 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wppurking/c28846401aeddfb8795e914e3aa89bf4 to your computer and use it in GitHub Desktop.
Save wppurking/c28846401aeddfb8795e914e3aa89bf4 to your computer and use it in GitHub Desktop.
require 'libusb'
# 初始化 Libusb context
usb = LIBUSB::Context.new
# 通过固定的 idVendor 获取 zebra 的第一个 usb 设备.
# https://usb-ids.gowdy.us/read/UD/
d = usb.devices(idVendor: 0x0a5f).first
# 通过 device 获取用于操作 io 的 DevHandler
h = d.open
# 获取需要操作的的第一个 usb interface 的句柄
h.claim_interface(d.interfaces.first)
# zpl 语言的打印
zpl = %(^XA
^JMA^LL228^PW308^MD10^RP2^PON^LRN^LH10,0
^FO0,32^BY2^BCN,80,Y,N,N,A^FDXB001KAN4^FS
^PQ1
^XZ
)
# 传输 zpl 给 zebra 打印机进行打印
h.bulk_transfer(endpoint: d.endpoints.find {|e| e.direction == :out }, dataOut: zpl, timeout: 3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment