搜尋套件、儲存庫與 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

原始碼儲存庫

使用此套件的專案

暫無相關資料。