USB Communication Using Qt
-
I am starting on a project that requires information to be transmitted between a linux / windows based desktop PC and an external microcontroller circuit. The ideal would be to use USB but I am unable to find any information or book explaining in detail how to communicate with the PC's USB ports from my Qt application. I really like Qt for it's GUI design but it wouldn't be of any use starting the project using Qt if I cannot find any information on this crucial requirement. Can someone indicate if this is possible with a reference to a good book or link to a website or suggest a different (C++) approach? (The microcontroller part is not a problem)
-
Some useful links that might help that I have found so far:
http://www.microchip.com/forums/m340892.aspx
http://libusb.sourceforge.net/api-1.0/index.htmlYou may need to piece together the info you need from the microchip thread on how to use libusb with Qt but it seems to be informative.
-
Dear Candiman,
you might want to have a look at "Waiting for Friday":http://www.waitingforfriday.com/index.php/Building_a_PIC18F_USB_device
You'll find an example, containing hardware based on a Pic 18f4550 (cheap and free if you ask microchip for samples), firmware code (using a free as "free-beer" compiler), a base class to help you deal with the USB communication and a full visual application sample.
From my point of view, should be fairly easy to hide your internal communication in usb in a few classes, then provide a nice shell object with signals and slots to deal with your hardware.
This way, you split nicely the code and you can easily test your UI without bothering with hardware (and test your hardware without bothering with UI ;) ) Of course, the HW communication layer will most-probably be platform specific whereas your UI will be generic. You could even think of using plugins to extend the functionality of your UI with HW... I have had a similar project in mind for quite a while, just can't find time to start it.... -
USB and other hardware peripheral communication means (excepting networking) are not part of the Qt modules, as far as I know. Best course of action would be to go for some cross platform library (e.g. libusb, which you already found) and use that in your Qt program.
-
Hi Candyman,
there can be found some source code based on Qt for serial connections. You will across a couple of derivatives obviously orginating from the same starting point.
"See for instance":http://qextserialport.sourceforge.net/
It can be used with USB-serial (PC-device). What the differences for USB-USB are, I am blank. Would be great to know, how to do it. -
Yes we use the usb-serial approach by way of an FT-245 convertor chip on the comms side of our devices. This just marshalls between usb and standard RS-232 comms which allows us to use qextserialport on /dev/ttyUSB0 or COM1 for e.g. Without such a chip, libusb is the way to go but Qt can still be used for other aspects of the application though.
-
/dev/ttyUSB0 is simply the name that the kernel (or udev or whatever else you are using) assigns to serial over USB devices ie when using a usb-serial convertor. So when using this type of device under windows the corresponding device is COM1.
If you are not using a usb-serial convertor then you have to use the libusb functionality for communicating - that is you cannot simply use COM1 etc.
-
[quote author="Andre" date="1303983404"]Could you not use QExtSerialPort to simply list the available ports, instead of guessing their names?[/quote]
Not that I am aware off. Probably, you have to do it brute force by checking all com ports.
[quote author="ZapB" date="1303983794"]If you are not using a usb-serial convertor then you have to use the libusb functionality for communicating - that is you cannot simply use COM1 etc.[/quote]
That gives me something to chew on...
Thanks for your valuable responses
-
[quote author="koahnig" date="1303984402"]
[quote author="Andre" date="1303983404"]Could you not use QExtSerialPort to simply list the available ports, instead of guessing their names?[/quote]Not that I am aware off. Probably, you have to do it brute force by checking all com ports.
[/quote]
There is an enumerator in the source code: http://qextserialport.cvs.sourceforge.net/viewvc/qextserialport/qextserialport/
-
[quote author="Andre" date="1303985184"]
There is an enumerator in the source code: http://qextserialport.cvs.sourceforge.net/viewvc/qextserialport/qextserialport/
[/quote]you mean the enum on NamingConvention ?
I did not come across this yet. But it is nowherelse referenced. So it could be dead source. -
I mean this class: http://qextserialport.cvs.sourceforge.net/viewvc/qextserialport/qextserialport/qextserialenumerator.h?revision=1.3&view=markup
Sure, old code, and not in the docs, but the code is there...
-
BTW the sourceforge project is no longer active. The new home is "here":http://code.google.com/p/qextserialport/