tijmenvangulik / cordova-usb-hid Goto Github PK
View Code? Open in Web Editor NEWCordova usb hid plugin
Cordova usb hid plugin
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>
**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 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.