Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way in linux to get usb device added notifications in c

Tags:

c

linux

usb

what Linux library should i use to get asynchronous notifications of added usb devices? I'd like my program to work on any Linux device so I'll need to use a library that isn't specific to one Linux version

like image 943
rjs Avatar asked Mar 27 '12 14:03

rjs


People also ask

How do I enable USB notifications?

Depending on your Android version, you must do either of the following: Drag down the status bar, tap Connected as <connection type> under Notifications, and select Camera (PTP). Go to Settings > Storage > Menu > USB computer connection, and select Camera (PTP).

Which command displays the list of recognized USB devices?

Enter the following command: Get-PnpDevice -PresentOnly | Where-Object { $_. InstanceId -match '^USB' } . That command will show a list of all present USB devices.

How does Linux handle USB devices?

The Linux kernel supports two main types of USB drivers: drivers on a host system and drivers on a device. The USB drivers for a host system control the USB devices that are plugged into it, from the host's point of view (a common USB host is a desktop computer.)


2 Answers

If you are using 'C' then I would suggest using the notification features of libudev. Here is a good link with example 'C' code.

libudev Document

Hope that helps.

--Jim

like image 143
Chimera Avatar answered Nov 11 '22 09:11

Chimera


You need to include what language you are using before we can talk libraries, but if you want to just hook into a shell and parse infos you can use udevadm. You also will have to consider user mode, versus kernel mode, and you will most likely have to run your program or in kernel mode to be able to listen for this type of event.

like image 30
wachpwnski Avatar answered Nov 11 '22 11:11

wachpwnski