ubuntu在线安装libusb

  • 在线安装命令
  • 1.安装命令: Ubuntu 测试 其他linux应该是一样的
     
    sudo apt-get install libusb-1.0-0-dev
    sudo apt-get install libusb-dev

     

  • 编译命令
  •  
    libusb库 1.23 之前(应该是的 1.23之前没有做测试)
    例1.gcc -o main main.c -lusb
    libusb库 1.23 之后
    例2.gcc -o main main.c -lusb-1.0

     

  • 问题及测试程序 点击访问
  • #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <libusb-1.0/libusb.h>
    #include <stdio.h>
    #include <sys/types.h>
    
    static void print_devs(libusb_device **devs)
    {
    
    	libusb_device *dev;
    	int i = 0;
    	while ((dev = devs[i++]) != NULL) {
    		struct libusb_device_descriptor desc;
    		int r = libusb_get_device_descriptor(dev, &desc);
    		if (r < 0) {
    			fprintf(stderr, "failed to get device descriptor");
    			return;
    		}
                    	printf("%04x:%04x (bus %d, device %d)\n",
    			desc.idVendor, desc.idProduct,
    			libusb_get_bus_number(dev), libusb_get_device_address(dev));
    	}
    }
    
    int main(void)
    {
    	libusb_device **devs;
    	int r;
    	ssize_t cnt; 
    	r = libusb_init(NULL);
    	if (r < 0)
    		return r;
    	cnt = libusb_get_device_list(NULL, &devs);
    	if (cnt < 0)
    		return (int) cnt;
    	print_devs(devs);
    	libusb_free_device_list(devs, 1);
    	libusb_exit(NULL);
    	return 0;
    
    }

     

     

上一篇:Windows下Qt+libusb PC程序与斑马打印机使用USB通信(1)——window环境下libusb的编译


下一篇:python之时间模块