Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume USB device is configured when looking for endpoints #47

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Printers/Communication/UsbPrinterDeviceChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,21 @@ export class UsbPrinterDeviceChannel extends EventTarget implements IPrinterDevi
private async connect() {
const d = this.device;

// Any sane USB device should expose at least one configuration with one
// interface.
if (
d.configurations.length === 0 ||
d.configurations[0].interfaces.length === 0 ||
d.configurations[0].interfaces[0].alternates.length === 0
) {
throw new WebZlpError('USB printer did not expose any interfaces.');
Cellivar marked this conversation as resolved.
Show resolved Hide resolved
}

// A standard Zebra printer will have two endpoints on one interface.
// One of them will be output, one of them will be input. They can be
// in a random order (or missing!) so we must enumerate them to find them.
let o: USBEndpoint, i: USBEndpoint;
for (const endpoint of d.configuration.interfaces[0].alternates[0].endpoints) {
for (const endpoint of d.configurations[0].interfaces[0].alternates[0].endpoints) {
if (endpoint.direction == 'out') {
o = endpoint;
} else if (endpoint.direction == 'in') {
Expand Down
Loading