views:

460

answers:

2

I have an arduino-based device which connects through USB.

I'd like to detect it from my Qt4 application, using QExtSerialPort (or whatever necessary), when it's plugged in.

If this weren't possible, I thought I could somehow get a list of the system's port names and just try all of them in search for my arduino (where I'd implement some kind of handshaking procedure for it to detect it correctly). My concern in this approach is that I'm not sure if a device (e.g. printer) would get damaged if I send some kind of handshaking ack at a different baud rate.

So, I don't really know where to start for any of them. Which would be the best approach? Any ideas on how to implement it?

+2  A: 

I believe you can find list of serial ports on Windows by looking into

HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM

registry key

Each serial port on a UNIX system has one or more device files (files in the /dev directory) associated with it:

System           Port 1           Port 2
IRIX®            /dev/ttyf1       /dev/ttyf2
HP-UX            /dev/tty1p0      /dev/tty2p0
Solaris®/SunOS®  /dev/ttya        /dev/ttyb
Linux®           /dev/ttyS0       /dev/ttyS1
Digital UNIX®    /dev/tty01       /dev/tty02

more details on serial programing on POSIX systems here

serge_gubenko
+1  A: 

Since your device is USB, your UART port will be emulated by some kind of conversor in his hardware. So first you must understand what driver is being used on your system.

The most common SERIAL->USB conversor uses PL2303/PL2301 chip, so it would create a path on /dev, if its the first device, it will appear as "/dev/ttyUSB0", but you may also see the list reading the proc path (like "cat /proc/bus/usb/devices"). Under Windows it usually creates a virtual "COM", just go to device manager and check the port.

When you are sure about how the HW talks to your system, you may use QExtSerialPort for wrapping the system API and talk to the device.

Douglas Gemignani