我正在使用与CAN总线适配器通信的应用程序。运行应用程序的平板电脑使用特殊电缆进入对接模式,以便在充电时充当USB主机。
我的问题是,即使适配器仍然连接,我也会随机收到UsbManager.ACTION_USB_DEVICE_DETACHED。我收到消息后,我现在有一个粗略的方法来重新连接,这是命中或未命中。我偶尔可以重新连接的事实让我相信软件问题正在导致广播。电缆有可能坏了,但我想先排除软件。
会导致播放UsbManager.ACTION_USB_DEVICE_DETACHED的可能情况有哪些?
仅在设备物理断开连接或是否存在与其他软件相关的情况下才会出现"分离"?
如果有多种情况,是否有办法可以获得有关每个断开连接的更多信息(即原因),以便我可以优雅地从中恢复?
编辑:这是来自dmesg的日志
<6>[ 113.721018] c1 max77693_chgin_isr_work: irq(436), chgin(0x3), prev 0x3
<6>[ 113.722357] c0 max77693_irq_thread: interrupt source(0x01)
<6>[ 113.722859] c0 max77693_irq_thread: charger interrupt(0x40)
<7>[ 114.337320] c0 hub 2-0:1.0: state 7 ports 3 chg 0000 evt 0002
<7>[ 114.337361] c0 s5p-ohci s5p-ohci: GetStatus roothub.portstatus [0] = 0x00020101 PESC PPS CCS
<7>[ 114.337399] c0 hub 2-0:1.0: port 1 enable change, status 00000101
<3>[ 114.337430] c0 hub 2-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
<7>[ 114.337461] c0 hub 2-0:1.0: port 1, status 0101, change 0002, 12 Mb/s
<6>[ 114.337498] c0 usb 2-1: USB disconnect, device number 2 by hub_thread+0x4a8/0x1468
<6>[ 114.337532] c0 call_battery_notify : VID : 0x403, PID : 0xffa8 set 1700mA.
<3>[ 114.337568] c0 set_online: fail to get max77693-charger psy
<7>[ 114.337594] c0 usb 2-1: unregistering device
<7>[ 114.337615] c0 usb 2-1: unregistering interface 2-1:1.0
<7>[ 114.337738] c0 s5p-ohci s5p-ohci: shutdown urb eaf51200 ep1in-bulk
<7>[ 114.338083] c0 s5p-ohci s5p-ohci: urb eaf51200 path 1 ep1in 5cd20000 cc 5 --> status -62
<7>[ 114.338499] c0 usb 2-1: usb_disable_device nuking all URBs
<7>[ 114.460048] c0 hub 2-0:1.0: debounce: port 1: total 100ms stable 100ms status 0x101
<7>[ 114.575052] c0 s5p-ohci s5p-ohci: GetStatus roothub.portstatus [0] = 0x00100103 PRSC PPS PES CCS
<6>[ 114.630056] c0 usb 2-1: new full speed USB device number 3 using s5p-ohci
<7>[ 114.745061] c0 s5p-ohci s5p-ohci: GetStatus roothub.portstatus [0] = 0x00100103 PRSC PPS PES CCS
<7>[ 114.820051] c0 usb 2-1: ep0 maxpacket = 8
<7>[ 114.833106] c0 usb 2-1: default language 0x0409
<7>[ 114.842116] c0 usb 2-1: udev 3, busnum 2, minor = 130
<6>[ 114.842148] c0 usb 2-1: New USB device found, idVendor=0403, idProduct=ffa8
<6>[ 114.842186] c0 usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
<6>[ 114.842225] c0 usb 2-1: Product: CANUSB
<6>[ 114.842248] c0 usb 2-1: Manufacturer: LAWICEL
<6>[ 114.842274] c0 usb 2-1: SerialNumber: LWWULFZR
<6>[ 114.842302] c0 call_battery_notify : VID : 0x403, PID : 0xffa8 no action.
<7>[ 114.843022] c0 usb 2-1: usb_probe_device
<7>[ 114.843058] c0 usb 2-1: configuration #1 chosen from 1 choice
<7>[ 114.844126] c0 usb 2-1: adding 2-1:1.0 (config #1, interface 0)
<7>[ 114.848315] c0 drivers/usb/core/inode.c: creating file '003'
<7>[ 114.848467] c0 hub 2-0:1.0: state 7 ports 3 chg 0000 evt 0002
<6>[ 114.876895] c0 max77693_chgin_isr_work: irq(436), chgin(0x3), prev 0x3
<6>[ 114.878316] c0 max77693_irq_thread: interrupt source(0x01)
<6>[ 114.878828] c0 max77693_irq_thread: charger interrupt(0x40)
<6>[ 116.036672] c0 max77693_chgin_isr_work: irq(436), chgin(0x3), prev 0x3
<3>[ 116.775239] c0 [HOTPLUG OUT] check_down 200000<=200000 && 327<200
<3>[ 116.775412] c0 CPU_DOWN 1
<5>[ 116.777995] c0 CPU1: shutdown
<3>[ 121.490462] c0 [HOTPLUG IN] check_up 300000>=500000 && 152>200
<3>[ 121.490542] c0 CPU_UP 3
<4>[ 121.506612] c1 CPU1: Booted secondary processor
<6>[ 121.506753] c1 notifier_call_chain : NOTIFY BAD tick_notify
<6>[ 121.510069] c1 Switched to NOHz mode on CPU #1
<3>[ 126.980185] c0 [HOTPLUG OUT] check_down 200000<=200000 && 540<200
<3>[ 126.980313] c0 CPU_DOWN 1
<5>[ 126.983628] c0 CPU1: shutdown
答案 0 :(得分:0)
感谢Chris,我通过dmesg
运行adb shell
来解答所有问题。
“会导致UsbManager.ACTION_USB_DEVICE_DETACHED被广播的可能场景是什么?是仅在设备物理断开连接或是否存在与其他软件相关的”分离“时?”
物理拔出USB电缆会导致播放UsbManager.ACTION_USB_DEVICE_DETACHED消息,但这不是唯一原因。如果USB端口复位,也可以广播该消息,如果线路上有太多噪音(EMI),就会发生这种情况:
<3>[ 114.337430] c0 hub 2-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
“如果有多种情况,是否有办法可以获得有关每个断开连接的更多信息(即原因),以便我可以优雅地从中恢复?”
在收到广播后从dmesg
运行adb shell
以确定断开连接的根本原因。在这种情况下,我的电缆容易受到噪音的影响,导致端口被禁用然后重新启用。我的解决方案是在我修改它的位置屏蔽电缆。