USB Hid communication in VB6 (Visual Basic 6)

General discussion on mikroC PRO for PIC.
Author
Message
stevencovert
Posts: 247
Joined: 19 May 2009 21:46
Location: Virginia, USA

Re: USB Hid communication in VB6 (Visual Basic 6)

#16 Post by stevencovert » 29 Sep 2010 19:15

I did a project also in VB6, uaing a shareware-based HID library for VB6 from Kadtronix (I think). Anyways, if you go to Microchip's site, you can download an applciation for your OWN USB VID... Its a subset of Microchips, and your limited to 10K units.. but you can have your own USB VID...

Steve
I like apple P=IE!

womai
Posts: 239
Joined: 16 Apr 2008 07:45

Re: USB Hid communication in VB6 (Visual Basic 6)

#17 Post by womai » 29 Sep 2010 22:31

Actually I was about to try the Kadtronix library (even had obtained the 1 month trial version) when I finally got Jan Axelson's code working (from which the projects I posted here are derived). My point here is now - why would I pay for the Kadtronix library when I have working VB6 code that is free... (there is no impact for maximum speed, as you can see my own code running on an old PC already achieves the theoretical maximum for HID). Even better, since the VB6 source code is published, everybody can tweak and customize it to his liking.

Wolfgang

melillo
Posts: 44
Joined: 13 Oct 2010 16:41
Location: Montreal, Quebec, Canada
Contact:

Re: USB Hid communication in VB6 (Visual Basic 6)

#18 Post by melillo » 13 Oct 2010 19:16

Hello everybody,

I am trying to do something similar, but in my case I want to use VisualC++ 6.0. It should be very easy: turn on a led and read a switch, via usb (hid) and a pic18f4550. The pic programming isn't done yet, but I'm confident that it will be easy with the examples on the mikroelektronica site. It's the computer side that bugs me. I found the following site: http://www.alanmacek.com/usb/ but I did not found all the files. Anybody ever did such a program in C++?

Thank you in advance
Marc

Dario.rijeka
Posts: 58
Joined: 23 Oct 2010 22:17

Re: USB Hid communication in VB6 (Visual Basic 6)

#19 Post by Dario.rijeka » 19 Aug 2011 16:56

Hi to all,

I'm working on project with18F2550 to read I button and send data by RS232, USB keyboard and USB HID, as well as to be possible to program parameters by hyperterminal and HID TERMINAL application.

so far I did everything except HID communication program. Idea is to use VB, but I did try your program but is not working with my USB unit.

herewith you can find my dsc file and please note that KBD is REPORT1, and HID is REPORT2. I cannot read data from unit with zour program example even it is work with Mikroelektronika HID example. The only difference is report ID which is stored in sendbuff(0), and for mikrolektronika example is 0 but for my unit is 2.

Anybody able to help?

Thanks,
Damir

Code: Select all

module USBdsctestBAsicMicro

const USB_VENDOR_ID as word = 0x1121
const USB_PRODUCT_ID as word = 0x0329
const USB_SELF_POWER as char = 0x80            ' Self powered 0xC0,  0x80 bus powered
const USB_MAX_POWER as char = 50               ' Bus power required in units of 2 mA
const HID_INPUT_REPORT_BYTES as char = 64
const HID_OUTPUT_REPORT_BYTES as char = 64
const EP_IN_INTERVAL as char = 1
const EP_OUT_INTERVAL as char = 1

const USB_INTERRUPT as char = 1               '1 if INTERRUPT IS USED   ===============================================================================
const USB_TRANSFER_TYPE as char = 0x03         '0x03 Interrupt
const USB_HID_EP as char = 1
const USB_HID_RPT_SIZE as char =100

structure device_descriptor

    dim bLength as char               ' bLength         - Descriptor size in bytes (12h)
    dim bDescriptorType as char       ' bDescriptorType - The constant DEVICE (01h)
    dim bcdUSB as word                ' bcdUSB          - USB specification release number (BCD)
    dim bDeviceClass as char          ' bDeviceClass    - Class Code
    dim bDeviceSubClass as char       ' bDeviceSubClass - Subclass code
    dim bDeviceProtocol as char       ' bDeviceProtocol - Protocol code
    dim bMaxPacketSize0 as char       ' bMaxPacketSize0 - Maximum packet size for endpoint 0
    dim idVendor as word              ' idVendor        - Vendor ID
    dim idProduct as word             ' idProduct       - Product ID
    dim bcdDevice as word             ' bcdDevice       - Device release number (BCD)
    dim iManufacturer as char         ' iManufacturer   - Index of string descriptor for the manufacturer
    dim iProduct as char              ' iProduct        - Index of string descriptor for the product.
    dim iSerialNumber as char         ' iSerialNumber   - Index of string descriptor for the serial number.
    dim bNumConfigurations as char    ' bNumConfigurations - Number of possible configurations
end structure

const device_dsc as device_descriptor = (
  0x12,                   ' bLength
  0x01,                   ' bDescriptorType
  0x0200,                 ' bcdUSB
  0x00,                   ' bDeviceClass
  0x00,                   ' bDeviceSubClass
  0x00,                   ' bDeviceProtocol
  8,                      ' bMaxPacketSize0
  USB_VENDOR_ID,          ' idVendor
  USB_PRODUCT_ID,         ' idProduct
  0x0001,                 ' bcdDevice
  0x01,                   ' iManufacturer
  0x02,                   ' iProduct
  0x00,                   ' iSerialNumber
  0x01                    ' bNumConfigurations
)

' Configuration 1 Descriptor
const configDescriptor1 as byte[41] = (
    ' Configuration Descriptor
    0x09,                   ' bLength             - Descriptor size in bytes
    0x02,                   ' bDescriptorType     - The constant CONFIGURATION (02h)
    0x29,0x00,              ' wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
    1,                      ' bNumInterfaces      - Number of interfaces in the configuration
    1,                      ' bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
    0,                      ' iConfiguration      - Index of string descriptor for the configuration
    USB_SELF_POWER,         ' bmAttributes        - Self/bus power and remote wakeup settings
    USB_MAX_POWER,          ' bMaxPower           - Bus power required in units of 2 mA

    ' Interface Descriptor
    0x09,                   ' bLength - Descriptor size in bytes (09h)
    0x04,                   ' bDescriptorType - The constant Interface (04h)
    0,                      ' bInterfaceNumber - Number identifying this interface
    0,                      ' bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
    2,                      ' bNumEndpoint - Number of endpoints supported not counting endpoint zero
    0x03,                   ' bInterfaceClass - Class code
    0,                      ' bInterfaceSubclass - Subclass code
    0,                      ' bInterfaceProtocol - Protocol code
    0,                      ' iInterface - Interface string index

    ' HID Class-Specific Descriptor
    0x09,                   ' bLength         - Descriptor size in bytes.
    0x21,                   ' bDescriptorType - This descriptor's type: 21h to indicate the HID class.
    0x01,0x01,              ' bcdHID          - HID specification release number (BCD).
    0x00,                   ' bCountryCode    - Numeric expression identifying the country for localized hardware (BCD) or 00h.
    1,                      ' bNumDescriptors - Number of subordinate report and physical descriptors.
    0x22,                   ' bDescriptorType - The type of a class-specific descriptor that follows
    USB_HID_RPT_SIZE,0x00,  ' wDescriptorLength - Total length of the descriptor identified above.

    ' Endpoint Descriptor
    0x07,                   ' bLength - Descriptor size in bytes (07h)
    0x05,                   ' bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP or 0x80,     ' bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      ' bmAttributes - Transfer type and supplementary information
    0x40,0x00,              ' wMaxPacketSize - Maximum packet size supported
    EP_IN_INTERVAL,         ' bInterval - Service interval or NAK rate

    ' Endpoint Descriptor
    0x07,                   ' bLength - Descriptor size in bytes (07h)
    0x05,                   ' bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP,             ' bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      ' bmAttributes - Transfer type and supplementary information
    0x40,0x00,              ' wMaxPacketSize - Maximum packet size supported
    EP_OUT_INTERVAL         ' bInterval - Service interval or NAK rate
)

structure hid_report_descriptor
  dim report as char[USB_HID_RPT_SIZE]
end structure

const hid_rpt_desc as hid_report_descriptor = (
  ( 0x05,0x01,                ' USAGE_PAGE (Generic Desktop)
    0x09, 0x06,               ' USAGE (Keyboard)
    0xa1, 0x01,               ' COLLECTION (Application)
    0x05, 0x07,
    0x19, 0xe0,                   '   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                   '   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                   '   LOGICAL_MINIMUM (0)
    0x25, 0x01,                   '   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                   '   REPORT_SIZE (1)
    0x85, 0x01,                   '   REPORT ID 1  (75)
    0x95, 0x08,                   '   REPORT_COUNT (8)
    0x81, 0x02,                   '   INPUT (Data,Var,Abs)
   ''''''''''''''''''''''''''
    0x95, 0x01,                  '   REPORT_COUNT (1)
    0x75, 0x08,                  '   REPORT_SIZE (8)
    0x81, 0x03,                  '   INPUT (Cnst,Var,Abs)
   ''''''''''''''''''''''''''''
    0x95, 0x05,                  '   REPORT_COUNT (5)
    0x75, 0x01,                  '   REPORT_SIZE (1)
    0x05, 0x08,                  '   USAGE_PAGE (LEDs)
    0x19, 0x01,                  '   USAGE_MINIMUM (Num Lock)
    0x29, 0x05,                  '   USAGE_MAXIMUM (Kana)
    0x91, 0x02,                  '   OUTPUT (Data,Var,Abs)
    0x95, 0x01,                  '   REPORT_COUNT (1)
    0x75, 0x03,                  '   REPORT_SIZE (3)
    0x91, 0x03,                  '   OUTPUT (Cnst,Var,Abs)
    0x95, 0x06,                  '   REPORT_COUNT (6)
    0x75, 0x08,                  '   REPORT_SIZE (8)
    0x15, 0x00,                  '   LOGICAL_MINIMUM (0)
    0x25, 0x65,                  '   LOGICAL_MAXIMUM (101)
    0x05, 0x07,                  '   USAGE_PAGE (Keyboard)
    0x19, 0x00,                  '   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x65,                  '   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                  '   INPUT (Data,Ary,Abs)
    0xc0,
   
    0x06, 0x00, 0xFF,      ' Usage Page = 0xFF00 (Vendor Defined Page 1)
    0x09, 0x01,             ' Usage (Vendor Usage 1)
    0xA1, 0x01,             ' Collection (Application)
    ' Input report
    0x19, 0x01,             ' Usage Minimum
    0x29, 0x40,             ' Usage Maximum
    0x15, 0x00,             ' Logical Minimum (data bytes in the report may have minimum value = 0x00)
    0x26, 0xFF, 0x00,       ' Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
    0x75, 0x08,             ' Report Size: 8-bit field size
    0x85, 0x02,             '   REPORT ID 2  (75)
    0x95, HID_INPUT_REPORT_BYTES,' Report Count
    0x81, 0x02,             ' Input (Data, Array, Abs)
    ' Output report
    0x19, 0x01,             ' Usage Minimum
    0x29, 0x40,             ' Usage Maximum
    0x75, 0x08,             ' Report Size: 8-bit field size
    0x95, HID_OUTPUT_REPORT_BYTES,' Report Count
    0x91, 0x02,             ' Output (Data, Array, Abs)
    0xC0)                   ' End Collection
    )

'Language code string descriptor
structure str1
  dim bLength as char
  dim bDscType as char
  dim wString as word[1]
end structure

const strd1 as str1 = (
  4,
  0x03,
  (0x0409)
)

'Manufacturer string descriptor
structure str2
  dim bLength as char
  dim bDscType as char
  dim wString as word[14]
end structure

const strd2 as str2 = (
  30,           'sizeof this descriptor string
  0x03,
  ("M","I","c","r","o"," ","I",".","C","."," ","L","T","D")
)

'Product string descriptor
structure str3
  dim bLength as char
  dim bDscType as char
  dim wString as word[21]
end structure

const strd3 as str3 = (
  44,           'sizeof this descriptor string
  0x03,
  ("U","S","B"," ","K","e","y","b","o","a","r","d"," ","E","m","u","l","a","t","o","r")
)


dim USB_config_dsc_ptr as ^const char[1]

dim USB_string_dsc_ptr as ^const char[3]

sub procedure USB_Init_desc()

implements
  sub procedure USB_Init_desc()
    USB_config_dsc_ptr[0] = @configDescriptor1
    USB_string_dsc_ptr[0] = ^const char(@strd1)
    USB_string_dsc_ptr[1] = ^const char(@strd2)
    USB_string_dsc_ptr[2] = ^const char(@strd3)
  end sub
end.

Kilrah
Posts: 8
Joined: 10 Aug 2011 13:30

Re: USB Hid communication in VB6 (Visual Basic 6)

#20 Post by Kilrah » 19 Aug 2011 21:56

slavisa.zlatanovic wrote:Hi!
I sure wish MikroE would put out a set of standard PC example apps (with source code!) for USB for the most common development environments - VB6, VB.NET, VCC, Delphi should cover most requirements. The HID terminal is great to prove the microcontroller side is working, but doesn't really get you anywhere for your own application. At least their MikroC USB examples are there, that was already a big help, given than the help file for the USB library commands isn't really explaining much. And having extensive support for USB applications (based on PIC18F2550/4550) in MikroC and MikroBasic would be a very attractive marketing tool for them as well, given that all the world is moving to USB now.
I will pass this to our developers.
Thank for suggesting it!
Even better than strict Windows solutions, any chance about a cross-platform framework like QT?
Development is easy to do on a Windows machine, but when you want to make something that goes out to the wide world, it's always a good point if you can provide a PC-side app that is cross-platform, at least Win & Mac OS...

licina.boris@gmail.com
Posts: 1
Joined: 10 Dec 2023 16:00

Re: USB Hid communication in VB6 (Visual Basic 6)

#21 Post by licina.boris@gmail.com » 10 Dec 2023 16:17

I'm asking for help.
1. How to define VID and PID in VB software, since for me it says for the connected device: USB\VID_0908&PID_01FE\
2. Where are the characters that are sent to an external device via the USB port defined?

Thank you in advance!

dronycroin@gmail.com
Posts: 1
Joined: 18 Jan 2024 16:49

Re: USB Hid communication in VB6 (Visual Basic 6)

#22 Post by dronycroin@gmail.com » 18 Jan 2024 16:50

I know that I'm going to face this problem eventually, now it's going to be much easier! Thanks again.

Post Reply

Return to “mikroC PRO for PIC General”