如何检测插入的USB [英] How to detect inserted USB

查看:39
本文介绍了如何检测插入的USB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开发的基于 ARM 的嵌入式系统上运行的 Qt 应用程序中,我必须检测 USB 随身碟 何时插入以及它包含什么,因为我想显示包含Windows 上的文件,并允许用户选择其中之一.为了我必须:

In Qt Application I've developed to run on an embedded ARM-based system, I have to detect when USB pendrive has been inserted and what it contains, since I'd like to show contained files on a windows and allow the user to choice one of them. In order I have to:

  1. 检测USB何时插入;
  2. USB 识别;
  3. 其中包含的 USB 文件.

试着解释一下:我有一个文件要在外部设备中保存和恢复.它包含一些与我使用 Qt 为嵌入式系统(基于 ARM 微控制器)开发的应用程序相关的设置.我已经为 SD 卡完成了同样的工作,因为我确切地知道将打开什么样的设备、它的路径、它的名称等.如果我想使用 USB 随身碟做同样的事情,问题就存在,因为每个人都有自己的名字.因此,我首先不知道它的路径(我假设是/media/myusername",即插入 USB 时我在哪里找到它的),以及如何打开它.我开始使用 QFileSystemWatcher 库进行一些试验:我将 directoryChanged 信号连接到一个显示我文件夹的插槽.它有效,但还不足以进一步进行.有什么解决办法吗?

Try to explain: I have a file to save and restore in an external device. It contains some settings related to my app developed using Qt for an embedded system (based on ARM microcontroller). I'm already done tyhe same for SD card, because I know exactly what kind of device will be opened, its path, its name etc. Problem exist if I wanna do the same using a USB pendrive, since every one has its own name. Thus I don't know firstly its path (I supposed "/media/myusername", i.e. where I found my USB when it's inserted), and how to open it. I'm starting making some trials using the QFileSystemWatcher library: I connect the directoryChanged Signal to a slot that shows me folder. It works, but it's not enough to proceed further. Any solution?

如何做到这一点?

推荐答案

udev 使用 udevadm (udevadm monitor | grep ...) , libudevudev 规则

the normal way to get notification about attached usb devices is over udev either using udevadm (udevadm monitor | grep ...) , libudev or udev rules

http://www.signal11.us/oss/udev/

https://unix.stackexchange.com/questions/116536/usb-连接断开通知

可以 linux 信号连接特定 USB 设备时我的 Qt 程序?

https://askubuntu.com/questions/27948/usb-device-changes-using-udev-and-d-bus

HAL 在 linux 中已弃用... http://madison-project.wdfiles.com/local--files/tutorials/Hal_Tutorial.pdflinux 热插拔

这篇关于如何检测插入的USB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆