USBDemo, something to learn USB a little bit


Results 1 to 40 of 279

Threaded View

  1. #11
    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

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