【问题标题】:How to logically disconnect and reconnect a USB modem without unplugging it physically如何在不物理拔出 USB 调制解调器的情况下逻辑断开和重新连接
【发布时间】:2015-06-01 07:57:55
【问题描述】:

我想像开机重启一样重启 USB 调制解调器,而无需在 Linux 机器中物理重启和拔出它。 我试过做这个程序:

  • echo -n 0 > /sys/devices/platform/omap/ti81xx-usbss/musb-hdrc.0/usb1/bConfigurationValue
  • echo -n 1 > /sys/devices/platform/omap/ti81xx-usbss/musb-hdrc.0/usb1/bConfigurationValue

但我只能断开它,但第二个命令失败了。给出以下打印:

hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
usb 1-1: new full speed USB device using musb-hdrc and address 4
usb 1-1: device descriptor read/64, error -19
usb 1-1: device descriptor read/64, error -19
usb 1-1: new full speed USB device using musb-hdrc and address 5
usb 1-1: device descriptor read/64, error -19
usb 1-1: device descriptor read/64, error -19
usb 1-1: new full speed USB device using musb-hdrc and address 6
usb 1-1: device not accepting address 6, error -19
usb 1-1: new full speed USB device using musb-hdrc and address 7
usb 1-1: device not accepting address 7, error -19
hub 1-0:1.0: unable to enumerate USB device on port 1

有什么方法可以使这个重置过程自动化。这样,如果我 insmod 一个模块,它应该注册 USB 设备,当我 rmmod 一个模块时,它应该断开 USB 设备。

有没有这样的模块?

【问题讨论】:

  • “重置”是什么意思?这似乎是与“断开/重新连接”不同的问题,并且可能将重新启动设备称为上电复位、断开远程连接或重新枚举 USB 设备。您实际上要检索什么?我的答案是切换 DTR;但我不确定你在问什么。
  • 感谢您的回复。我的意思是重新启动 USB 调制解调器/端口,例如上电复位。无需重启,无需拔下设备。
  • 这与嵌入式系统有什么关系?
  • 您应该通过编辑问题而不是评论来澄清问题。但是,您的评论并不清楚;看起来像一个 XY 问题——你可能已经为你的实际问题发明了一个解决方案,并使问题成为如何实现你的解决方案的一个问题;询问真正的问题。

标签: linux embedded usb linux-device-driver embedded-linux


【解决方案1】:

这与您希望以管理方式关闭/不关闭接口的任何其他接口类似。

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>

void main(int argc, char **argv)
{
    const char *filename;
    int fd;

     filename = argv[1];
    fd = open(filename, O_WRONLY);
    ioctl(fd, USBDEVFS_RESET, 0);
    close(fd);
    return;
}

编译代码:

$ gcc -o usb-reset usb-reset.c

我已将 Arduino 连接到我的 ubuntu 机器 /dev/ttyACM0,我将尝试通过以下方式重置 Arduino:

sudo ./usb-reset /dev/ttyACM0

这会重置电路板!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    相关资源
    最近更新 更多