Revert Datamax to kernel usblp driver -- direct libusb bulk transfer times out on this Pi 3B's USB controller
deploy / deploy (push) Successful in 9s
deploy / deploy (push) Successful in 9s
This commit is contained in:
1 parent
3833452fa9
commit
858fc3a20d
2 files changed
+5
-24
No files matched your search
@@ -6,6 +6,5 @@ gem 'puma'
|
|||||||
gem 'rqrcode'
|
gem 'rqrcode'
|
||||||
gem 'logger'
|
gem 'logger'
|
||||||
gem 'ostruct'
|
gem 'ostruct'
|
||||||
gem 'libusb'
|
|
||||||
|
|
||||||
gem 'rackup', "~> 2.1"
|
gem 'rackup', "~> 2.1"
|
||||||
@@ -3,7 +3,6 @@ require 'sinatra'
|
|||||||
require "sinatra/reloader"
|
require "sinatra/reloader"
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'libusb'
|
|
||||||
|
|
||||||
set :protection, :except => :frame_options
|
set :protection, :except => :frame_options
|
||||||
set :environment, :production
|
set :environment, :production
|
||||||
@@ -14,14 +13,10 @@ if !File.exist?('config.json') || !File.readable?('config.json')
|
|||||||
raise RuntimeException, 'Could not read config.json'
|
raise RuntimeException, 'Could not read config.json'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Addressed the same way as the Brother QL printers (usb://VID:PID/Serial via
|
# Direct libusb bulk transfer (bypassing the kernel usblp driver, matching how
|
||||||
# brother_ql_web) instead of a udev symlink -- self-contained, no reliance on
|
# brother_ql_web addresses its printers) times out on this Pi 3B's USB
|
||||||
# OS device naming/ordering.
|
# controller -- back to the kernel driver via a stable udev symlink instead.
|
||||||
DATAMAX_VENDOR_ID = 0x0b0b
|
PRINTER_DEVICE = '/dev/usb/lp_datamax' # see /etc/udev/rules.d/99-datamax.rules
|
||||||
DATAMAX_PRODUCT_ID = 0x106e
|
|
||||||
DATAMAX_SERIAL = '24624'
|
|
||||||
DATAMAX_ENDPOINT = 0x02 # bulk OUT, interface 0
|
|
||||||
|
|
||||||
PRINTER_DPI = 203 # DatamaxONeil E4204B Mark III native head resolution
|
PRINTER_DPI = 203 # DatamaxONeil E4204B Mark III native head resolution
|
||||||
PRINTER_DARKNESS = 8 # lower than factory default to stop thermal dot-gain from fusing barcode bars
|
PRINTER_DARKNESS = 8 # lower than factory default to stop thermal dot-gain from fusing barcode bars
|
||||||
TEST_LABEL_PDF = File.join(File.dirname(__FILE__), 'test-label.pdf')
|
TEST_LABEL_PDF = File.join(File.dirname(__FILE__), 'test-label.pdf')
|
||||||
@@ -90,20 +85,7 @@ helpers do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print_to_datamax(data)
|
def print_to_datamax(data)
|
||||||
usb = LIBUSB::Context.new
|
File.open(PRINTER_DEVICE, 'wb') { |f| f.write(data) }
|
||||||
device = usb.devices(idVendor: DATAMAX_VENDOR_ID, idProduct: DATAMAX_PRODUCT_ID)
|
|
||||||
.find { |d| d.serial_number == DATAMAX_SERIAL }
|
|
||||||
unless device
|
|
||||||
raise format('Datamax printer not found (USB %04x:%04x/%s)',
|
|
||||||
DATAMAX_VENDOR_ID, DATAMAX_PRODUCT_ID, DATAMAX_SERIAL)
|
|
||||||
end
|
|
||||||
|
|
||||||
device.open do |handle|
|
|
||||||
handle.auto_detach_kernel_driver = true # usblp kernel driver otherwise holds the interface
|
|
||||||
handle.claim_interface(0) do
|
|
||||||
handle.bulk_transfer(endpoint: DATAMAX_ENDPOINT, dataOut: data, timeout: 30_000) # USB 1.1, large ZPL payloads need more than the 1s default
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transparently reverse-proxies the current request to one of the
|
# Transparently reverse-proxies the current request to one of the
|
||||||
|
|||||||
Reference in new issue
Block a user