当前位置: 技术问答>linux和unix
程序出错啦!!!
来源: 互联网 发布时间:2016-04-28
本文导语: #include #include #define BUF_SIZE 1024 typedef struct { struct usb_device *udev; usb_dev_handle *device_handle; }device_descript; #define USB_TIMEOUT 10000 #define VENDOR_ID 0x0204 //USB设备的厂商编号 #define PRODUCT_ID 0x6025 //USB设备...
#include
#include
#define BUF_SIZE 1024
typedef struct
{
struct usb_device *udev;
usb_dev_handle *device_handle;
}device_descript;
#define USB_TIMEOUT 10000
#define VENDOR_ID 0x0204 //USB设备的厂商编号
#define PRODUCT_ID 0x6025 //USB设备的产品编号
#define DEVICE_MINOR 16
int g_num;
device_descript g_list[DEVICE_MINOR]; //保存USB设备的相关属性
int Device_Find();//寻找USB设备,并将设备信息保存到g_list中
int Device_Open();//根据相关信息打开USB设备
int Device_Read(usb_dev_handle * handle,struct usb_interface_descriptor*interface,char readBuf[]);//操作设备,读取数据到readBuf中
int Device_Close(usb_dev_handle *handle);
int main()
{
int i;
usb_dev_handle *handle;
struct usb_interface_descriptor *interface;
char BUF[BUF_SIZE+1];
Device_Find();
Device_Open();
for(i=0;iconfig->interface->altsetting;
if(handle)
{
printf("usb device was opened!n");
/////////////////////////////////////////////////////////////
//这里数据读不出来,请问哪里出错了?
Device_Read(handle,interface,BUF);
/////////////////////////////////////////////////////////////
Device_Close(handle);
}
else
printf("cannot open usb device!n");
}
printf("%sn",BUF);
return 0;
}
int Device_Find()
{
struct usb_bus *bus;
struct usb_device *dev;
struct usb_bus *busses;
g_num=0;
usb_init();
usb_find_busses();
usb_find_devices();
busses=usb_get_busses();
for(bus=busses;bus;bus=bus->next)
{
for(dev=bus->devices;dev;dev=dev->next)
{
if(dev->descriptor.idVendor==VENDOR_ID && dev->descriptor.idProduct==PRODUCT_ID)
{
if(g_num