node-uvc-control icon indicating copy to clipboard operation
node-uvc-control copied to clipboard

Setting UVCC autoWhiteBalance to 0 Getting LIBUSB_ERROR_IO

Open mesalagagan opened this issue 5 years ago • 8 comments

sudo uvcc devices

Optical Mouse [ vId: 0x458  / pId: 0x3a  ]
USB Keyboard [ vId: 0x4d9  / pId: 0x1702  ]
EHCI Host Controller [ vId: 0x1d6b  / pId: 0x2  ]
EHCI Host Controller [ vId: 0x1d6b  / pId: 0x2  ]
USB 2.0 Camera [ vId: 0xc45  / pId: 0x6366  ]

sudo uvcc --vendor 0xc45 --product 0x6366 set autoWhiteBalance 0

Error: LIBUSB_ERROR_IO

Screenshot from 2019-07-24 17-18-41

mesalagagan avatar Jul 24 '19 11:07 mesalagagan

I've seen IO error before, but it meant I didn't have permission to use the usb device.

positlabs avatar Jul 24 '19 12:07 positlabs

@GaganMeesala: I can confirm the problem -- am also getting LIBUSB_ERROR_IO on ubuntu. The same webcam works on macOS without any issue. Looks like the problem isn't in uvcc though, but in upstream code. Perhaps a change in libusb's nodejs wrapper?

joelpurra avatar Aug 09 '19 11:08 joelpurra

@positlabs: I've set permissions according to the (newly added) link in README.md, but it didn't fix this LIBUSB_ERROR_IO issue.

  • https://github.com/makenai/node-uvc-control/blob/ca1e2c963e98b309ad3b65c5fc538f052ea5fd64/README.md#notes
  • https://askubuntu.com/questions/978552/how-do-i-make-libusb-work-as-non-root

Note that the suggested fix is for LIBUSB_ERROR_ACCESS, not LIBUSB_ERROR_IO. Running as a superuser (in my case in a sudo su - shell) still gives LIBUSB_ERROR_IO. Looked through issues in node-usb, but didn't come up with anything substantial so far.

joelpurra avatar Aug 09 '19 11:08 joelpurra

Did some more testing in ubuntu 19 with a c920 webcam.

Note: seems usb v1.6.0 is required in node v12.11.1 -- or at least it's more convenient as it uses prebuild.

Looking at the constants in uvc-control and usb, it seems (based on bmRequestType) that uvc-control reads/writes using a camera interface rather than the camera device. Writing to an interface (on linux) requires claiming ("locking"?) the interface first. While it is possible to do so when another application (or the kernel?) is using the webcam, it will basically kill their interface and sort of crash the camera so it can't be opened (for video) again. Unplugging/plugging in the device makes it usable again, although a software reset might also work.

I have pushed unfinished patches for the two "current" uvc-control versions.

  • uvc-control v1.0.2: seems to fix usage in uvcc. (The separate uvcc devices still needs a fix.)
  • uvc-control v2 (unreleased): works for some values, but not all. One example is absolute_zoom, which works in v1 (as absoluteZoom) but gets LIBUSB_TRANSFER_STALL in v2.

Added various (temporary) branches in case you'd like to check them out already. Tested on ubuntu 19 and macos 10.14. Does it work for you @GaganMeesala, @positlabs?

Targeting the device in controlTransfer

You can install and run tests from the uvcc branches. Run ./index.js to use the local branch version and configure --verbose to see debug logs/warnings.

cd uvcc
rm -r node_modules
npm install
# NOTE: might need to configure your vendor/product.
./index.js --verbose export
./index.js --verbose ranges

v1-next

  • https://github.com/joelpurra/node-uvc-control/tree/v1-control-transfer-target-device
  • https://github.com/joelpurra/uvcc/tree/feature/uvc-control-v1-next
./index.js --verbose range absoluteZoom
./index.js --verbose get absoluteZoom
./index.js --verbose set absoluteZoom 150

v2-next

  • https://github.com/joelpurra/node-uvc-control/tree/v2-control-transfer-target-device
  • https://github.com/joelpurra/uvcc/tree/feature/uvc-control-v2-next
./index.js --verbose range absolute_zoom
./index.js --verbose get absolute_zoom
./index.js --verbose set absolute_zoom 150

Constant value debugging

Just getting the runtime values of constants, and printing numbers in decimal/binary/hexadecimal. Helped finding the interface/device fix.

  • https://github.com/joelpurra/node-uvc-control/tree/v1-debug-constants
  • https://github.com/joelpurra/node-uvc-control/tree/v2-debug-constants

Print constants to the console.

  • ./test/constants/usb-expanded.js
  • ./test/constants/uvc-control-expanded.js

joelpurra avatar Oct 10 '19 21:10 joelpurra

@joelpurra Looking forward to the fix. Thanks for your effort.

arielweinberger avatar Nov 04 '19 19:11 arielweinberger

Did anyone test the experimental branches so far? Might use the forked version of node-uvc-control to get uvcc running on linux, so a new version can be published on npm. It'd be nice to have someone else confirm the functionality first though.

joelpurra avatar Jan 21 '20 13:01 joelpurra

See #64.

joelpurra avatar Apr 10 '20 10:04 joelpurra

@gaganmesala: this should be fixed in uvcc v2.0.0, which was just released. Let me know if it works!

  • https://joelpurra.com/projects/uvcc/

joelpurra avatar Sep 02 '20 12:09 joelpurra