web_usb 0.1.0 copy "web_usb: ^0.1.0" to clipboard
web_usb: ^0.1.0 copied to clipboard

Platformweb
outdated

A starting point for Dart libraries or applications.

Dart wrapper via dart:js for https://wicg.github.io/webhid/

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

2
likes
120
pub points
59%
popularity

Publisher

verified publisherwoodemi.com

A starting point for Dart libraries or applications.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

js

More

Packages that depend on web_usb