Apparence-io / webUSB_plugin

A flutter webusb plugin

Home Page:https://pub.dev/packages/usb_device

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

web usb logo



License: MIT pub dev usb_device




πŸš€  Overview

WebUSB plugin provide access to USB devices from Flutter Web πŸ’™ by using web usb official API.

  • πŸ“± Get device info with configuration.
  • πŸ”Œ Pair a device with filter.
  • πŸ“€ Send data to USB device.
  • πŸ“₯ Receive data from USB device.
  • πŸŽ›οΈ Change USB device configuration.

πŸ’»  Platform Support

Android iOS MacOS Web Linux Windows
βž– βž– βž– βœ”οΈ βž– βž–

πŸ“–  Installation

Install the package

flutter pub add usb_device

Import the package

import 'package:usb_device/usb_device.dart';

πŸš€  Get started

  • Import & instanciate the plugin.
import 'package:usb_device/usb_device.dart';

final UsbDevice usbDevice = UsbDevice();
  • Common used methods.
// get paired devices
final pairedDevices = await usbDevice.pairedDevices;

// pair a device 
final pairedDevice = await usbDevice.requestDevices([DeviceFilter(vendorId : 0x00, productId: 0x00)]);

// get device's configurations 
List<USBConfiguration> availableConfigurations = await usbDevice.getAvailableConfigurations(pairedDevice);

// get device's info
USBDeviceInfo deviceInfo = await usbDevice.getPairedDeviceInfo(pairedDevice);

// start session
await usbDevice.open(pairedDevice);

// close session
await usbDevice.close(pairedDevice);

πŸ“š  Methods

USB

Name Description Returned value
pairedDevices Get paired attached devices Future<List<dynamic>>
requestDevice(List<DeviceFilter> filters) Pair a device with filter or not Future<dynamic>
isSupported() Pair a device with filter or not Future<bool>
open() Start a session Future
close() Close a session Future
claimInterface(dynamic device, int interfaceNumber) Claim an interface for exclusive access Future
releaseInterface(dynamic device, int interfaceNumber) Release a claimed interface Future
reset(dynamic device) Reset device Future
selectConfiguration(dynamic device, int configurationValue) Select a specified configuration Future
clearHalt(dynamic device, String direction, int endpointNumber) Returns a promise that resolves when a halt condition is cleared Future
controlTransferIn(dynamic device, SetupParam setup, {int? length}) Return result of a command Future<USBInTransferResult>
controlTransferOut(dynamic device, SetupParam setup, {dynamic data}) Send a command to device Future<USBOutTransferResult>
transferIn(dynamic device, int endpointNumber, int length) Return data from device Future<USBInTransferResult>
transferOut(dynamic device, int endpointNumber, dynamic data) Send data to device Future<USBOutTransferResult>
isochronousTransferIn(dynamic device, int endpointNumber, List<int> packetLengths) Resolves with a USBIsochronousInTransferResult when time sensitive information has been transmitted to (received by) the USB device Future<USBIsochronousInTransferResult>
isochronousTransferOut(dynamic device, int endpointNumber, List<int> packetLengths) Resolves with a USBIsochronousOutTransferResult when time sensitive information has been transmitted from the USB device Future<USBIsochronousOutTransferResult>
setOnConnectCallback(Function(dynamic) onConnect) Connect callback Future
setOnDisconnectCallback(Function(dynamic) onDisconnect) Disconnect callback Future
getSelectedConfiguration(dynamic pairedDevice) Get the selected configuration Future<USBConfiguration?>
getAvailableConfigurations(dynamic pairedDevice) Get available device's configurations Future<List<USBConfiguration>>
getPairedDeviceInfo(dynamic pairedDevice) Get info of paired device Future<USBDeviceInfo>

πŸ“£  Sponsor

logo apparence io



Initiated and sponsored by Apparence.io.

πŸ‘₯  Contribution

Contributions are welcome. Contribute by creating a PR or create an issue πŸŽ‰.

About

A flutter webusb plugin

https://pub.dev/packages/usb_device


Languages

Language:Dart 47.8%Language:C++ 24.9%Language:CMake 16.1%Language:HTML 3.8%Language:Ruby 2.7%Language:JavaScript 1.9%Language:C 1.5%Language:Swift 1.2%Language:Kotlin 0.1%Language:Objective-C 0.0%