系统调用中断

时间:2012-06-10 17:54:10

标签: linux libusb-1.0

当我选择设备时运行代码我得到输出(显示后面的部分):

选择设备:7

Productid = 785
Vendorid = 1480 Claimed Interface./new:@ g :系统调用中断

我认为这可能是由于错误的端点或接口没有。但后来我也不知道怎么知道得到它们。请帮帮我。

enter code here

if(idx==numUsbDevs) 
            { printf("\n\nselect the device :  ");
              scanf("%d",&idx);
         if(idx > numUsbDevs)
             {printf("Invalid input, Quitting.............");
              break; }    

       devPtr = devList[idx-1];

       retVal = libusb_open (devPtr, &devHandle);
           if (retVal != LIBUSB_SUCCESS)
           break;

      retVal = libusb_get_device_descriptor (devPtr, &devDesc);
           if (retVal != LIBUSB_SUCCESS)
           break;
               printf ("  \nProductid     = %d", devDesc.idProduct);
               printf ("  \nVendorid      = %d", devDesc.idVendor);


   //========================================================================
   // Reading Data
   //========================================================================

     unsigned char data[4]; //data to read

         //data[0]='a';data[1]='b';data[2]='c';data[3]='d'; //some dummy values


    if(libusb_kernel_driver_active(devHandle, 0) == 1) { //find out if kernel driver is attached

         printf("\nKernel Driver Active\n");

    if(libusb_detach_kernel_driver(devHandle, 0) == 0) //detach it

        printf("Kernel Driver Detached!");
     }

         int r; //for return values 
          r = libusb_claim_interface(devHandle, 0); //claim interface 0 (the first) of device

      if(r < 0) {

    printf("\nCannot Claim Interface %d",r);

    return 1;
                }

    printf("\nClaimed Interface");

   int actual_length; //used to find out how many bytes were written


   r = libusb_bulk_transfer(devHandle,LIBUSB_ENDPOINT_IN, data, sizeof(data), &actual_length, 0);

      if (r == 0 && actual_length == sizeof(data)) {

              // results of the transaction can now be found in the data buffer
             // parse them here and report button press
          } 
      else {
             error();
           } 


   r = libusb_release_interface(devHandle, 0); //release the claimed interface

   if(r!=0) {

            printf("\nCannot Release Interface");

            return 1;
           }

            printf("\nReleased Interface");


            idx=numUsbDevs +2; //to exit if statement
            }

   }  // end of while loop

0 个答案:

没有答案