Skip to content

Failed to execute 'open' on 'USBDevice': Access denied. #12

@vickyponraj

Description

@vickyponraj

Throws

RethrownDartError: SecurityError: Failed to execute 'open' on 'USBDevice': Access denied.
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 329:10 createErrorWithStack
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 265:28 _throw
dart-sdk/lib/core/errors.dart 120:5 throwWithStackTrace
dart-sdk/lib/async/zone.dart 1386:11 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7

class _MyHomePageState extends State<MyHomePage> {
  final UsbDevice usbDevice = UsbDevice();

  void _incrementCounter() async {
    const int vendorId = 0x4B43; // '4B43' in hexadecimal
    const int productId = 0x3830; // '3830' in hexadecimal

    final pairedDevice = await usbDevice.requestDevices(
        [DeviceFilter(vendorId: vendorId, productId: productId)]);

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


    debugPrint('usbVersionMajor - ${deviceInfo.usbVersionMajor}');
    debugPrint('usbVersionMinor - ${deviceInfo.usbVersionMinor}');
    debugPrint('usbVersionSubMinor - ${deviceInfo.usbVersionSubMinor}');
    debugPrint('deviceClass - ${deviceInfo.deviceClass}');
    debugPrint('deviceSubClass - ${deviceInfo.deviceSubClass}');
    debugPrint('deviceProtocol - ${deviceInfo.deviceProtocol}');
    debugPrint('vendorId - ${deviceInfo.vendorId}');
    debugPrint('productId - ${deviceInfo.productId}');
    debugPrint('deviceVersionMajor - ${deviceInfo.deviceVersionMajor}');
    debugPrint('deviceVersionMinor - ${deviceInfo.deviceVersionMinor}');
    debugPrint('deviceVersionSubMinor - ${deviceInfo.deviceVersionSubMinor}');
    debugPrint('manufacturerName - ${deviceInfo.manufacturerName}');
    debugPrint('productName - ${deviceInfo.productName}');
    debugPrint('serialNumber - ${deviceInfo.serialNumber}');
    debugPrint('opened - ${deviceInfo.opened}');

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

OUTPUT

usbVersionMajor - 1
usbVersionMinor - 1
usbVersionSubMinor - 0
deviceClass - 0
deviceSubClass - 0
deviceProtocol - 0
vendorId - 19267
productId - 14384
deviceVersionMajor - 0
deviceVersionMinor - 0
deviceVersionSubMinor - 0
manufacturerName - Caysn
productName - Thermal Printer
serialNumber - 4B48325338FFFF1400035068
opened - false
RethrownDartError: SecurityError: Failed to execute 'open' on 'USBDevice': Access denied.

dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 329:10 createErrorWithStack
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 265:28 _throw
dart-sdk/lib/core/errors.dart 120:5 throwWithStackTrace
dart-sdk/lib/async/zone.dart 1386:11 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions