USBDemo, something to learn USB a little bit


Closed Thread
Results 1 to 40 of 279

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I can't speak for Visual Basic, but in Delphi, you request a list of HID devices, and each one has it's own "Handle".

    If two devices have the same Vendor/Product ID's then you look for the serial number to tell the difference. But access to the device is by specifying the Handle.

    Here's a small program that can identify the serial number and handle. Note: the handle changes on every connection or power-up/re-boot.

    www.pbpgroup.com/files/HIDmonitor.exe
    Put it anywhere, there is no installation to do.
    <br>
    DT

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    same rules apply with any language, look at the mcHID API reference. But seems NOBODY want to use the serial number... no matter why they suffer

    Nice utility Darrel!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    ... But seems NOBODY want to use the serial number...
    Well, if there was an easy way to do it, it might look more attractive.
    Running EasyHID or manually editing the descriptor file each time doesn't seem like an option.

    Maybe there's a way to have the descriptor file read the Hardware Serial number, then have the programmer auto-increment the serial number, ... but it doesn't currently have that feature.

    Other than that, since you can find the handle of each device with the same Vendor/Product ID, within your software you can create a Challenge/Response type arrangement that will let the computer assign a unique number to any new devices on the BUS.

    Nice utility Darrel!
    Thanks Steve,

    It's come in handy a few times troubleshooting USB connections.
    Thought I'd spruce it up and pass it on.
    <br>
    DT

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    On another forum someone already Suggest USBDeview. I use it a lot, it's a real nice utility ...
    http://www.nirsoft.net/utils/usb_devices_view.html

    They also have bunch of other nice freebies over there...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    All good info.

    But thanks for trumping my puny efforts.
    <br>
    DT

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    well... when you did that utility... wasn't it to learn something ?

    And i'm sorry... i thought i posted that link before.. oops!

    It's still a nice utility you've made so far!
    Last edited by mister_e; - 1st December 2007 at 02:01.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Excellent point! That's exactly what it was.

    That program started from my attempt at modifying the USBDemo program from VB to Delphi.

    It's based on the Delphi routines supplied by David Barker in the EasyHID results.

    It's only right that I posted it here,... along with the reason I even know about USB. (USBDemo)


    <br>
    DT

  8. #8


    Did you find this post helpful? Yes | No

    Default So much help!

    Quote Originally Posted by Darrel Taylor View Post
    Other than that, since you can find the handle of each device with the same Vendor/Product ID, within your software you can create a Challenge/Response type arrangement that will let the computer assign a unique number to any new devices on the BUS.
    Ok i will use Darrelīs exe program.

    I know it will not be exactly the same for VB but if there is any chance that you could post the source code i would finally see how itīs done!

    I am sure i can do with just the handler, i could also identify wich device was connected first and have a record of devices....

    This would be a great place to begin

    Thanks for your replies

    DJC

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Josuetas
    Ok i will use Darrelīs exe program.
    Thank You!<hr>
    Looking at the VB side of USBDemo
    Code:
    Public Sub OnPlugged(ByVal pHandle As Long)
        '
        '   A HID device has been plugged in,
        '   check if it's the right one, and enable the form LED (top left)
        '
        Dim DeviceHandle As Long
        Dim VendorName As String * 15
        Dim ProductName As String * 15
        
        If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then ' Good one?
            '
            '   get the device handle
            '   =====================
            DeviceHandle = hidGetHandle(VendorID, ProductID)
            '
            '   Get the vendor and product name from the handle
            '   ===============================================
            hidGetVendorName DeviceHandle, VendorName, 255
            hidGetProductName DeviceHandle, ProductName, 255
            '
            '   Enable the LED and display device information
            '   VendorName and ProductName
            '   =============================================
            imgON.Visible = True
            lVendorName.Caption = VendorName
            lProductName.Caption = ProductName
            End If
    End Sub
    Using the line shown in red, anytime a device is plugged in with the same Vendor/Product ID, it will forget about the last device and start using the new one.

    To get around that, you need to check further to make sure it's the device you want to talk to. And, for that, you need to search through the HID Device list.

    Again, I don't do VB, so the syntax is most probably wrong. But ...<hr>
    The function hidGetItemCount returns the number of HID devices in the List.
    Then hidGetItem(Index) returns the handle of the item in the list that's specified by Index (0 to count-1).

    You can get the info about that device by requesting each field.
    Vendor = hidGetVendorID(handle)
    Product = hidGetProductID(handle)
    Serial = hidGetSerialNumber(handle)

    Now if everything matches, you know you have the right one. If not, keep searching through the list.

    If you're not using the Serial Number, you'll need to send/receive something to the device to figure out if it's the correct one.

    Is that any help?
    I'll keep trying if not.
    <br>
    Last edited by Darrel Taylor; - 2nd December 2007 at 00:18. Reason: added "hid" to function names
    DT

  10. #10
    Join Date
    Dec 2007
    Location
    Denmark
    Posts
    28


    Did you find this post helpful? Yes | No

    Default hey

    Steve, do I need the 18f4550 or any other USB pic for your USB project? or can I do it with a standard pic, like the 18f452?

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Atwoz, only USB PIC will work!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Thumbs up HIDmonitor.exe

    Quote Originally Posted by Darrel Taylor View Post

    www.pbpgroup.com/files/HIDmonitor.exe
    Put it anywhere, there is no installation to do.
    <br>
    Very handy little utility. Thank you very much Darrel.
    Regards,
    ozion

  13. #13
    Join Date
    Aug 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    i want to use usbdemo to count rpm of motor and display the rpm in computer. how to do that?

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Begin small, begin by finding a way to count the RPM, show it on a lcd or via a serial communication... once you have it done, port your to code to USBDemo.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Aug 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    i use 8 slot encoder.
    after googling few minutes. i add this code into usbdemo
    Code:
         COUNT PORTA.2,100,speed
         speed = speed * 10 * 60 / 8
         rpm[0] = speed / 1000 // 10
         rpm[1] = speed / 100 // 10
         rpm[2] = speed / 10 // 10
         rpm[3] = speed // 10
         rpm[4] = 0
         rpm[5] = 0
         rpm[6] = 1
         rpm[7] = 1
         
    @   SendUSB _rpm

  16. #16
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    With the release of PBP version 2.60, mister-e's USBdemo (or any other program derived from EasyHID) will no longer compile (without some changes).

    The new way of doing USB with PBP is really nice.
    So here's a modification to Steve's program that will allow it to be compiled with PBP 2.60, and hopefully show how much easier it is to do USB.<hr>
    . If you haven't already ... download and extract the USBDemo from the beginning of this thread.

    . Then create a new folder (USBDemo260) and copy the USBDemo.pbp file from Steve's archive into the new folder.
    That is the only file that is valid with 2.60, so don't copy any of the others.

    . Download the USBDEMOdesc.bas.txt (descriptor) file attached to this post and place it in the same folder. Remove the .txt extension.

    . In the USB18 folder, inside your PBP folder ...
    Copy the following files to the project ...

    usb_dev.asm
    usb_dev.inc
    usb_hid.asm
    usb_hid.inc
    usb_mem.asm


    . Add this line to the USBDemo.PBP program ... and compile.
    Code:
      INCLUDE "USBDEMOdesc.bas"
    And away you go, with a little Ding-Dong ... Or maybe a Dong-Ding. <hr>
    Make sure you change the configs if you're not using a 4Mhz crystal.
    And comment out the UCFG EXT variable since it's not needed anymore.

    The Visual Basic part of mister-e's demo is the same.
    You can use the pre-compiled program, or modify it as desired.
    Attached Files Attached Files
    DT

  17. #17
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default One statement causes compile error

    Quote Originally Posted by Darrel Taylor View Post
    . If you haven't already ... download and extract the USBDemo from the beginning of this thread.

    . Then create a new folder (USBDemo260) and copy the USBDemo.pbp file from Steve's archive into the new folder.
    That is the only file that is valid with 2.60, so don't copy any of the others.

    . Download the USBDEMOdesc.bas.txt (descriptor) file attached to this post and place it in the same folder. Remove the .txt extension.

    . In the USB18 folder, inside your PBP folder ...
    Copy the following files to the project ...

    usb_dev.asm
    usb_dev.inc
    usb_hid.asm
    usb_hid.inc
    usb_mem.asm


    . Add this line to the USBDemo.PBP program ... and compile.
    Code:
      INCLUDE "USBDEMOdesc.bas"
    Darrel, I followed steps you listed explicitly and then tried to compile with PBP 2.6. Got the following error:
    " ERROR line 81: Redefinition of VAR. USBDemo.pbp]"
    which I don't understand since the UCFG variable is not declared anywhere else in the code...just this line where the code occurs.
    The error applies to the statement
    "UCFG VAR BYTE EXT ' include UCFG register... Yeah Melabs didn't ("

    I went to manual on 2.6 compiler to check syntax of this statement. I guess I don't understand the use of EXT at the end of the statement....manual doesn't explain that.

    Can you tell me what might be wrong and why this won't compile?? I would really like to get this USBDemo going for my 18F4550.

    Also don't understand why Steve's schematic that you posted varies from the hardware description in the USBDemo260 code:
    Here is the Hardware description from the code:
    Hardware:
    ' ---------
    ' 4 Push Buttons on PORTA<5:2> with pull-down resistors
    ' 2 Trim pot on PORTA<1:0>
    ' 8 LEDs attach between PORTB and GND
    ' 2 LEDs attach to CCP<2:1> pins
    ' 4 MHZ crystal & all the usual USB stuff
    Yet the schematic shows no pushbuttons on PORTA <5:2>, no trim pota on PORTA <1:0>, no LEDS on PORTB or CCP, and a 20 MHz crystal rather than 4 MHz. Can you advise me of the correct hardware hookups for the USBDemo260 code...the schematic or the code description??

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 11:38
  3. Replies: 9
    Last Post: - 31st July 2008, 09:56
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 01:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts