سؤال

I would like to launch a program automatically when I connect my arduino hardware into my laptop.

I know it is kind of possible because that's the way Itunes works when i connect my ipod.

Sorry if my question is too broad, but it's because of my lacks of acknowledgment of USB technology and driver development. I will clarify my question according to the answers.

I have found a topic with dmesg (http://www.freebsd.org/doc/handbook/usb-disks.html), but on my Mac OSX, the response is not the same as the example (I have a lot of code signing error and there's lot of output informations). So I'm assuming that's depending of the OS.

What my question is about is if there is a standardized way to detect an USB port, or if it is OS dependent (my question is for unix family only).

For the moment, the solution I have found is to take a cron and scan the tty. file and check if it can respond to my signal, and if it can, I launch my program. But that is really a dirty agressive solution.

I haven't any clear documentation about it. But that only because I don't know where to find the documentation. I know that usbconfig can give information about a device, but it's not pre installed into mac machine.

So, does the kernel can provide signals when an hardware is connected? Where should I provide the information of my hardware to the computer? Is it OS specific? And where I can find the documentation for what I want (i haven't found a clear way for a research) ?

Help will be greatly appreciated. Thank you for the response!

هل كانت مفيدة؟

المحلول

Unfortunately USB device notifications are OS-specific. There is no official standard with regard to this issue, therefore each implementation is different, even among the various Unix-like systems.

On Linux the kernel notifies the udev daemon via (IIRC) an open netlink socket, and then udev may use a variety of method to notify the rest of the userspace. I believe FreeBSD uses devd for the same purpose - I expect that OS X will have its own method to do this as well.

You might be able to build a cross-platform solution using the device enumeration facilities in libusb. It is cross-platform and had bindings for several programming languages, so you should be able to whip-up a little daemon to do this...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top