Code Monkey home page Code Monkey logo

cordova-usb-hid's People

Contributors

tijmenvangulik avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cordova-usb-hid's Issues

Don't have permissions to enumerate devices

I'm using the first example you have given in a Vue3 application.
When I attempt to enumerate devices I get the following error.

Uncaught (in promise) Can not enumerate devices: User has not given 10529/net.karliner.hidthingtest permission to access device /dev/bus/usb/001/002

At the moment, I can't see how to request usb enumeration permissions.
As you obviously have got your example running, could you tell me how you get them?

My target is Android 11 (moto9 plus)

Code as follows:

<script>
import { defineComponent } from "vue";

export default defineComponent({
  name: "IndexPage",
  async mounted() {
    console.log("Hello Thing");
    this.numhids = "3";

    console.log(window.cordova.plugins.UsbHid.registerReadCallback);
    await window.cordova.plugins.UsbHid.registerReadCallback((response)=>{
              console.log("received "+buf2hex(response));
    })
    var devices=await cordova.plugins.UsbHid.enumerateDevices();
    if (devices.length==0) throw "Device not found";
    await cordova.plugins.UsbHid.requestPermission(devices[0]);
    await cordova.plugins.UsbHid.open({
                                  packetSize:121,
                                  skippFirstByteZero:true,
                                  writeTimeout:500});
    var data= new Uint8Array([0x02,0xF0,0xFD,0x00,0x80,0x80,0xF2]);
    await cordova.plugins.UsbHid.write(data)
    console.log("Devidces ", devices)
  },
  data() {
    return {
      numhids: "0",
    };
  },
});
</script>

ERROR ReferenceError: cordova is not defined when I integred cordova github plugin

**Hello, thanks for your library.

As decribed on the readme. I have integred the library in my project.
The code of my .ts is below :**
``
import { Component } from '@yuny/core';
declare interface Cordova {
plugins:CordovaPlugins;
}
declare interface CordovaPlugins {
UsbHid : UsbHidPlugin;
}
declare var cordova: Cordova;
@component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
constructor() {}
showAlert() {
console.log("oui")
cordova.plugins.UsbHid.registerReadCallback((response)=>{
//console.log("received "+buf2hex(response));
});
var devices= cordova.plugins.UsbHid.enumerateDevices();
console.log(devices)
if (devices.length==0) throw "Device not found";
cordova.plugins.UsbHid.requestPermission(devices[0]);
cordova.plugins.UsbHid.open({
packetSize:64,
skippFirstByteZero:true,
writeTimeout:500});
var data= new Uint8Array([0x02,0xF0,0xFD,0x00,0x80,0x80,0xF2]);
cordova.plugins.UsbHid.write(data)
}
}

When I run this code I have this error output:
``
consolelogs.js:49 ERROR ReferenceError: cordova is not defined
at Tab1Page.showAlert (tab1.page.ts:23)
at Object.eval [as handleEvent] (Tab1Page.html:41)
at handleEvent (core.js:38098)
at callWithDebugContext (core.js:39716)
at Object.debugHandleEvent [as handleEvent] (core.js:39352)
at dispatchEvent (core.js:25818)
at core.js:37030
at HTMLButtonElement. (platform-browser.js:1789)
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:34182)

Please can you help me to fix this bug ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.