【发布时间】:2019-03-16 07:00:41
【问题描述】:
这两天我一直在寻找一种方法来编写程序或制作驱动程序来处理我的 USB 设备端的 USB 串行请求。我专门制作了 USB 设备,连接它的唯一方法是通过 USB 串行端口,在我的 PC 上,我使用 Google 的 Webusb API 访问设备上的终端控制台。所以我可以发送 Linux 命令(即 ifconfig),所以我想做的是构建可以在设备上运行的东西,以监听来自 USB 串行的请求并发送正确的响应。例如,我有一个在 Arduino 上运行的 C 代码完全符合我的要求,但问题是该代码仅适用于 Arduino,不适用于我的设备,这里是 c 代码:
// Third-party WebUSB Arduino library
#include <WebUSB.h>
WebUSB WebUSBSerial(1 /* https:// */, "webusb.github.io/arduino/demos");
#define Serial WebUSBSerial
void setup() {
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect.
}
Serial.write("WebUSB FTW!");
Serial.flush();
}
void loop()
{
if (webUsbSerial)
{
if (webUsbSerial.available())
{
int byte = webUsbSerial.read();
if (byte == 'h')
{
webUsbSerial.write("hallo from Arduino");
}
else
webUsbSerial.write("sorry not a function yet!!!!");
webUsbSerial.flush();
}
}
}
正如您在此示例中看到的,我检查命令是否为“h”并发送hello world。我想在我的具有 Linux 操作系统的设备上做同样的事情,
我试过libusb,但我认为这是一个USB-host API而不是USB-Device。
提前谢谢你。
【问题讨论】:
标签: linux linux-kernel usb linux-device-driver usbserial