Lib usb如何从端口读取字符

发布于 2024-12-06 08:16:58 字数 578 浏览 4 评论 0原文

我想编写一个从 USB 设备读取数据的应用程序,并且正在寻找一个可以使工作变得更轻松的库。我找到了一个名为 lib-usb 的库。不幸的是,它几乎没有文档。这是我尝试过的:

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

     int main(){
        struct usb_device dev;
        struct usb_device *device;
        usb_dev_handle *handle;
        struct usb_bus bus;

usb_init();
            usb_find_busses();
            int a=usb_find_devices();
        bus=usb_get_buses();
        handle=usb_open(device);

            return 0;
        }

但我不知道如何选择我想要读取的端口。我想将读取的数据保存为字符串。任何建议表示赞赏。

I want to write an application that reads data from the USB device and was looking for a library that can make the job easier. I found a library called lib-usb. Unfortunately, it has almost no documentation. Here is what I have tried:

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

     int main(){
        struct usb_device dev;
        struct usb_device *device;
        usb_dev_handle *handle;
        struct usb_bus bus;

usb_init();
            usb_find_busses();
            int a=usb_find_devices();
        bus=usb_get_buses();
        handle=usb_open(device);

            return 0;
        }

But I can't figure out how to select a port that I want to read from. I would like to save read data as a string. Any advice is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-12-13 08:16:58

USB 并不真正传输字符,而是传输数据包。此外,你的代码根本没有任何意义;在 http://libusb.sourceforge.net/api-1.0/,我建议您阅读。

USB doesn't really transfer characters -- it transfers packets. Additionally, your code makes no sense at all; there is some pretty good documentation online at http://libusb.sourceforge.net/api-1.0/, which I recommend that you read.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文