AnsweredAssumed Answered

Use sysfs to detect if a usb device is connected/disconnected?

Question asked by Mercy Yuen on Mar 21, 2014
Latest reply on Mar 24, 2014 by Victor Linnik

I'm running a imx6qsabresd board.  whenever I plug in a usb device, I can see the message on the terminal:

usb 2-1: new low speed USB device number 3 using fsl-ehci
input: Microsoft Basic Optical Mouse as /devices/platform/fsl-ehci.1/usb2/2-1/2-1:1.0/input/input3
generic-usb 0003:045E:0084.0002: input,hidraw0: USB HID v1.10 Mouse [Microsoft Basic Optical Mouse] on usb-fsl-ehci.1-1/input0


when I disconnect, I see the message:

usb 2-1: USB disconnect, device number 3


I want to figure out a way to check the usb device is connected.

 

I thought I could do something simple like

file *fp = fopen("/sys/devices/platform/fsl-ehci.1/usb2/2-1/2-1:1.0/input/input3","r");

if(fp)

  printf("found USB2\n");

else

  printf("didn't find USB2\n");

 

But this code doesn't work. I always get the output "didn't find USB2"

 

could someone please give me some suggestions?  Please don't tell me to try using libudev.  It does not work on this compiler because of:  libudev.h: No such file or directory

 

Thanks in advance!

Outcomes