パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.1.1

win_ble

WinBle プラグインを使用して、Flutter Windows および純粋な Dart プロジェクトで Bluetooth Low Energy を有効にする(Windows専用)

Windows
30日間ダウンロード
13.7万
いいね数
39
Pub ポイント
150

パッケージをインストール

flutter pub add win_ble

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

win_ble パッケージは、Windows および純粋な Dart プロジェクトを対象とした Flutter アプリケーションで Bluetooth Low Energy (BLE) 機能を有効にします。Windows 専用に設計されており、ネイティブ BLE 機能へのブリッジを提供し、開発者がデバイスを検出したり、ペリフェラルに接続したり、特性の読み書きや BLE 操作の管理が可能になります。このプラグインは、Windows プラットフォーム上で BLE デバイスとの低消費電力無線通信が必要なアプリケーションに最適です。プラットフォームチャネルを通じて Windows Bluetooth API を活用しており、Flutter エコシステム内での信頼性の高いパフォーマンスを実現しています。

用途

  • BLEセンサーへの接続
  • BLEビーコンからデータを読み取る
  • BLE対応のIoTデバイスの制御
  • Windows専用のヘルスモニタリングアプリの開発
  • 近接に基づく機能の実装

主な機能

  • Windows専用のBLEサポート
  • ネイティブな Windows Bluetooth API 統合
  • デバイスの検出と接続管理
  • 特徴の読み取り/書き込み操作
  • 純粋な Dart の互換性

適している対象

  • Windows デスクトップアプリ開発者
  • IoTデバイス統合業者
  • ヘルスとフィットネスアプリの作成者
  • Bluetooth中心のユーティリティツール
  • Windows固有のBLE要件を備えたクロスプラットフォームアプリ

注意事項

  • Windows プラットフォームに限定
  • Windows 10 以降が必要です
  • Android/iOS 対応なし
  • システムレベルのBluetooth権限に依存します
  • 特定のハードウェアでは、追加の構成が必要になる場合があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

WinBle

win_ble version

Use the WinBle plugin to enable Bluetooth Low Energy in Flutter Windows and pure Dart projects (Windows only)

Usage

First initialize WinBle, to initialize on Flutter Windows, get server path using await WinServer.path, and for pure dart projects ( Windows only ) Download BleServer.exe file and place in the same folder, checkout example_dart for more details

  // To initialize on Flutter Windows
  await WinBle.initialize(serverPath: await WinServer.path());

  // For pure dart projects
  await WinBle.initialize(serverPath: "Path of BLEServer.exe file");

Dispose WinBle after using

 WinBle.dispose();

To Start Scan

 WinBle.startScanning();

 StreamSubscription? scanStream = WinBle.scanStream.listen((event) {
  // Get Devices Here
 });

To Stop Scan

  WinBle.stopScanning();

  scanStream?.cancel();

To Connect

 // To Connect
 await WinBle.connect(address);

 // Get Connection Updates Here
 StreamSubscription  _connectionStream =
    WinBle.connectionStreamOf(device.address).listen((event) {
    // event will be a boolean , in which
    // true => Connected
    // false => Disconnected
 });

To Disconnect

  await WinBle.disconnect(address);

To get MaxMtuSize

  await WinBle.getMaxMtuSize(address);

Handle Bluetooth radio

  // To get rdaio status
  WinBle.getBluetoothState();

  // To get updates of radio state
  WinBle.bleState.listen((BleState state) {
    // Get BleState (On, Off, Unknown, Disabled, Unsupported)
  });

  // To turn on radio
  WinBle.updateBluetoothState(true);

  // To turn off radio
  WinBle.updateBluetoothState(false);

Pairing Options

  // To Pair
  await WinBle.pair(address);

  // To UnPair
  await WinBle.unPair(address);

  // To Check if Device can be Paired
  bool canPair = await WinBle.canPair(address);

  // To Check if Device is Already Paired
  bool isPaired = await WinBle.isPaired(address);

Rest All Methods are

  // To Get Services
  var services = await WinBle.discoverServices(address);

  // To Get Characteristic
  List<BleCharacteristic> bleCharacteristics = await WinBle.discoverCharacteristics(address: address, serviceId: serviceID);

  // To Read Characteristic
  List<int> data = await WinBle.read(address: address, serviceId: serviceID, characteristicId: charID);

  // To Write Characteristic
  await WinBle.write( address: address, service: serviceID,  characteristic: charID,  data: data, writeWithResponse: writeWithResponse);

  // To Start Subscription
  await WinBle.subscribeToCharacteristic(address: address, serviceId: serviceID, characteristicId: charID);

  // To Stop Subscription
  await WinBle.unSubscribeFromCharacteristic(address: address, serviceId: serviceID, characteristicId: charID);

  // Get Characteristic Value Updates Here
   StreamSubscription _characteristicValueStream = WinBle.characteristicValueStream.listen((event) {
     // Here We will Receive All Characteristic Events
   });

Note

Requires Windows version >= 10.0.15014

If windows release build opens cmd while running app, try this

Edit your /windows/runner/main.cpp file, this is a known flutter issue

if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()){
CreateAndAttachConsole();
}
// Add this Code
// <------- From Here --------- >
else{
    STARTUPINFO si = {0};
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;

    PROCESS_INFORMATION pi = {0};
    WCHAR lpszCmd[MAX_PATH] = L"cmd.exe";
    if (::CreateProcess(NULL, lpszCmd, NULL, NULL, FALSE, CREATE_NEW_CONSOLE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
    {
      do
      {
        if (::AttachConsole(pi.dwProcessId))
        {
          ::TerminateProcess(pi.hProcess, 0);
          break;
        }
      } while (ERROR_INVALID_HANDLE == GetLastError());
      ::CloseHandle(pi.hProcess);
      ::CloseHandle(pi.hThread);
    }
}
// <------- UpTo Here --------- >

Additional information

Thanks to noble-winrt for initial BleServer Code

This is Just The Initial Version feel free to Contribute or Report any Bug!

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

ランキング