vc6 & libusb

偶然间把一个usbbulk 的实验在java 里实现了,刚才又在VC 下用libusb 做了一个,虽然很简单,但也是遇到一个问题,在这里记下,为了备忘,也为了让同路人少走弯路。
首先 usb.h libusb0.dll libusb.lib 放到工程目录里,然后就是要在project setting 里添加libusb.lib 如下图:

vc6_libusb.jpg

然后就是写代码了,开始的时候不知道流程,总提示 could not claim interface 0 , 却不知道怎么办,偶尔在http://lists.alioth.debian.org/pipermail/sane-devel/2003-February/006638.html

看到usb_set_configuration(hdev, 1);

于是有了下面测试成功的程序:

// usb_paul.cpp : Defines the entry point for the console application.

//paul phenix s-yaojing@163.com

#include “stdafx.h”

#include “usb.h”

#define USB_VID 0×547

#define USB_PID 0×1002

int main(int argc, char* argv[])

{

struct usb_bus *bus;

struct usb_device *dev;

usb_dev_handle *hdev;

char writedata[] = {1,2,3,4,5};

char readdata[sizeof(writedata)];

printf(”Hello World!\n”);

usb_init();

usb_set_debug(3);

usb_find_busses();

usb_find_devices();

for (bus = usb_get_busses(); bus;bus->next)

{

for (dev = bus->devices; dev; dev->next)

{

hdev = usb_open(dev);

if (hdev)

{

int VID = dev->descriptor.idVendor;

int PID = dev->descriptor.idProduct;

if ((VID == USB_VID)&(PID == USB_PID))

{

printf(”The PID is 0x%4x \n”,PID);

printf(”The VID is 0x%4x \n”,VID);

usb_set_configuration(hdev, 1);

usb_claim_interface(hdev,0);

usb_bulk_write(hdev,0×04,writedata,sizeof(writedata),2000);

usb_bulk_read(hdev,0×88,readdata,sizeof(readdata),2000);

}

printf(”Readdata is :\n”);

for (int i =0 ;i<sizeof(readdata);i++)

{

printf(”Readdata is %d “,readdata[i]);

}

}

usb_close(hdev);

break;

}

break;

}

return 0;

}

其实功能很简单,就是在一个端点写入一组数据,然后在另外的一个端点读出,然后打印出来。在68013上跑的程序是bulkloop

from: http://s-yaojing.blog.163.com/blog/static/15455309200891045038662/


Technorati : ,

基于VC的USBASP上位机软件源码.rar

该日志未加标签。
News, usb

相关日志

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

(必填)

(必填)