Js how to read data from USB device
- User
Js how to read data from USB device
- Assistant
- User
I have that JS code and i got an error Cannot read properties of null (reading 'addEventListener') Code: async function connectToUsbDevice() { try { // Request a USB device const device = await navigator.usb.requestDevice({ filters: [] });
// You can specify filters for specific devices console.log('Device selected:', device); // Open the USB device await device.open(); console.log('Device opened:', device); // Select a configuration await device.selectConfiguration(1); console.log('Configuration selected:', device); // Claim an interface await device.claimInterface(0); console.log('Interface claimed:', device); // Now, read data from the device const data = await readFromDevice(device); console.log('Data received from device:', data); // Release the interface when you are done await device.releaseInterface(0); console.log('Interface released:', device); // Close the device await device.close(); console.log('Device closed:', device);} catch (error) { console.error('Error:', error); } }
- Assistant
- User
I have a JS code and i getting an error Cannot read properties of null (reading 'addEventListener') Code: async function connectToUsbDevice() { try { // Request a USB device const device = await navigator.usb.requestDevice({ filters: [] });
// You can specify filters for specific devices console.log('Device selected:', device); // Open the USB device await device.open(); console.log('Device opened:', device); // Select a configuration await device.selectConfiguration(1); console.log('Configuration selected:', device); // Claim an interface await device.claimInterface(0); console.log('Interface claimed:', device); // Now, read data from the device const data = await readFromDevice(device); console.log('Data received from device:', data); // Release the interface when you are done await device.releaseInterface(0); console.log('Interface released:', device); // Close the device await device.close(); console.log('Device closed:', device);} catch (error) { console.error('Error:', error); } }
- Assistant
- User
I got an error on my JS code - Cannot read properties of null (reading 'addEventListener')
- Assistant
- User
After clicking on button and choosing Barcode scanner i got an error - SecurityError: Failed to execute 'open' on 'USBDevice': Access denied.
- Assistant
- User
Переделай приложение для localhost
- Assistant
- User
I use module http and i still getting error - SecurityError: Failed to execute 'open' on 'USBDevice': Access denied.
- Assistant
- User
i have another error - Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- Assistant
- User
i got an error GET http://localhost:8080/favicon.ico 404 (Not Found)
- Assistant
- User
Ok, i did exactly like you answer me but i still getting error - script.js:35 Error: SecurityError: Failed to execute 'open' on 'USBDevice': Access denied.
- Assistant
- User
I coping http://localhost:8080 but in web it transform into http://localhost:8080/ maybe its a problem?
- Assistant
- User
i got a message that Device selected and i got a data from USBDevice, but it still Access denied when i trying await device.open();
- Assistant
- User
in message Device selected that i got i have an info about configuration, here is configurationValue is 1 but configurationName is null
- Assistant
- User
Problem isnt with getting wrong properties problem is that Access denied when i trying use await device.open();
- Assistant
- User
when i click on button a see a list where i can to choose an usb device, now i tried other like keyboard and mouse they opened
- Assistant
- User
This scanner use a OPOS protocol maybe it will help you
- Assistant
- User
Yes that scanner have another interface type USB keyboard (HID)
- Assistant
- User
But i want to take a data from barcode scanner even if web page is collapsed and mouse focus in wrong place
- Assistant
- User
No i want it on JS and i find another interface type for scanner - USB HID POS
- Assistant