Page 1 of 3 123 LastLast
Results 1 to 20 of 47

Thread: Windows USB example

  1. #1
    Join Date
    Mar 2011
    Location
    Italy
    Posts
    5
    Thanks
    1
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Windows USB example

    This program is an example of how to use an USB device in Qt.
    It is limited only to the HID devices class (joystick, mouse, keyboard...)
    It uses the standard Microsoft HID driver. If you use another driver you must know how it works.
    It demonstrates how to:
    -recognize a device by VID&PID
    -read/write
    -attach/detach notification
    Two examples are provided:
    -first example reads the XY position of a joystick
    -second example sends a message to the device and waits for the answer.

    See comments in source for details.

    Licence: GPL.

    I hope that this program can be useful to someone.
    Attached Files Attached Files

  2. The following 4 users say thank you to gavagai for this useful post:

    ASUKA_521 (25th March 2012), baetaekwon (19th February 2013), caodungviet (28th April 2011), Gamer (12th October 2013)

  3. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Windows USB example

    Excellent!
    It might be a good idea if you'd add it to the examples section in the wiki, here it gets lost among the many other threads...
    http://www.qtcentre.org/wiki/index.p...egory:Examples
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Windows USB example

    I don't like the idea of using global variables. And threads access those variables without a proper protection. This is bound to blow up sooner or later.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Windows USB example

    I haven't looked at the code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows USB example

    When you say:

    Qt Code:
    1. //to find a better way for this...
    2. while(lpdbv->dbcc_name[i] != 0)
    3. {
    4. s.append(lpdbv->dbcc_name[i]);
    5. i++;
    6. }
    7. s = s.toUpper();
    To copy to clipboard, switch view to plain text mode 

    Have you tried:

    Qt Code:
    1. QString s = QString::fromWCharArray(lpdbv->dbcc_name).toUpper();
    To copy to clipboard, switch view to plain text mode 

    Don't know if it'll work, it's just something that sprung into mind when I read your code/comment.

  7. The following user says thank you to squidge for this useful post:

    gavagai (25th March 2011)

  8. #6
    Join Date
    Mar 2011
    Location
    Italy
    Posts
    5
    Thanks
    1
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows USB example

    hi squidge,
    thanks for your suggestion. Yes, it works!
    I had not seen this static function to convert wchar_t in QString.
    Thanks again.

  9. #7
    Join Date
    Jul 2010
    Location
    Ahmedabad,Gujarat,India
    Posts
    25
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Windows USB example

    Thanks for Share awesome Example for USB Communication...
    but i have problem to devide...... The "Device Class GUID" is {6bdd1fc6-810f-11d0-bec7-08002be2092f}
    can u please explain me more.

    i'll try this type #define HID_CLASSGUID {0x6bdd1fc6, 0x810f, 0x11d0,{ 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f }}
    but result is same not connected ....

    please help me, i m waiting for u r kindly reply...
    thanks in advance.

  10. #8
    Join Date
    Mar 2011
    Location
    Italy
    Posts
    5
    Thanks
    1
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows USB example

    Don't use the class GUID returned by device manager, it don't works. It is the device SETUP GUID class. We need the device INTERFACE GUID class (see http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx).
    Try this:
    - be sure that your device is installed and recognized in the system
    - start regedit and search for your vid&pid (VID_XXXX&PID_XXXX) in the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\DeviceClasses. You can get more of a result.
    - Try to use the parent class GUID where the descriptor starts with the type of device (##?#HID#VID... or ##?#IMAGE#VID...).
    For more informations see the examples in http://msdn.microsoft.com/en-us/library/ff551069.aspx

    Your device seems to be an image device. I do not know if endpoint size (InputBuffer and OutputBuffer size) is correct for this device. Depends on the driver.

    Good luck

  11. The following user says thank you to gavagai for this useful post:

    pavanbarot (1st April 2011)

  12. #9
    Join Date
    Jul 2010
    Location
    Ahmedabad,Gujarat,India
    Posts
    25
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Thumbs up Re: Windows USB example

    Thanks a lot it's works fine....
    Attached Images Attached Images

  13. #10
    Join Date
    Mar 2011
    Location
    Italy
    Posts
    5
    Thanks
    1
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows USB example

    ok, it works but I think it is not exactly correct.
    Your image shows a generic class GUID for all USB devices (##?# USB VID # ...).
    Better to use a GUID for a specific class of devices.
    Search again to find something like # #? # IMAGE # VID_XXXX&PID_XXXX and uses its GUID.
    Maybe I'm wrong, but I think for read / write operations you must use a more specific GUID.

  14. #11
    Join Date
    Mar 2011
    Location
    Bangalore
    Posts
    3

    Default Re: Windows USB example

    I am new member to this forum. So this information is useful for me. I will try this.

  15. #12
    Join Date
    Mar 2011
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows USB example

    sorry but i don't understand about The "Device Class GUID", please you help me?? for example,
    #define HID_CLASSGUID {0x6bdd1fc6, 0x810f, 0x11d0,{ 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f }}
    so :{ 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f }.what is it??
    please explain for me,i don't understand about it. what it means?? sorry ,because my english is not good

  16. #13
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows USB example

    They are device class GUIDs used in device detection and classification. See the Windows DDK for more information and other GUIDs.

  17. #14
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows USB example

    Hi all.
    And why different descriptors for reading and writing device?
    (You can also open once a one descriptor for reading and writing!)

  18. #15
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows USB example

    Quote Originally Posted by kuzulis View Post
    Hi all.
    And why different descriptors for reading and writing device?
    (You can also open once a one descriptor for reading and writing!)
    You can but that will not work across all devices. Some devices for example are read-only, so if you try to open them as read/write the call will fail, but if you have seperate read and write only the write will fail, so you know the device is read-only and don't need to do additional work (such as reopening as read only and setting a read-only flag). Typically however you will know this before writing code but as an example it is impossible to know this in advance.

  19. #16
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Windows USB example

    aah, I understand, thank you.

  20. #17
    Join Date
    Mar 2011
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows USB example

    i can conect with USB, but when i open it ,so my computer is broke dow,, why such that??

  21. #18
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows USB example

    Please rephrase. Don't understand.

  22. #19
    Join Date
    Mar 2011
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows USB example

    sorry, because my english is not good..i can connect this project with USB,but when i open this project ,my computer can't run.
    please help me!!

  23. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Windows USB example

    You mean it reboots?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  24. The following 2 users say thank you to wysota for this useful post:

    caodungviet (28th April 2011), Gamer (12th October 2013)

Similar Threads

  1. Replies: 2
    Last Post: 6th September 2010, 15:22
  2. Replies: 3
    Last Post: 12th July 2010, 07:25
  3. Program runs on Windows 7, crashes on Windows XP
    By JovianGhost in forum General Programming
    Replies: 8
    Last Post: 7th June 2010, 01:55
  4. Deployment Procedure On Windows On Linux and Windows
    By Harshith J.V. in forum Installation and Deployment
    Replies: 4
    Last Post: 9th July 2009, 12:27
  5. Replies: 10
    Last Post: 25th February 2007, 01:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.