搜索插件、代码仓与 APP 分类

插件详情v1.0.2

usb_device

Flutter 插件,用于与 USB 设备通信(启动会话、发送数据、设置配置等)。

Web
近 30 天下载
674
喜欢数
35
Pub 分数
150

安装插件

flutter pub add usb_device

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

usb_device 包是 Flutter 插件,可在网页上实现与 USB 设备的通信。它允许用户启动会话、发送和接收数据,并通过支持 WebUSB 的网页浏览器直接配置 USB 设备。该插件专为网页应用程序中的设备交互设计,利用浏览器级别的 USB API 提供对连接外设的低级别访问。对于开发需要与传感器、控制器或自定义设备进行交互的基于网页的工具的开发者来说,该插件非常有用。它仅支持网页平台,并且需要用户授权才能访问设备。

适合场景

  • 通过 USB 在网页应用中连接硬件
  • 向USB连接的设备发送命令
  • 从外部USB外设读取数据
  • 开发基于网络的设备控制界面
  • 启用与嵌入式设备的实时通信

主要特点

  • 仅限网页的 USB 通信
  • 支持会话管理
  • 数据传输和接收
  • 设备配置选项
  • 基于浏览器的 WebUSB 集成

适合对象

  • 使用硬件的Web开发人员
  • 物联网网络应用
  • 自定义设备控制仪表板
  • 原型设计USB功能的网络工具
  • 涉及USB设备的教育项目

使用建议

  • 仅限网页平台
  • 需要浏览器支持 WebUSB
  • 访问设备需要用户权限
  • 不支持移动或桌面原生应用
  • 依赖设备对 WebUSB 的兼容性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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 🎉.

所属分类

依赖

依赖清单 2 项

  • usb_device_platform_interface^1.0.0
  • usb_device_web^1.0.0

源码仓库

使用此插件的项目

暂无相关数据。