USB Communication Using Qt
Page |
1 |
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)
56 replies
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.html
You 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 [waitingforfriday.com]
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….
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 [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.
Could you not use QExtSerialPort to simply list the available ports, instead of guessing their names?
Not that I am aware off. Probably, you have to do it brute force by checking all com ports.
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.
That gives me something to chew on…
Thanks for your valuable responses
Could you not use QExtSerialPort to simply list the available ports, instead of guessing their names?Not that I am aware off. Probably, you have to do it brute force by checking all com ports.
There is an enumerator in the source code: http://qextserialport.cvs.sourceforge.net/viewvc/qextserialport/qextserialport/
You must log in to post a reply. Not a member yet? Register here!





