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

UsbDevice manufacturer, product & serial number description #30

Merged
merged 5 commits into from Aug 20, 2021

Conversation

shaxxx
Copy link
Contributor

@shaxxx shaxxx commented Aug 17, 2021

Currently there is no way to present human friendly list of devices for user to select (IE. select pos printer).
I added 2 new functions to get human friendly info about UsbDevice.

getDeviceDescription returns new object of UsbDeviceDescription type with manufacturer, product & serial number info.
getDevicesWithDescription returns list of UsbDeviceDescription type with manufacturer, product & serial number info.

All devices/handles are opened/closed automatically.
Default device handle is neither populated or used since this opens and closes multiple devices.
Existing object model and api is left as is.

See #21

@Sunbreak
Copy link
Collaborator

Any common USB device to test the usecase?

@shaxxx
Copy link
Contributor Author

shaxxx commented Aug 18, 2021

Not quite sure what you mean.
This is applicable to all USB devices in a scenario where vendor/product id is not known to developer.

In my case I need to allow user to select POS printer attached to the host.
I surely can't know all the possible vendor/product ids that end user can buy and use.
If there is multiple USB devices (on desktop there always is) and I offer list of vendorId/productId to the end user there is no way for him to know what vendorId/productId belongs to printer.

With this PR I can offer human friendly devices list and instead of vendorId/productId display something like "Logitech Mouse", "Logitech USB receiver", "POS PRINTER". User selects the item and I can save vendorId/productId to be used in a future.
I've tested it on Android, Linux and MacOs and I get something like this for my POS printer

{device: {identifier: 17, vendorId: 1317, productId: 42752, configurationCount: 1}, manufacturer: Sewoo, product: POS PRINTER, serialNumber: null}

Notice how it literally says: POS PRINTER
But again, this is applicable to all USB devices (iot devices, usb disk, serial devices) when there's a need for end user to select device.

@shaxxx
Copy link
Contributor Author

shaxxx commented Aug 18, 2021

Keep in mind on Linux user needs write permission for device to get the description.
This can be done over udev rules, ie, create file /etc/udev/rules.d/mydevice.rules with something like this for device with vendorId 0x0525

SUBSYSTEM=="usb", ATTRS{idVendor}=="0525", MODE="0666"
SUBSYSTEM=="usb_device", ATTRS{idVendor}=="0525", MODE="0666"

save it and reload udev rules with

sudo udevadm control --reload-rules

and make sure to re-attach device.

If you want to enable it for all devices just ommit ATTRS{idVendor}=="0525", something like this

SUBSYSTEM=="usb", MODE="0666"
SUBSYSTEM=="usb_device", MODE="0666"

Or if this is too much you can always run the app as root (not recommended).

lib/src/quick_usb_desktop.dart Outdated Show resolved Hide resolved
lib/src/quick_usb_desktop.dart Outdated Show resolved Hide resolved
lib/src/quick_usb_desktop.dart Outdated Show resolved Hide resolved
lib/src/quick_usb_desktop.dart Outdated Show resolved Hide resolved
@Sunbreak
Copy link
Collaborator

I've tested it on Android, Linux and MacOs and I get something like this for my POS printer

I re-test it on Android/Windows/macOS/Linux and it works with my Logitech mouse

Thanks for your contribution :)

@shaxxx
Copy link
Contributor Author

shaxxx commented Aug 20, 2021

There was permission bug when permission was asked, user would allow it and getDescription would still return null values.
Subsequent requests would work since permission was granted.

@Sunbreak Sunbreak merged commit 935d2fe into woodemi:master Aug 20, 2021
@shaxxx shaxxx mentioned this pull request Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants