Home > OS >  Help libusb_claim_interface return - 6 if system automatic load is prohibited
Help libusb_claim_interface return - 6 if system automatic load is prohibited

Time:05-26

Operating system: UOS 20
In order to add rules under the user permissions to access the USB device file
 SUBSYSTEM=="usb", ATTRS {idVendor}=="1111", the MODE="0666" 


The sample code
 # include & lt; Stdio. H> 
# include & lt; Stdlib. H>
# include & lt; String. H>
# include & lt; Stdarg. H>
# include & lt; Unistd. H>
# include "libusb. H"

Libusb_context * g_stUsbCtx=0;
Struct libusb_device pDevList=0 * *, * pCurDev=0;
Struct libusb_device_handle * pDevHandle=0;
Int main ()
{
Int iRtn=0;
If (g_stUsbCtx==0)
{
IRtn=libusb_init (& amp; G_stUsbCtx);
If (iRtn & lt; 0)
{
IRtn=1;
Return iRtn;
}
}
IRtn=libusb_get_device_list (g_stUsbCtx, & amp; PDevList);
If (iRtn & lt; 0)
{
IRtn=1;
Return iRtn;
}
PDevHandle=libusb_open_device_with_vid_pid (x2222 g_stUsbCtx x1111 0, 0);
If (pDevHandle & lt;=0)
{
IRtn=1;
Libusb_close (pDevHandle);
PDevHandle=0;
Return iRtn;
}


Uint8_t ucInterfaceIndex=0;
IRtn=libusb_claim_interface (pDevHandle ucInterfaceIndex);

If ((iRtn!=LIBUSB_SUCCESS) & amp; & (ucInterfaceIndex==0))
{
IRtn=libusb_detach_kernel_driver (pDevHandle ucInterfaceIndex);

IRtn=libusb_claim_interface (pDevHandle ucInterfaceIndex);
}
IRtn=libusb_release_interface (pDevHandle ucInterfaceIndex);


//close
If (pDevHandle)
{

If (ucInterfaceIndex!=(uint8_t) (1))
{
Libusb_detach_kernel_driver (pDevHandle ucInterfaceIndex);
}
Libusb_close (pDevHandle);
PDevHandle=0;
}
return 0;
}



UOS system will automatically load my USB devices, cause libusb_claim_interface must fail the first time, you need to call libusb_detach_kernel_driver to unload equipment.
This time the problem comes, each invocation libusb_detach_kernel_driver, system can play box prompts "equipment has pulled up,"
Is there a way to make it not tip, it's best to keep the system doesn't automatically loaded my device, or in the case of don't need to uninstall issued instructions,

Thanks for your bosses!
  • Related