向 USB 数据引脚发送 0 和 1?

发布于 2024-12-27 05:40:51 字数 120 浏览 2 评论 0原文

我正在尝试弄清楚如何制作一些软件和 USB 硬件。

我们暂时把硬件问题放在一边。对于软件来说,如何将数据发送到USB端口?

C++ / Java 或任何其他语言(最好在 Linux 上工作)。

Am trying to figure how can I make some software and USB hardware.

Let's put the hardware thing aside for now. For software, how can I send data to a USB port?

C++ / Java or any other language (prefer to be working on Linux).

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

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

发布评论

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

评论(5

素衣风尘叹 2025-01-03 05:40:51

USB 端口与“哑”RS-232 串行端口不同。它是一条总线,需要相当复杂的处理,全部由主机(通常是计算机)驱动。非常低级的操作,例如“发送 1 和 0”到数据引脚或多或少是不可能的。

在 Linux 中从用户空间对 USB 进行编程的最简单方法可能是使用 libusb

在客户端(您的自定义 USB 硬件)端,要么寻找具有内置 USB 控制器的系统,要么寻找软件堆栈。我认为编写自己的软件堆栈是不可行的,因为您(无意冒犯)对于 USB 的了解似乎还没有达到那个水平。

例如,V-USB 是用于 Atmel AVR 微控制器的软件 USB 堆栈。

USB ports are not like "dumb" RS-232 serial ports. It's a bus, that requires quite complicated handling, all driven by the host (the computer, typically). Very low-level operations such as "sending ones and zeros" to the data pins are more or less impossible.

The easiest way to program USB from user-space in Linux is probably to use libusb.

On the client (your custom USB hardware) end, either look for a system featuring a built-in USB controller, or a software stack. I don't think writing your own software stack is feasible, since you (no offense) don't seem to be quite at that level regarding your knowledge of USB.

V-USB is a software USB stack for Atmel's AVR microcontrollers, for instance.

原来分手还会想你 2025-01-03 05:40:51

正如其他人指出的那样,您必须为 USB 设备编写驱动程序。

另一种选择是通过 USB 使用串行协议与设备进行通信,那么您的硬件需要 USB 转串行芯片。关于USB串行的最佳答案是在问题如何让 C++ 从 USB 端口(如串行端口)执行 I/O 作者:Mike DeSimone

As others have pointed out you have to write a driver for the USB device.

Another option is to communicate with the device using a serial protocol over USB, then your hardware needs an USB to serial chip. The best answer regarding USB over serial is in the question How to get C++ to perform I/O from a USB Port like a Serial Port by Mike DeSimone

苏璃陌 2025-01-03 05:40:51

如果您想使用 USB 进行 bitbang I/O,那么您可以将 FTDI 芯片(如 FT232)(用于许多 USB 转串行电缆)连接到 USB 端口。
在 PC 上,您可以使用 libFTDI 对 FTDI 芯片的 I/O 引脚进行 bitbang 。

我认为这是使用 USB 控制 I/O 引脚的最简单方法。

If you want to bitbang I/O using USB, then you can connect a FTDI chip like the FT232 (which is used in many USB to serial cables) to the USB port.
On the PC you can use libFTDI to bitbang the I/O pins of the FTDI chip.

I think this is the easiest way for controlling I/O pins using USB.

就此别过 2025-01-03 05:40:51

串行端口模拟的替代方案是 USB HID(人体输入设备),Linux 开箱即用地支持它。您将使用“HIDAPI”与您的设备进行通信。

An alternative to serial port emulation is USB HID (Human Input Device), which is supported on Linux out of the box. You'd use the "HIDAPI" to communicate with your device.

指尖凝香 2025-01-03 05:40:51

USB 端口只是一个串行端口。因此,您首先要考虑的是编写一个软件来处理串行端口通信。

请注意,每当设备连接时,操作系统可能会为其分配不同的端口号。

A usb port is just a serial port. Therefore, the first place that you want to look is writing a sofware to handle serial port communication.

Be aware that the OS may assign a different port number to the device whenever it's connected.

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