标签: libusb

使用 libusb 和 Ruby 从 USB 设备(Waterrower S4 Monitor)读取数据

我买了一个Waterrower,它有一个S4 性能监视器,背面有一个微型 USB 连接器,我认为能够获取来自 S4 的数据并用它做一些很好的事情会很好。

我确实知道一些 Ruby,但我一点也不喜欢与硬件交谈。我确实在 Github 上找到了Lars Kanislibusb Ruby 绑定,并使用了它:

2.1.0 :001 > require "libusb"
 => true 
2.1.0 :002 > usb = LIBUSB::Context.new
 => #<LIBUSB::Context:0x000001011451c0 @ctx=#<FFI::Pointer address=0x000001032788b0>, @on_pollfd_added=nil, @on_pollfd_removed=nil, @hotplug_callbacks={}> 
2.1.0 :003 > usb.devices
 => [#<LIBUSB::Device 20/9 04d8:000a Microchip Technology Inc. CDC RS-232: WR-S4.2 ? (Comm (00,00))>, #<LIBUSB::Device 20/8 054c:0243 Sony Storage Media 2A08080530914 (MassStorage SCSI Bulk-Only)>, #<LIBUSB::Device 20/1 05ac:025a Apple Inc. Apple Internal Keyboard / Trackpad ? (HID …
Run Code Online (Sandbox Code Playgroud)

ruby macos usb libusb osx-yosemite

2
推荐指数
1
解决办法
3251
查看次数

CMake/Make 找不到 libusb

我是 C/C++ 新手,正在尝试在 Ubuntu 机器(Trusty Tahr)上本地构建和运行ttwatch 。说明包括首先安装一些库:cmake、openssl、curl、libusb,并包含安装“-dev”版本的注释(例如 libssl-dev、libcurl-dev、libusb-1.0-0-dev)。我在使用 libusb 时遇到了一些麻烦。我在互联网上看到了有关此问题的问题,但尚未找到有效的解决方案。

运行cmake .似乎工作正常:

meowmeow@kittytown:~/code/ttwatch$ cmake .
-- Enabled daemon function
-- Found libusb-1.0:
--  - Includes: /usr/include/libusb-1.0
--  - Libraries: /usr/lib/x86_64-linux-gnu/libusb.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/meowmeow/code/ttwatch
Run Code Online (Sandbox Code Playgroud)

但运行make显示 libusb 没有正确定位:

meowmeow@kittytown:~/code/ttwatch$ make
[ 42%] Built target libttbin
[ 42%] Built target libttwatch
[ 42%] Built target ttbincnv
[ 42%] Built target ttbinmod
[ 42%] Built target manifest …
Run Code Online (Sandbox Code Playgroud)

c c++ makefile cmake libusb

2
推荐指数
1
解决办法
2万
查看次数

C中的奇怪宏声明

可能重复:
为什么在C/C++宏中有时会出现无意义的do/while和if/else语句?
做{...}而(0)有什么好处?

探索libusb-1.0.9源代码,我找到了这样的line(./os/poll_windows.c:78):

#define CHECK_INIT_POLLING do {if(!is_polling_set) init_polling();} while(0)
Run Code Online (Sandbox Code Playgroud)

至于我,这是一样的:

#define CHECK_INIT_POLLING if(!is_polling_set) init_polling();
Run Code Online (Sandbox Code Playgroud)

是否有理由循环该表达式?

更新:

在答案之后,我仍然无法意识到会出现什么问题,以下示例有助于:

#include <stdio.h>

#define TEST if(test) foo();
#define TEST_DO do { if(test) foo(); } while(0)

int test = 1;
void foo() {
    printf("%s", "Foo called");
}

int main(int argc, char** argv) {
    if(argc > 1) TEST_DO; /* LINE 12 */
    else printf("%s", "skipping...");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果放在TEST第12行,编译器将给出错误"error: ‘else’ without a previous ‘if’".
希望,这会有所帮助.

c libusb libusb-1.0

1
推荐指数
1
解决办法
205
查看次数

如何获得 USB iManufacturer 编号?

这是我的 C 代码:

int main()
{
    struct usb_bus *busses, *bus;
    usb_init();
    usb_find_busses();
    usb_find_devices();

    busses = usb_get_busses();

    for (bus = busses; bus; bus = bus->next)
    {
        struct usb_device *dev;

        for (dev = bus->devices; dev; dev = dev->next)
        {
            struct usb_device_descriptor *desc;

            desc = &(dev->descriptor);
            printf("idVendor/idProduct ID: %2.2x : %2.2x\n",desc->idVendor,desc->idProduct);

            if ((desc->idVendor == 0x2232) && (desc->idProduct == 0x6001))
            {
                printf("iManafacturer/iProduct ID: %04x  :%04x \n",desc->iManufacturer,desc->iProduct);
                //return dev;
            }
        }
    }
    system("pause");
    return NULL;
}
Run Code Online (Sandbox Code Playgroud)

在我编译代码(编译结果)后,我无法像USBView结果一样获得iManufacturer编号。我不知道如何像USBView显示那样获得iManufacturer(例如NMGAAI00010200144W11111)。

我怎样才能做到这一点?

编译结果 USB查看结果

c usb driver libusb

1
推荐指数
1
解决办法
4661
查看次数

在Linux上使用libusb编译c代码时出现问题

我正在尝试在项目中使用 libusb,但无法使库正常工作。这是我正在尝试编译的一些源代码。它没有做任何特别的事情。它只是一个获取 USB 驱动程序列表然后释放它的虚拟程序。

#include <stdio.h>
#include <usb.h>
#include <stdlib.h>

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

     struct libusb_device **devs;
     struct libusb_context *context = NULL;
     size_t list;
     size_t i;
     int ret;

   ret = libusb_init(&context);

   if(ret < 0)
      {
        perror("libusb_init");
        exit(1);
      }

   list = libusb_get_device_list(context, &devs);

   if(list < 0)
   {

       fprintf(stderr, "error in getting device list\n");
       libusb_free_device_list(devs, 1);
       libusb_exit(context);
       exit(1);
   }


   libusb_free_device_list(devs, 1);
   libusb_exit(context);

  return 0;

}
Run Code Online (Sandbox Code Playgroud)

我编译用

gcc -o 测试 test.c -lusb

我收到错误

/tmp/cc2hwzii.o: in function 'main:
test.c:(.text+0x24): undefined reference to 'libusb_init' …
Run Code Online (Sandbox Code Playgroud)

c linux libusb

1
推荐指数
1
解决办法
2708
查看次数

如何使用FTDI D2XX驱动程序API获取Linux设备

我正在使用FTDI D2XX驱动程序API与FTDI设备进行通信.它给了我一些关于设备的信息,比如locid,serialnumber,description,但这还不够.

如何/dev/ttyUSBXX使用此API 获取设备编号()或总线或端口.

谢谢

driver libusb linux-device-driver ftdi d2xx

1
推荐指数
1
解决办法
2625
查看次数

brew install libusb 链接失败

我正在Mac 中使用brew安装libusb

brew 安装 libusb

链接步骤失败如下

Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local 

Could not symlink lib/libusb-1.0.0.dylib 

Target /usr/local/lib/libusb-1.0.0.dylib already exists. 

You may want to remove it:   rm '/usr/local/lib/libusb-1.0.0.dylib'

To force the link and overwrite all conflicting files:   brew link
--overwrite libusb
Run Code Online (Sandbox Code Playgroud)

所以我删除了现有的 libusb

须藤rm'/usr/local/lib/libusb-1.0.0.dylib'

然后做了一个链接

酿造链接--覆盖libusb

链接不起作用,下面显示错误

错误:无法符号链接 lib/libusb-1.0.0.dylib

/usr/local/lib 不可写。

如果我尝试

须藤酿造链接--覆盖libusb

相反,这也不起作用。我错过了什么?

我使用的是 OSX El Capitan 版本 10.11.4 (15E65)

homebrew libusb

1
推荐指数
1
解决办法
8689
查看次数

libusb 支持为 Freescale imx6 板构建 Yocto

我目前正在使用 Yocto 创建替代 BSP 来替换现有的 BSP。我是 Yocto 的新手,我需要知道如何向 Yocto 添加 libusb 支持以在连接时检测蓝牙适配器。

问候, 帕万

usb bluetooth bsp libusb yocto

1
推荐指数
1
解决办法
1660
查看次数

错误:非静态成员函数 'int test::hotplug_callback(libusb_context*, libusb_device*, libusb_hotplug_event, void*)' 的使用无效

我改编了 libusb 热插拔示例

\n\n

* libusb example program for hotplug API\n * Copyright \xc2\xa9 2012-2013 Nathan Hjelm <hjelmn@mac.com>

\n\n

(下面的代码)作为测试并将其放入类中,因为我的真实程序也有同样的问题。\n我知道如果我将 static 放在它起作用的两个回调前面,但我不希望它们是静态的。我想从回调访问我的实例变量。这个想法是用户插入一个 USB 设备,我们称之为 usbXYZ。从回调中,我实例化类 usbXYZ 并放入 std::map - 用户将其删除,然后我将其从地图中删除。包含带有对象的 std::map 的类有一个“更高级别”的方法来写入设备。

\n\n

请问如何使回调函数非静态工作?如果可能的话请解释一下,因为我不明白。谢谢。

\n\n
#include <stdlib.h>\n#include <stdio.h>\n#include <thread>\n\n#include "libusb-1.0/libusb.h"\n\nclass test{\npublic:\n    test() {\n        okGo();\n    }\n\nprivate:\n    int done = 0;\n    libusb_device_handle *handle = NULL;\n\n    int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)\n    {\n        struct libusb_device_descriptor desc;\n        int rc;\n\n        (void)ctx;\n        (void)dev;\n        (void)event;\n        (void)user_data;\n\n        rc = libusb_get_device_descriptor(dev, &desc);\n        if (LIBUSB_SUCCESS != …
Run Code Online (Sandbox Code Playgroud)

c++ libusb

0
推荐指数
1
解决办法
258
查看次数