Dart wrapper via dart:js
for https://wicg.github.io/webusb/
Features
- canUseUsb
- getDevices/requestDevice
- open/close
- reset
- selectConfiguration
- claimInterface/releaseInterface
- transferIn/transferOut
Usage
canUseUsb
bool canUse = canUseUsb();
print('canUse $canUse');
getDevices/requestDevice
List<UsbDevice> getDevices = await usb.getDevices();
_device = getDevices[0];
UsbDevice requestDevice = await usb.requestDevice(RequestOptions(
filters: [ledgerDeviceIds],
));
_device = requestDevice;
open/close
_device?.open().then((value) {
print('device.open success');
}).catchError((error) {
print('device.open $error');
});
_device?.close().then((value) {
print('device.close success');
}).catchError((error) {
print('device.close $error');
});
reset
https://developer.mozilla.org/en-US/docs/Web/API/USBDevice/reset
_device?.reset().then((value) {
print('device.reset success');
}).catchError((error) {
print('device.reset $error');
});
selectConfiguration
https://developer.mozilla.org/en-US/docs/Web/API/USBDevice/selectConfiguration
claimInterface/releaseInterface
_device?.claimInterface(_interface!.interfaceNumber).then((value) {
print('device.claimInterface success');
}).catchError((error) {
print('device.claimInterface $error');
});
_device?.releaseInterface(_interface!.interfaceNumber).then((value) {
print('device.releaseInterface success');
}).catchError((error) {
print('device.releaseInterface $error');
});
transferIn/transferOut
var usbInTransferResult = await _device!.transferIn(endpointNumber, packetSize);
print('usbInTransferResult ${usbInTransferResult.data.lengthInBytes}');
var usbOutTransferResult = await _device?.transferOut(endpointNumber, makeBlock(getAppAndVersion));
print('usbOutTransferResult ${usbOutTransferResult?.bytesWritten}');
Additional information
Status in Chromium: https://chromestatus.com/feature/5651917954875392