Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vickyponraj opened this issue Oct 31, 2024 · 0 comments
Open

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

vickyponraj opened this issue Oct 31, 2024 · 0 comments

Comments

@vickyponraj
Copy link

vickyponraj commented Oct 31, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant