manuelbl / JavaDoesUSB

USB library for Java
MIT License
136 stars 10 forks source link

Is this lib suitable for optical mouse configuration ? #23

Open pooyamotorhead opened 2 months ago

pooyamotorhead commented 2 months ago

Hello , Good day Im gonna write a program for read/write optical mouse configurations like turning off RGB lights and so on. Is this library suitable for this kind of programming in JAVA ? Is there any example for mouse configuration by using this lib ? Thank You

manuelbl commented 2 months ago

I‘m not familiar with what protocol the mouse uses for configuration. If the protocol is on a separate USB interface from the standardized HID interface, then this library can likely be used. If it is implemented on top of HID, then no because the HID interface is exclusively claimed by the operating system.

If you have more information about the protocol then I can likely provide more information.

pooyamotorhead commented 2 months ago

Hi I tried to send some commands to my device (an Optical Mouse)

Im getting this error :

INFO: Child device USB\VID_4E53&PID_5406&MI_01\6&3b5a55ec&0&0001 has no device path / interface GUID Exception in thread "AWT-EventQueue-0" net.codecrete.usb.UsbException: claiming interface failed (function has no device path / interface GUID, might be missing WinUSB driver)

Here's my code :

var testDevice = Usb.findDevice(0x4e53,0x5406).orElseThrow();
testDevice.open();
testDevice.claimInterface(1);
var transfer = new UsbControlTransfer(UsbRequestType.VENDOR, UsbRecipient.INTERFACE, 9, 775, 1);
testDevice.controlTransferOut(transfer, null);
testDevice.close();

What's wrong with it ?

manuelbl commented 2 months ago

You are using Windows and the WinUSB driver is not installed for interface 1. As described on the project's home page, the WinUSB driver is required to communicate with the device (other than enumerating it).

Most devices designed for WinUSB can instruct Windows to automatically install the driver. But this doesn't seem to be the case here.

You can use Zadig to install the WinUSB driver. Be careful. If another driver is installed for USB interface 1, replacing the driver will likely break some software. If the HID driver is installed on interface 1, the mouse will no longer work as a mouse. It can be restored (see Zadig documentation). But you will need another mouse to actually do it.

You can also run the enumerate example and then post the part of the output of the optical mouse here. That would help me better understand the USB device.

pooyamotorhead commented 2 months ago

Thank You for your support dear Manuel .