win_ble 0.0.2 copy "win_ble: ^0.0.2" to clipboard
win_ble: ^0.0.2 copied to clipboard

outdated

WinBle Plugin to use Bluetooth Low Energy in Flutter Windows Desktop

WinBle #

WinBle Plugin to use Bluetooth Low Energy in Flutter Windows

Getting Started #

add this package to pubspec.yaml file

win_ble: ^0.0.2

requires Windows version >= 10.0.15014

Make Sure to Add this code in your project's =>

/windows/runner/main.cpp file , otherwise Windows Console will open on running Application

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

Usage #

First initialize WinBle by Calling this Method

 WinBle.initialize();

Dispose WinBle after using , by Calling

 WinBle.dispose();

To Start Scan , Call

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

To Stop Scan , Call

  WinBle.stopScanning();
  scanStream?.cancel();

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);

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
    });

Additional information #

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

33
likes
0
pub points
86%
popularity

Publisher

verified publisherrohitsangwan.site

WinBle Plugin to use Bluetooth Low Energy in Flutter Windows Desktop

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, path_provider

More

Packages that depend on win_ble