日期:2014-05-16  浏览次数:20669 次

在linux中是不是能看到设备节点就说明设备可以被访问了
我的USB设备现在可以看到/proc/bus/usb/001/008的可是在下面的访问的时候总是不行,求助大家帮忙看下问题在哪

芯片:CY7C68013
系统:企业版Redhat5以上

下面是用libusb1.0的部分代码


libusb_get_device_list可以看到所有usb设备,本设备信息Number of possible configurations: 1 Device Class: 0 VendorID: 1607 ProductID: 4098Interfaces: 1 ||| Number of alternate settings: 1 | Interface Number: 0 | Number of endpoints: 2 | Descriptor Type: 5 | EP Address: 130 | Descriptor Type: 5 | EP Address: 134 | 

可根据上面的VendorID: 1607 ProductID: 4098 用./getdevpath -v647 -p1002
查到/proc/bus/usb/001/008,拔掉设备则查不到

打开设备
dev_handle = libusb_open_device_with_vid_pid(ctx, 1607, 4098); 
  if(dev_handle == NULL)
  cout<<"Cannot open device"<<endl;
  else
  cout<<"Device Opened"<<endl;


结果为 Device Opened

int actual; //used to find out how many bytes were written
  if(libusb_kernel_driver_active(dev_handle, 0) == 1) { //find out if kernel driver is attached
  cout<<"Kernel Driver Active"<<endl;
  if(libusb_detach_kernel_driver(dev_handle, 0) == 0) //detach it
  cout<<"Kernel Driver Detached!"<<endl;
  }
  r = libusb_claim_interface(dev_handle, 0); //claim interface 0 (the first) of device (mine had jsut 1)
  if(r < 0) {
  cout<<"Cannot Claim Interface"<<endl;
  return 1;
  }
  cout<<"Claimed Interface"<<endl;
  cout<<"Data->"<<data1<<"<-"<<endl; //just to see the data we want to write : abcd
  cout<<"Writing Data..."<<endl;
  r = libusb_bulk_transfer(dev_handle, (2 | LIBUSB_ENDPOINT_OUT), data1, 5, &actual, 0); //my device's out endpoint was 2, found with trial- the device had 2 endpoints: 2 and 129
  if(r == 0 && actual == 4) //we wrote the 4 bytes successfully
  cout<<"Writing Successful!"<<endl;
  else
  {
  perror("Write Error");
  };

这里出现错误错误信息为

libusb:error [submit_bulk_transfer] submiturb failed error -1 errno=2
Write Error: No such file or directory


------解决方案--------------------
没人回答