Developing a custom HID control interface to do anything you want with VB etc.


+ Reply to Thread
Page 1 of 8 123 ... LastLast
Results 1 to 15 of 110
  1. #1
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Developing a custom HID control interface to do anything you want with VB etc.

    Here is a small project for controlling a PIC(tm) over usb via VB that I am in the process of developing.

    The idea is to first design the PIC(tm) side that is a generic usb HID device. It only, basically, has buffers and the necessary polling and is seen as a connected usb device on the PC.

    What you then DO with the device is up to your VB program.
    The device will be recognised and polled with no programs running on the PC.

    When the VB program is running, you can do whatever (within reason ) to control the pic - or send info FROM the PIC(tm) to your VB application.

    Maybe you want to ....

    turn on a few led's ?

    Send data to an LCD unit.

    Send data from the PIC(tm) back to your program. Button presses, data aquisition, anything in fact. Text or data or state(s).

    Control a stepper motor

    Control ANYTHING.

    -------------------------------------------------------------------

    So, first thing is to develop the PIC(tm) code to be recognised as a HID compliant device, but user defined.

    Second, develop the VB code to communicate as and when you need to.

    -------------------------------------------------------------------

    The uses are fairly endless, and by using, again, a common framework, we can do such, we only have to assign in and out buffers, then we decide WHAT each byte in the buffer controls.

    Let's start with the PIC(tm) Code and device descriptor.
    This will connect, be recognised as a USB HID device, but with no specific function, it will stay connected because it being polled.

    Here is the BAS file and USB Descriptor file (inc) to allow the first stage to operate.

    I have used an 18F4550 for this example, and although the USB HID descriptor is maxed at 64 bytes per buffer, the device is currently assigned 8 bytes in and out, this can be easilly changed up to 64 bytes per buffer. Polling interval is set at 10mS.

    The bas file is as follows for proton.

    Code:
    ' select MCU and clock speed
    ' By Joe Hanley 2011, (Captainslarty) developed from EASYHID by Mechanique.
    ' Which in turn, was developed from PDS samples by Les !
    Device = 18F4550
    Xtal = 48    
      Config_Start
       PLLDIV = 5           ' Divide by 5 (20 MHz oscillator input)
       CPUDIV = OSC1_PLL2   ' [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
       USBDIV = 2           ' USB clock source comes from the 96 MHz PLL divided by 2
       FOSC = HSPLL_HS      ' HS oscillator, PLL enabled, HS used by USB
       FCMEN = OFF          ' Fail-Safe Clock Monitor disabled
       IESO = off            ' Oscillator Switchover mode enabled 
       PWRT = off            ' PWRT enabled
       BOR = OFF            ' Brown-out Reset disabled in hardware and software
       BORV = 0             ' Maximum setting
       VREGEN = On          ' USB voltage regulator enabled
       WDT = OFF            ' HW Disabled - SW Controlled
       WDTPS = 1            ' 1:1
       MCLRE = On           ' MCLR pin enabled; RE3 input pin disabled
       LPT1OSC = OFF        ' Timer1 configured for higher power operation
       PBADEN = OFF         ' PORTB <4:0> pins are configured as digital I/O on Reset
       CCP2MX = OFF         ' CCP2 input/output is multiplexed with RC1
       STVREN = OFF         ' Stack full/underflow will not cause Reset
       LVP = OFF            ' Single-Supply ICSP disabled
       XINST = OFF          ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
       Debug = OFF          ' Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
       CP0 = OFF            ' Block 0 (000800-001FFFh) not code-protected
       CP1 = OFF            ' Block 1 (002000-003FFFh) not code-protected
       CP2 = OFF            ' Block 2 (004000-005FFFh) not code-protected
       CPB = OFF            ' Boot block (000000-0007FFh) not code-protected
       CPD = OFF            ' Data EEPROM not code-protected
       WRT0 = OFF           ' Block 0 (000800-001FFFh) not write-protected
       WRT1 = OFF           ' Block 1 (002000-003FFFh) not write-protected
       WRT2 = OFF           ' Block 2 (004000-005FFFh) not write-protected
       WRTB = OFF           ' Boot block (000000-0007FFh) not write-protected
       WRTC = OFF           ' Configuration registers (300000-3000FFh) not write-protected
       WRTD = OFF           ' Data EEPROM not write-protected
       EBTR0 = OFF          ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
       EBTR1 = OFF          ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
       EBTR2 = OFF          ' Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
       EBTRB = OFF          ' Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    
    ' descriptor file, located in \inc\usb_18 - a copy
    ' is located in the same folder as this file    
    USB_Descriptor = "generichidjoeDESC.inc"
    
    ' USB Buffer...
    Symbol USBBufferSizeMax = 8
    Symbol USBBufferSizeTX  = 8
    Symbol USBBufferSizeRX  = 8
    Dim    USBBuffer[USBBufferSizeMax] As Byte
    
    ' some useful flags...
    Dim PP0 As Byte System        ' USBPOLL status return
    Symbol CARRY_FLAG = STATUS.0  ' high if microcontroller does not have control over the buffer
    Symbol ATTACHED_STATE = 6     ' is USB attached
         
    ' ************************************************************
    ' * main program loop - remember, you must keep the USB      *
    ' * connection alive with a call to USBPoll, USBIn or USBOut *
    ' * every couple of milliseconds or so                       *
    ' ************************************************************
    GoSub AttachToUSB
    ProgramLoop:
       GoSub DoUSBIn
       GoSub DoUSBOut
       GoTo ProgramLoop
      
    ' ************************************************************
    ' * receive data from the USB bus                            *
    ' ************************************************************
    DoUSBIn:
       USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
       Return
       
    ' ************************************************************
    ' * transmit data                                            *
    ' ************************************************************
    DoUSBOut:   
       USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut
       Return
    
    ' ************************************************************
    ' * wait for USB interface to attach                         *
    ' ************************************************************
    AttachToUSB:
       Repeat                                
          USBPoll        
       Until PP0 = ATTACHED_STATE
       Return
    ------------------------------------------------------------------------------------------------------

    Now, we need the Descriptor file for USB.

    This is (to work as is with this program -)

    Code:
     
    ' By Joe Hanley 2011, (Captainslarty) developed from EASYHID by Mechanique.
    ' Which in turn, was developed from PDS samples by Les !
    
    LIST
    
    #define    __EP0_BUFF_SIZE            64                ; 8, 16, 32, or 64
    #define    __MAX_NUM_INT            1                ; For tracking Alternate Setting
    #define    __MAX_EP_NUMBER            1                ; UEP1
    #define    __NUM_CONFIGURATIONS            1
    #define    __NUM_INTERFACES        1
    
    #define    __MODE_PP            _PPBM0
    #define    __UCFG_VAL            _PUEN | _TRINT | _FS | __MODE_PP    ; Full-speed
    
    #define __USB_USE_HID                   ; Inform the rest of the library subroutines that we're using a HID interface
    
    ; HID
    ; Endpoints Allocation
    #define    __HID_INTF_ID            0
    #define    __HID_UEP            UEP1
    #define    __HID_BD_OUT            __ep1Bo
    #define    __HID_INT_OUT_EP_SIZE            64
    #define    __HID_BD_IN            __ep1Bi
    #define    __HID_INT_IN_EP_SIZE            64
    #define    __HID_NUM_OF_DSC        1
    
    ; ------------------------------------------------------------------------------
    ; This table is polled by the host immediately after USB Reset has been released.
    ; The table defines the maximum packet size EP0 can take.
    ; See section 9.6.1 of the Rev 1.0 USB specification.
    ; These fields are application dependent to be modified to meet your specifications.
    ;
    __DeviceDescriptor
        Retlw    (__EndDeviceDescriptor - __DeviceDescriptor) / 2    ; bLength Length of this descriptor
        Retlw    __DSC_DEV                        ; bDescType This is a DEVICE descriptor
        dt    0x10, 0x01                        ; bcdUSB Revision 1.10 low byte, high byte
        Retlw    0x00                            ; bDeviceClass zero means each interface operates independently
        Retlw    0x00                            ; bDeviceSubClass
        Retlw    0x00                            ; bDeviceProtocol
        Retlw    __EP0_BUFF_SIZE                        ; bMaxPacketSize for EP0
    
            ; idVendor low byte, high byte
        dt    0x81, 0x17
            ; idProduct low byte, high byte
        dt    0xD0, 0x07
    
        dt    0x00, 0x00                        ; bcdDevice low byte, high byte
        Retlw    0x01                            ; iManufacturer
        Retlw    0x02                            ; iProduct
    
            ; iSerialNumber index
        Retlw    0x00
    
        Retlw    __NUM_CONFIGURATIONS                         ; bNumConfigurations
    __EndDeviceDescriptor
    
    ; ------------------------------------------------------------------------------
    ; This table is retrieved by the host after the address has been set.
    ; This table defines the configurations available for the device.
    ; See section 9.6.2 of the Rev 1.0 USB specification (page 184).
    ; These fields are application dependent to be modified to meet your specifications.
    ;
    ; Configuration pointer table
    __USB_CD_Ptr
    __Configs
        db    Low ___Config1, High ___Config1
        db    Low ___Config1, High ___Config1
    
    ; Configuration Descriptor
    ___Config1
        Retlw    (__Interface1-___Config1) / 2    ; bLength Length of this descriptor
        Retlw    __DSC_CFG                        ; bDescType 2 = CONFIGURATION
    __Config1Len
        Retlw    Low ((__EndConfig1 - ___Config1) / 2)    ; Length of this configuration
        Retlw    High ((__EndConfig1 - ___Config1) / 2)
        Retlw    0x01                            ; bNumInterfaces Number of interfaces
        Retlw    0x01                            ; bConfigValue Configuration Value
        Retlw    0x04                            ; iConfig String Index for this config = #01
        Retlw    0xA0                            ; bmAttributes attributes - bus powered
    
            ; Max power consumption (2X mA)
        Retlw    0x32
    __Interface1
        Retlw    (__HIDDescriptor1 - __Interface1) / 2    ; length of descriptor
        Retlw    __DSC_INTF
        Retlw    0x00                            ; number of interface, 0 based array
        Retlw    0x00                            ; alternate setting
        Retlw    0x02                            ; number of endpoints used in this interface
        Retlw    0x03                            ; interface CLASS - assigned by the USB
        Retlw    0x00                            ; boot device
        Retlw    0x00                            ; interface protocol - mouse
        Retlw     0x00                            ; index to string descriptor that describes this interface
    __HIDDescriptor1
        Retlw    (__Endpoint1In - __HIDDescriptor1) / 2    ; descriptor size (9 bytes)
          Retlw    0x21                            ; descriptor type (HID)
        dt        0x00, 0x00                        ; HID CLASS release number (1.00) low byte, high byte
           Retlw    0x00                            ; Localised country code (none)
         Retlw    0x01                            ; Number of HID CLASS descriptor to follow (1)
         Retlw    0x22                            ; Report descriptor type (HID)
    __ReportDescriptor1Len
        Retlw    Low ((__EndReportDescriptor1 - __ReportDescriptor1) / 2)
        Retlw    High ((__EndReportDescriptor1 - __ReportDescriptor1) / 2)
    __Endpoint1In
        Retlw    (__EndPoint1Out - __Endpoint1In) / 2    ; length of descriptor
        Retlw    __DSC_EP
        Retlw    0x81                            ; EP1, IN
        Retlw    0x03                            ; Interrupt
        dt    0x40, 0x00                        ; This should be the size of the endpoint buffer low byte, high byte
        Retlw    0x0A                            ; Polling interval
    __EndPoint1Out
        Retlw    (__EndConfig1 - __EndPoint1Out) / 2    ; Length of this Endpoint Descriptor
        Retlw    __DSC_EP                        ; bDescriptorType = 5 for Endpoint Descriptor
        Retlw    0x01                            ; Endpoint number & direction
        Retlw    0x03                            ; Transfer type supported by this Endpoint
        dt    0x40, 0x00                        ; This should be the size of the endpoint buffer low byte, high byte
        Retlw    0x0A                            ; Polling interval 
    __EndConfig1
    
    __ReportDescriptor1
        ; vendor defined usage page
        Retlw    0x06        
        Retlw    0x00       
        Retlw    0xFF
    
        ; vendor defined usage
        Retlw    0x09        
        Retlw    0x00
    
        ; collection(application)
        Retlw    0xA1        
        Retlw    0x01
    
        ; *** INPUT REPORT ***
                   
        ; vendor defined usage
        Retlw    0x09        
        Retlw    0x01
    
        Retlw    0x15        ; logical minimum (-128)
        Retlw    0x80        ; 
        Retlw    0x25        ; logical maximum (127)
        Retlw    0x7F        ; 
        Retlw    0x35        ; Physical Minimum (0)
        Retlw    0x00        ;
        Retlw    0x45        ; Physical Maximum (255)
        Retlw    0xFF        ;
            
        ; report size in bits
        Retlw    0x75    
        Retlw    0x08
            
        ; report count (number of fields)
        Retlw    0x95        
        Retlw    0x08
            
        ; Input (Data, Variable, Absolute)
        Retlw    0x81        
        Retlw    0x02
    
        ; *** OUTPUT REPORT ***
        
        ; vendor defined usage
        Retlw    0x09        ; usage (Vendor Defined)
        Retlw    0x02        ;
    
        Retlw    0x15        ; logical minimum (-128)
        Retlw    0x80        ; 
        Retlw    0x25        ; logical maximum (127)
        Retlw    0x7F        ; 
        Retlw    0x35        ; Physical Minimum (0)
        Retlw    0x00        ;
        Retlw    0x45        ; Physical Maximum (255)
        Retlw    0xFF        ;
            
        ; report size in bits
        Retlw    0x75        
        Retlw    0x08
            
        ; report count (number of fields)
        Retlw    0x95    
        Retlw    0x08
            
        ; Output (Data, Variable, Absolute)
        Retlw    0x91        
        Retlw    0x02
    
        Retlw   0xC0        ; end collection
    __EndReportDescriptor1
    
    ; String pointer table
    __USB_SD_Ptr
    __Strings
        db    Low __String0, High __String0
        db    Low __String1, High __String1
        db    Low __String2, High __String2
        db    Low __String3, High __String3
        db    Low __String4, High __String4
    
    __String0
        Retlw    (__String1 - __String0) / 2        ; Length of string 
        Retlw    __DSC_STR                        ; Descriptor type 3
        dt   0x09, 0x04                            ; Language ID (0x0409 as defined by MS)
    
    ;company name
    __String1
        Retlw    (__String2 - __String1) / 2
        Retlw    __DSC_STR
        
            Retlw   'M'
            Retlw   0x00
            Retlw   'y'
            Retlw   0x00
            Retlw   'C'
            Retlw   0x00
            Retlw   'o'
            Retlw   0x00
            Retlw   'm'
            Retlw   0x00
            Retlw   'p'
            Retlw   0x00
            Retlw   'a'
            Retlw   0x00
            Retlw   'n'
            Retlw   0x00
            Retlw   'y'
            Retlw   0x00
    
    
    ;product name
    __String2
        Retlw    (__String3 - __String2) / 2
        Retlw    __DSC_STR
        
            Retlw   'M'
            Retlw   0x00
            Retlw   'y'
            Retlw   0x00
            Retlw   'P'
            Retlw   0x00
            Retlw   'r'
            Retlw   0x00
            Retlw   'o'
            Retlw   0x00
            Retlw   'd'
            Retlw   0x00
            Retlw   'u'
            Retlw   0x00
            Retlw   'c'
            Retlw   0x00
            Retlw   't'
            Retlw   0x00
    
    
    ; serial number
    __String3
        Retlw    (__String4 - __String3) / 2
        Retlw    __DSC_STR
        
    
    __String4
        Retlw    (__String5 - __String4) / 2
        Retlw    __DSC_STR
        dt    0
    __String5
    --------------------------------------------------------------------------------------------

    I claim no real credit for this, apart from trying to put this into reasonably easy to understand terms !

    ALL credit is to Mechanique's old program EASYHID.

    But we will adapt and change it as we need to develop it. Consider it like I am doing a learning excercise! .

    Also, enclosed are the VB generic files to control the project, (NOTE !!! these are for VB5 !! and will probably need to be updated to whatever version you are using).

    I will leave it at that for the moment, but hopefully you can see how easy it is.
    This is a template for two way comms using the pic and vb, what WE decide, or YOU decide to do with the actual data in the buffers is completely up to you.

    Compile and program the PIC(tm) side first !, you should see a HID device attached and remain connected.

    Joe.
    Attached Files Attached Files

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Just looked back at my MS Program Disks, and have got VB4 and VB6 Pro, so have just installed VB6 Pro (I also have VS2008 installed) but the vb files should be easier to convert to vb6, will sort that out and post updates if needed. I cant believe VB6 was 1998 !!!.. Jeeeeeeeez eventually, I will sort it for VB 2008 .net
    Priase the lord Bill for standard products lol
    Joe.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Ok, using VB6 ! , you will need the vb6 runtime files...
    here is more or less a 'hello world' to prove comms, it is dirty and brief, but shows what can be done and realistically HOW simple it is to integrate USB !!!!.

    Great fun..

    Ok, using the descriptor previously listed below. (YOU SHOULDNT NEED TO CHANGE THIS !)

    heres a crude new bas file for PDS and the vb exe file... using an 18F4550, you can turn on and off an led on Portd.0

    For the VERY simple and very crude vb exe, there are two button, led on and led off.. can't get much simpler than that haha.. and, best thing is, it bloody works !!!!.

    Have a play, and feel free to ask if there is anything that you don't understand, USB IS a steep learning curve, but.. I am trying to make it simple so we can all play !.

    Code:
    ' select MCU and clock speed
    Device = 18F4550
    Xtal = 48    
      Config_Start
       PLLDIV = 5           ' Divide by 5 (20 MHz oscillator input)
       CPUDIV = OSC1_PLL2   ' [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
       USBDIV = 2           ' USB clock source comes from the 96 MHz PLL divided by 2
       FOSC = HSPLL_HS      ' HS oscillator, PLL enabled, HS used by USB
       FCMEN = OFF          ' Fail-Safe Clock Monitor disabled
       IESO = off            ' Oscillator Switchover mode enabled 
       PWRT = off            ' PWRT enabled
       BOR = OFF            ' Brown-out Reset disabled in hardware and software
       BORV = 0             ' Maximum setting
       VREGEN = On          ' USB voltage regulator enabled
       WDT = OFF            ' HW Disabled - SW Controlled
       WDTPS = 1            ' 1:1
       MCLRE = On           ' MCLR pin enabled; RE3 input pin disabled
       LPT1OSC = OFF        ' Timer1 configured for higher power operation
       PBADEN = OFF         ' PORTB <4:0> pins are configured as digital I/O on Reset
       CCP2MX = OFF         ' CCP2 input/output is multiplexed with RC1
       STVREN = OFF         ' Stack full/underflow will not cause Reset
       LVP = OFF            ' Single-Supply ICSP disabled
       XINST = OFF          ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
       Debug = OFF          ' Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
       CP0 = OFF            ' Block 0 (000800-001FFFh) not code-protected
       CP1 = OFF            ' Block 1 (002000-003FFFh) not code-protected
       CP2 = OFF            ' Block 2 (004000-005FFFh) not code-protected
       CPB = OFF            ' Boot block (000000-0007FFh) not code-protected
       CPD = OFF            ' Data EEPROM not code-protected
       WRT0 = OFF           ' Block 0 (000800-001FFFh) not write-protected
       WRT1 = OFF           ' Block 1 (002000-003FFFh) not write-protected
       WRT2 = OFF           ' Block 2 (004000-005FFFh) not write-protected
       WRTB = OFF           ' Boot block (000000-0007FFh) not write-protected
       WRTC = OFF           ' Configuration registers (300000-3000FFh) not write-protected
       WRTD = OFF           ' Data EEPROM not write-protected
       EBTR0 = OFF          ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
       EBTR1 = OFF          ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
       EBTR2 = OFF          ' Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
       EBTRB = OFF          ' Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    
    ' descriptor file, located in \inc\usb_18 - a copy
    ' is located in the same folder as this file    
    USB_Descriptor = "generichidjoeDESC.inc"
    
    ' USB Buffer...
    Symbol USBBufferSizeMax = 8
    Symbol USBBufferSizeTX  = 8
    Symbol USBBufferSizeRX  = 8
    Dim    USBBuffer[USBBufferSizeMax] As Byte
    TRISD.0 = 0
    Symbol led = PORTD.0
    led=1
    DelayMS 1000
    led=0
    
    ' some useful flags...
    Dim PP0 As Byte System        ' USBPOLL status return
    Symbol CARRY_FLAG = STATUS.0  ' high if microcontroller does not have control over the buffer
    Symbol ATTACHED_STATE = 6     ' is USB attached
         
    ' ************************************************************
    ' * main program loop - remember, you must keep the USB      *
    ' * connection alive with a call to USBPoll, USBIn or USBOut *
    ' * every couple of milliseconds or so                       *
    ' ************************************************************
    GoSub AttachToUSB
    ProgramLoop:
       GoSub DoUSBIn
       GoSub DoUSBOut
       GoTo ProgramLoop
      
    ' ************************************************************
    ' * receive data from the USB bus                            *
    ' ************************************************************
    DoUSBIn:
       USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
       If USBBuffer[1] = 1 Then
       led=1
      Else led =0
       EndIf
       
       Return
       
    ' ************************************************************
    ' * transmit data                                            *
    ' ************************************************************
    DoUSBOut:   
       USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut
       Return
    
    ' ************************************************************
    ' * wait for USB interface to attach                         *
    ' ************************************************************
    AttachToUSB:
       Repeat                                
          USBPoll        
       Until PP0 = ATTACHED_STATE
       Return
    And the VB EXE... (again, make sure you have the runtime files for VB6 !!!... )
    Attached Files Attached Files
    Last edited by Kapitan; 22nd January 2011 at 15:14.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    ok, here is the rather crappy VB6 code for the exe, you still need the other file the hiddll etc etc as in the original upload further down, these are just the crude changes to alter it....

    Code:
    ' vendor and product IDs
    Private Const VendorID = 6017
    Private Const ProductID = 2000
    
    ' read and write buffers
    Private Const BufferInSize = 8
    Private Const BufferOutSize = 8
    Dim BufferIn(0 To BufferInSize) As Byte
    Dim BufferOut(0 To BufferOutSize) As Byte
    
    Private Sub Command1_Click()
      BufferOut(0) = 0   ' first by is always the report ID
       BufferOut(1) = 0  ' first data item, etc etc
      BufferOut(2) = 1   
       BufferOut(3) = 0  
         BufferOut(4) = 0   
       BufferOut(5) = 0  
         BufferOut(6) = 0  
       BufferOut(7) = 0  ' 
       ' write the data (don't forget, pass the whole array)...
    WriteSomeData
    
    End Sub
    
    Private Sub Command2_Click()
      BufferOut(0) = 0   ' first by is always the report ID
       BufferOut(1) = 0  ' first data item, etc etc
      BufferOut(2) = 0   
       BufferOut(3) = 0  
         BufferOut(4) = 0   
       BufferOut(5) = 0  
         BufferOut(6) = 0   
       BufferOut(7) = 0  ' 
       ' write the data (don't forget, pass the whole array)...
    WriteSomeData
    
    End Sub
    
    ' ****************************************************************
    ' when the form loads, connect to the HID controller - pass
    ' the form window handle so that you can receive notification
    ' events...
    '*****************************************************************
    Private Sub Form_Load()
       ' do not remove!
       ConnectToHID (Me.hwnd)
    End Sub
    
    '*****************************************************************
    ' disconnect from the HID controller...
    '*****************************************************************
    Private Sub Form_Unload(Cancel As Integer)
       DisconnectFromHID
    End Sub
    
    '*****************************************************************
    ' a HID device has been plugged in...
    '*****************************************************************
    Public Sub OnPlugged(ByVal pHandle As Long)
       If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
          ' ** YOUR CODE HERE **
       End If
    End Sub
    
    '*****************************************************************
    ' a HID device has been unplugged...
    '*****************************************************************
    Public Sub OnUnplugged(ByVal pHandle As Long)
       If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
          ' ** YOUR CODE HERE **
       End If
    End Sub
    
    '*****************************************************************
    ' controller changed notification - called
    ' after ALL HID devices are plugged or unplugged
    '*****************************************************************
    Public Sub OnChanged()
       Dim DeviceHandle As Long
       
       ' get the handle of the device we are interested in, then set
       ' its read notify flag to true - this ensures you get a read
       ' notification message when there is some data to read...
       DeviceHandle = hidGetHandle(VendorID, ProductID)
       hidSetReadNotify DeviceHandle, True
    End Sub
    
    '*****************************************************************
    ' on read event...
    '*****************************************************************
    Public Sub OnRead(ByVal pHandle As Long)
       
       ' read the data (don't forget, pass the whole array)...
       If hidRead(pHandle, BufferIn(0)) Then
          ' ** YOUR CODE HERE **
          ' first byte is the report ID, e.g. BufferIn(0)
          ' the other bytes are the data from the microcontrolller...
       End If
    End Sub
    
    '*****************************************************************
    ' this is how you write some data...
    '*****************************************************************
    Public Sub WriteSomeData()
     
       hidWriteEx VendorID, ProductID, BufferOut(0)
    End Sub
    Last edited by Kapitan; 22nd January 2011 at 15:24.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    here are the vb files converted for visual basic 2008 .net.

    the exe is in the bin directory.

    Attached Files Attached Files

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Hi Joe,

    I'm following your posts like a turorial and I found difficulties to have the correct set up to run the/modify the code on post #4 related to VB6.

    Would you be so kind as to send to me a PM or upload al needed files ( ... you still need the other file the hiddll etc etc).

    Ciao

    Leo

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Quote Originally Posted by wirecut View Post
    Hi Joe,

    I'm following your posts like a turorial and I found difficulties to have the correct set up to run the/modify the code on post #4 related to VB6.

    Would you be so kind as to send to me a PM or upload al needed files ( ... you still need the other file the hiddll etc etc).

    Ciao

    Leo
    Hello my friend, of course I will, I will email you all the VB6 stuff with working examples.
    To be honest, at the moment, VB6 is more reliable for this !. I have found a few minor issues with VB2008, so will probably stick to VB6 for now.

    See how you get on with it. Then I will update them all here to make it easier. I have a version now that has two way communications working in a demo in VB6. Also, the PDS code is old, it is really for the older 14bit core 16F, but works with the 18F, I have also updated that too.

    Once you get to understand it, it is really easy to use, and you could do virtually anything you need.

    This code is really just a tranfer of buffer values to and from a HID Pic(tm) to VB code for HID on a PC, if you want to send a value to an lcd display on the pic, you can either send the data directly, or send just a value in one byte, that way, you can have up to 256 messgaes ready to display on the PIC(tm) .. either way.
    It really is a very very good way of using usb HID. and is fully supported in PDS.

    Will send you the details later today or early tomorrow.
    Ciao !
    Joe.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Just to add Leo, either use VB6, OR VB 2010, I have found VB 2008, even with sp1, to be a royal pain in the backside. (if that does not translate - it means it DOES NOT WORK CORRECTLY)

    I will send you the VB6 files, and update all for vb 2010.!
    Joe.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Complete update due to delving deeper and now understanding a little bit more .

    Although the below details work, lets semi start from scratch. !
    I will explain the reasons below -
    -------------------------------------------------------------------------------------------

    First of all, forget Easyhid, not that is not superb, but there are other, later and better ways to do this. ! - I just hadn't realised.

    Within Proton PDS, there are two files, Axelson.bas (In the pds samples directory) and JADESC.INC as the usb descriptor.
    I was not aware of these as all the sample bas I have seen contain 'USB' in the title. JADESC is mentioned in the Help File, but not the axelson.bas, although there 'is' a logical link once you realise it.
    Jan Axelson is the author of book USB COMPLETE.

    NOW, I realise the nature of these files, the work in proton is mainly done for the framework. so start with these files in PDS.

    For the VB side, please see Jan Axelson's web page.
    http://www.lvr.com/hidpage.htm

    The very updated VB files as opposed to easyhid are here, DOH!

    For VB6 -
    http://www.lvr.com/files/usbhidio2.zip

    and for VB 2008, which is now fine, as the program has been updated in the last few weeks..
    http://www.lvr.com/files/generic_hid_vb_46.zip

    You will need to change the vendor ID etc to suit.

    So, from now on, this will form the start of the framework.
    There is also an update for the mplabs code for the new JA demo VB, I will 'attempt' to convert the proton code in the bas if it needs it, I need to do more studying, but it looks like he has added only adc function and a few others, the descriptor, apart form the vid pid, should remain unaltered.

    The idea here is that you can do almost anything you want, without any windows drivers, the device is simply recognised as a HID device, (NO DRIVER NEEDED ON THE PC!), with in input buffer and output buffer. The VB code allows full communication providing the pic responds to the data.


    Joe.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    wastrix
    Guest wastrix's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    For VB6 -
    http://www.lvr.com/files/usbhidio2.zip

    and for VB 2008, which is now fine, as the program has been updated in the last few weeks..
    http://www.lvr.com/files/generic_hid_vb_46.zip
    That code is great for testing and learning, but I found it too much effort to integrate the USB functions into another app. (Because of her coding style - for each one line of code there are about 50 lines of comments, simply scrolling through has taken years off my life! I advocate the conservative use of comments - if there is a lot of information to convey with the code there should be separate DOCUMENTATION!)

    What I ended up doing was writing an C#.net/VB.net HID library, based on code from her USB Complete book, but stripped down to about 10% of the size. Unfortunately I left this hanging at about 90% complete when I decided to use WinUSB for that project instead.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Quote Originally Posted by wastrix View Post
    That code is great for testing and learning, but I found it too much effort to integrate the USB functions into another app. (Because of her coding style - for each one line of code there are about 50 lines of comments, simply scrolling through has taken years off my life! I advocate the conservative use of comments - if there is a lot of information to convey with the code there should be separate DOCUMENTATION!)

    What I ended up doing was writing an C#.net/VB.net HID library, based on code from her USB Complete book, but stripped down to about 10% of the size. Unfortunately I left this hanging at about 90% complete when I decided to use WinUSB for that project instead.
    Lol , I didnt know JAN was female !
    It is very similar to the easy hid code, but more support for vb 2008, in vb6 I found no issues. but will take on board all you have said. !
    Many thanks for the input... I have much to work through. (in fact, If I was still using vb6 the easyhid code is great and works well. !. but this doesnt look 'too' much different, will report back..
    Cheers William. !
    Joe.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #12
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Hi William, I have just tried the latest version for vb 2008, and must confess it is superb !..
    It was only released a few weeks back, so maybe you had a different version.?

    Really easy to use and integrate, yes, loads of comments lol, but oft' times many say you can't have enough .. I fully agree though, it a a fair thing to list out !!!.
    But, great code.. but that is just imho.. I like it. !
    Joe

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #13
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Just to confirm, the latest vb 2008 code works great with the axelson demo !. just need to set the dev id and PID, and all works outa da box.
    COnverting the earlier vb6 code to vb 2008 resulted in a program failure (Crash !) if one disconnected the device and reconnected it, on vb 6 it didnt, so it's a great start..
    I am probably just more tollerant to comments haha..
    But seriously, !!!. it is super.. does what it says and appears easy to mod..... and no changes to the original axelson demo or jadesc in pds. really good.. sorry to ramble, but it works like it says.

    Joe.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #14
    wirecut
    Guest wirecut's Avatar

    0 Not allowed!

    Unhappy Re: Developing a custom HID control interface to do anything you want with VB etc.

    Hi.

    I'm trying to use the example of axelson.bas with its VB6 software, but to me it does not work.
    Could some kind member of this forum whether it works on his PC to see if I'm missing something?

    http://click-server.com/forumfiles/c...95-Axelson.bas

    http://click-server.com/forumfiles/e...4-USBHIDIO.zip

    Ciao

    Leo

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #15
    Kapitan
    Guest Kapitan's Avatar

    0 Not allowed!

    Default Re: Developing a custom HID control interface to do anything you want with VB etc.

    Hi Leo, yes, it works fine here. You have to use the Axelson.bas supplied in PDS.

    However, I have found a new version of the original easyhid vb6 that was converted to VB2005, I have now converted this to VB2008, so they are virtually the same format and very easy to use.

    I was struggling with the conversion of the easy hid files to vb2008 !. but thanks to this link . http://helmpcb.com/?p=166
    Managed to sort it out. so now we can carry on with a very simple to use format for both vb6 and vb2008 (and indeed, vb2005!)
    I have included the project files for VB6 and VB2008,
    Use the generichidjoe.bas and desc files for this.
    I think this is the way to go forward. The Axelson is superb, but as Wastrix said, is actually very over complicated for what most users will ever do, but it is a superb learning tool. Anyways, let's work with these two files from now on, they are so simple to use. I just needed something that works with VB2008 AND VB6.

    Both are set up for the very simple led on and off control. I added the Write_Data sub as detailed in the help file.

    One version is set up for HEX Vid and Pid, the other for Decimal, so you need to note this, the decimal one can be easilly changed with a &H in the vb code.
    Attached Files Attached Files

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. radio control quad copter reciver to pic interface
      By timpainter in forum Projects discussion
      Replies: 17
      Last Post: 4th August 2014, 18:18
    2. Problem with Assembler for custom HID Device
      By Ex_Fisherman in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 9th January 2013, 18:23
    3. USB CDC + HID + IAD interface
      By bidouille in forum USB Module
      Replies: 12
      Last Post: 22nd October 2011, 17:48
    4. Replies: 5
      Last Post: 6th June 2011, 20:12
    5. [SOLVED !] Help with developing code for Sigma Delta ADCs for ref. designs?
      By Ashfaq in forum Proton Plus Compiler v3
      Replies: 6
      Last Post: 21st January 2009, 15:04

    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