PIC USB to VB.NET


Closed Thread
Results 1 to 40 of 54

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: PIC USB to VB.NET

    Hmm. Ok, seem to have some data coming out but its when I press buttons and not when I move the slider bar Its all wrong lol!
    I'll post code later.

  2. #2
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: PIC USB to VB.NET

    Ok so I stripped out some of the stuff I dont need and with the addition of a few things this is the VB side:

    Code:
    Public Class Form1
    
        ' vendor and product IDs
        Private Const VendorID As Short = 6017   'Replace with your device's
        Private Const ProductID As Short = 2000  'product and vendor IDs
    
    
        ' read and write buffers
        Private Const BufferInSize As Short = 16  'Size of the data buffer coming IN to the PC
        Private Const BufferOutSize As Short = 16 'Size of the data buffer going OUT from the PC
        Dim BufferIn(BufferInSize) As Byte       'Received data will be stored here - the first byte in the array is unused
        Dim BufferOut(BufferOutSize) As Byte     'Transmitted data is stored here - the first item in the array must be 0
    
        Dim PORTC(8) As Integer
    
        Dim IOUT1 As Byte
        ' ****************************************************************
        ' when the form loads, connect to the HID controller - pass
        ' the form window handle so that you can receive notification
        ' events...
        '*****************************************************************
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' do not remove!
            ConnectToHID(Me)
            Pictureoff.Visible = True
            Pictureon.Visible = False
            Label8.Text = "PCB Temp COUNT"
            Label8.Text = "AN1"
            CheckBox1.Enabled = False
            CheckBox2.Enabled = False
            StatusLB2.Text = "USB DEVICE DISCONNECTED"
        End Sub
    
        '*****************************************************************
        ' disconnect from the HID controller...
        '*****************************************************************
        Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            Splash.Close()
            DisconnectFromHID()
        End Sub
    
        '*****************************************************************
        ' a HID device has been plugged in...
        '*****************************************************************
        Public Sub OnPlugged(ByVal pHandle As Integer)
            Dim VendorName As String = "00000000000000000000"
            Dim serial As String = "00000000000000000000"
    
            If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
                ' ** YOUR CODE HERE **)
                hidGetVendorName(pHandle, VendorName, 20)
                hidGetSerialNumber(pHandle, serial, 20)
    
                Label1.Text = "Vendor Name: " & VendorName
                Label2.Text = "Product Name: " & ProductName
                Label3.Text = "Vendor ID: " & VendorID
                Label4.Text = "Product ID: " & ProductID
                Label5.Text = "Serial: " & serial
                Pictureoff.Visible = False
                Pictureon.Visible = True
                Label8.Text = Val(BufferIn(1))
                Label8.Text = Val(BufferIn(2))
                CheckBox1.Enabled = True
                CheckBox2.Enabled = True
                StatusLB2.Text = "USB DEVICE CONNECTED"
            End If
        End Sub
    
        '*****************************************************************
        ' a HID device has been unplugged...
        '*****************************************************************
        Public Sub OnUnplugged(ByVal pHandle As Integer)
            If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
                hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
                ' ** YOUR CODE HERE **
                Pictureoff.Visible = True
                Pictureon.Visible = False
                Label8.Text = "DEG C"
                Label8.Text = "AN1"
                CheckBox1.Enabled = False
                CheckBox2.Enabled = False
                CheckBox4.Enabled = False
                StatusLB2.Text = "USB DEVICE DISCONNECTED"
            End If
        End Sub
    
        '*****************************************************************
        ' controller changed notification - called
        ' after ALL HID devices are plugged or unplugged
        '*****************************************************************
        Public Sub OnChanged()
            ' 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...
            Dim pHandle As Integer
            pHandle = hidGetHandle(VendorID, ProductID)
            hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
        End Sub
    
        '*****************************************************************
        ' on read event...
        '*****************************************************************
        Public Sub OnRead(ByVal pHandle As Integer)
            ' read the data (don't forget, pass the whole array)...
            Dim index As Byte
    
            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 microcontroller...
    
                If BufferIn(7) = 0 And BufferIn(8) = 0 Then
                    '
                    '   incomming ADC reading and PORTA status
                    '   --------------------------------------
                    ProgressBar1.Value = BufferIn(1) 'Display ADC results to
                    ProgressBar2.Value = BufferIn(2) 'the progress bars
                    '
                    ProgressBar3.Value = BufferIn(1) 'Display ADC results to
                    ProgressBar4.Value = BufferIn(3) 'the progress bars
    
                    Label8.Text = Val(BufferIn(1)) 'Display  Progress bars
                    Label9.Text = Val(BufferIn(2))  'Values
                    Label18.Text = Val(BufferIn(3))  'Value
                    '
                    Else
                    '
                    '   Incomming data is a text string
                    '   -------------------------------
                    For index = 1 To BufferInSize   ' pass the whole array but skip (0)
                        If BufferIn(index) <> 0 Then ' valid data?
                            txtreception.AppendText(Chr(BufferIn(index)))
                        End If
                    Next
                    txtreception.Text += vbNewLine
                    txtreception.Select(txtreception.Text.Length - 1, 0)
                    txtreception.ScrollToCaret()
                End If
    
    
            End If
        End Sub
        Public Sub WriteSomeData()
            '   Use to send data to the USB bus.
            '   data must be store in BufferOut array
            '
            '   Actual structure:
            '   -----------------
            '       BufferOut(0) = Report id => always 0
            '       BufferOut(1) = PORTB  ' first data item, etc etc
            '       BufferOut(2) = HPWM slider1 MSB
            '       BufferOut(3) = IOUT
            '       BufferOut(4) = HPWM slider2 MSB
            '       BufferOut(5) = HPWM slider2 LSB
            '       BufferOut(6) = n/a = 0
            '       BufferOut(7) = n/a = 0
            '       BufferOut(8) = n/a = 0
            BufferOut(0) = 0   ' first by is always the report ID
            BufferOut(6) = 0
            BufferOut(7) = 0
            BufferOut(8) = 0
    
            hidWriteEx(VendorID, ProductID, BufferOut(0)) ' send it
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            txtreception.Clear()
        End Sub
    
    
        Public Sub ActualizaPORTC()
            Dim i As Integer
    
            BufferOut(1) = 0
    
            If CheckBox1.Checked = True Then
                PORTC(6) = 1
            Else
                PORTC(6) = 0
            End If
    
            If CheckBox2.Checked = True Then
                PORTC(1) = 1
            Else
                PORTC(1) = 0
            End If
    
                    For i = 0 To 1
                BufferOut(1) = BufferOut(1) + (PORTC(i) * (2 ^ i))
            Next
    
            WriteSomeData()
        End Sub
    
        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
            ActualizaPORTAB()
        End Sub
    
        Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
            ActualizaPORTAB()
        End Sub
    
        'Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '   ActualizaPORTAB()
        'End Sub
    
        'Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '   ActualizaPORTAB()
        'End Sub
    
        'Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '   ActualizaPORTAB()
        'End Sub
    
        'Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '   ActualizaPORTAB()
        'End Sub
    
        'Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '   ActualizaPORTAB()
        'End Sub
    
        'Private Sub CheckBox8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '   ActualizaPORTAB()
        'End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            StatusLB3.Text = DateAndTime.Now.ToString
        End Sub
    
        Private Sub StatusLB1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StatusLB1.Click
    
        End Sub
    
        Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click
    
        End Sub
        Private Sub GroupBox3_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox3.Enter
    
        End Sub
    
        Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
    
        End Sub
    
        Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter
    
        End Sub
    
        Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click
    
        End Sub
    
        Private Sub Label12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label12.Click
    
        End Sub
    
    End Class
    And this is the PIC side:

    Code:
    CLEAR
    
    include "modedefs.bas"
    
    Define OSC 48
    DEFINE LCD_DREG	PORTB       ' Set LCD Data port
    DEFINE LCD_DBIT	4           ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB   ' Set LCD Register Select port
    DEFINE LCD_RSBIT 3     	' Set LCD Register Select bit
    DEFINE LCD_EREG	PORTB       ' Set LCD Enable port
    DEFINE LCD_EBIT	2           ' Set LCD Enable bit
    DEFINE LCD_BITS	4           ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2       ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2000' Set command delay time in us
    DEFINE LCD_DATAUS 50      ' Set data delay time in us
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    
    ASM
    INT_LIST  macro    ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler   USB_Handler
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Regal Electronics"
    DEFINE USB_PRODUCTNAME "Light Lynk - USB"
    DEFINE USB_SERIAL      "0001"
    DEFINE USB_INSIZE      16    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     16    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ------------
    ; --- They can be assigned to any pin, and no further action is required --- 
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    ;DEFINE USB_PLUGGEDLED  PORTB,7 ; LED indicates if USB is connected
    'DEFINE USB_TXLED       PORTC,6 ;  "      "     data being sent to PC
    DEFINE USB_RXLED       PORTB,6 ;  "      "     data being received from PC
    
    ;--- Variables -------------------------------------------------------------
    Old_PORTC   VAR  BYTE
    New_PORTC   VAR  BYTE
    
    
    ADCON1 = %00001011
    ADCON2 = %10000111
    
    TRISA = %00001111
    TRISB = %00000000
    TRISC = %00000111
    CMCON = 7
    PORTA.5 = 0
    
    LEDTEMP var word
    PCBTEMP var word
    LEDVOLT var word
    LEDCOUNT var word
    CURRENT var word
    LEDCURRENT var word
    LCUR0 var word
    LCUR1 var word
    
    ADJUST var word
    
    tb0 VAR WORD
    tb1 VAR WORD
    tb2 VAR WORD
    
    LED0 var word
    LED1 var word
    LED2 var word
    
    LEDV0 var word
    LEDV1 var word
    
    IOUT VAR byte
    IOUT1 VAR BYTE
    IOUT1 = 5
    
    JMG VAR WORD
    JMG1 VAR WORD
    JMG2 VAR WORD
    JMG3 VAR WORD
    JMG4 VAR WORD
    POT0 var word
    SCK     var     PORTB.0     ' Alias PORTB.0 to SCK (serial data clock)
    SDO     var     PORTC.7     ' Alias PORTC.7 to SDO (serial data out)
    CS      var     PORTB.1     ' Alias PORTB.1 to C_EN (chip enable)
    
    HIGH    CS                 'Chip enable high to start
    high    sck                'Mode 1,1 SCK idles high
    
    pot0.Highbyte = %00000000    'POT0 address in hex - easier for me to see which pot selected
    pot0.lowbyte = 0             'POT0 value in DEC - initialize pot - can be any value
    
    READ 10, pot0.lowbyte
    
    low     CS                          ' Make chip active
            pause   1                           ' Delay after making chip active per data sheet - only need 60nS
            shiftout    sdo,sck,5,[pot0\16]     ' Mode 1,1 in MCP4261 DS / Mode 5 PBP - clock idles high, MSB shift out first
            high    CS                          ' MCP4261 DS recommends toggling /CS between commands
            pause   1                           ' Delay keeps from banging CS pin
    
    
    ADJUST = 0
    PORTC.6 = 0
    
    Pause 1500
    LCDOUT $FE,$C0, " YJ5 LED DRIVER "
    pause 2000
    
    ;--- The Main Loop ---------------------------------------------------------
    Main:
    ARRAYWRITE USBTXBuffer, ["Random text here"]
    gosub WaitToSend
        FOR X = 0 to 1000           ; Check for incomming USB data while waiting
    @       ON_USBRX_GOSUB  _HandleRX
            PAUSE 1
        
            New_PORTC = PORTC                ; Check PORTC pins
            IF New_PORTC != Old_PORTC THEN
                Old_PORTC = New_PORTC
                ARRAYWRITE USBTXBuffer, ["Text Here!"]
                GOSUB WaitToSend
                ARRAYWRITE USBTXBuffer, [PCBTEMP, LEDTEMP, IOUT1, _
                                         PORTC.6, PORTA.4, PORTA.5,0,0]
                GOSUB WaitToSend
            ENDIF
        NEXT X
        
        'ADCIN 3, PCBTEMP            ; Send A/D about once/sec
        'ADCIN 2, LEDTEMP
        ARRAYWRITE USBTXBuffer, [tb0, LEDTEMP, IOUT1, _
                                 PORTC.6, PORTA.4, PORTA.5,0,0]
        GOSUB SendIfReady
        
    If PORTE.3 = 1 THEN MENU
    if PORTC.0 = 1 then SELEC
    if PORTC.1 = 1 then UP
    if PORTC.2 = 1 then DOWN
    
    ADCIN 3,PCBTEMP
    tb0 = PCBTEMP * 33 /92 
    tb1 = tb0*721                                     
    tb2 = Div32 255
    tb2 = tb2 - 300
    tb0 = tb2/10   
    tb1 = tb2//10
    
    ADCIN 2,LEDTEMP
    LED0 = LEDTEMP * 33 /92 
    LED1 = LED0*721                                     
    LED2 = Div32 255
    LED2 = LED2 - 264
    LED0 = LED2/10   
    LED1 = LED2//10
     
    PAUSE 200
     
    LCDOUT $FE,1,"PCB ",DEC2 tb0,".",DEC1 tb1,"C ",DEC4 IOUT1 
    LCDOUT $FE,$C0,"LED ",DEC2 LED0,".",DEC1 LED1,"C ", DEC4 LEDTEMP
    
    ADCIN 1, LEDCOUNT
    LEDVOLT = LEDCOUNT * 49 /100
    LEDV0 = LEDVOLT/10
    LEDV1 = LEDVOLT//100
    
    ADCIN 0, CURRENT
    LEDCURRENT = CURRENT * 50 /10
    LCUR0 = LEDCURRENT/10
    LCUR1 = LEDCURRENT//100       
    
    PAUSE 2000
    
    If PORTE.3 = 1 THEN MENU
    if PORTC.0 = 1 then SELEC
    if PORTC.1 = 1 then UP
    if PORTC.2 = 1 then DOWN
    
    LCDOUT $FE,1, "LED V ", DEC2 LEDV0, ".", DEC1 LEDV1,"V ", DEC4 LEDCOUNT
    LCDOUT $FE,$C0,"LED C ", DEC2 LCUR0, ".", DEC1 LCUR1,"A ", DEC4 CURRENT
    
    pause 2000
    
    If PORTE.3 = 1 THEN MENU
    if PORTC.0 = 1 then SELEC
    if PORTC.1 = 1 then UP
    if PORTC.2 = 1 then DOWN
     
    goto main
    
    MENU:
    'LCDOUT $FE, 1, "MENU" : LCDOUT $FE, $C0,"PRESSED"
    PORTC.6 = 1
    pause 300
    PORTC.6 = 0
    'LCDOUT $fe,1
    goto setup
    
    SELEC:
    LCDOUT $FE, 1, "SELECT" : LCDOUT $FE, $C0,"PRESSED"
    PORTC.6 = 1
    pause 300
    PORTC.6 = 0
    LCDOUT $fe,1
    goto main
    
    UP:
    LCDOUT $FE, 1, "UP" : LCDOUT $FE, $C0,"PRESSED"
    PORTC.6 = 1
    pause 300
    PORTC.6 = 0
    LCDOUT $fe,1
    goto main
    
    DOWN:
    LCDOUT $FE, 1, "DOWN" : LCDOUT $FE, $C0,"PRESSED"
    PORTC.6 = 1
    pause 300
    PORTC.6 = 0
    LCDOUT $fe,1
    goto main
    
    SETUP:
    LCDOUT $FE, 1, "SET LED CURRENT"
    LCDOUT $FE, $C0, DEC3 IOUT
    gosub HandleRX
    IF PORTC.1 = 1 THEN
    IOUT = IOUT + 1
    PAUSE 75
    ENDIF
    IF PORTC.2 = 1 THEN
    IOUT = IOUT - 1
    PAUSE 100
    ENDIF
    pot0.lowbyte = IOUT
    low     CS                          ' Make chip active
            pause   1                           ' Delay after making chip active per data sheet - only need 60nS
            shiftout    sdo,sck,5,[pot0\16]     ' Mode 1,1 in MCP4261 DS / Mode 5 PBP - clock idles high, MSB shift out first
            high    CS                          ' MCP4261 DS recommends toggling /CS between commands
            pause   1                           ' Delay keeps from banging CS pin
    
    
    WRITE 10, IOUT
    IF PORTC.0 = 1 THEN main
    PAUSE 75
    'IF PORTE.3 = 1 THEN VERSION
    GOTO SETUP
    
    VERSION:
    pause 100
    LCDOUT  $FE, 1, "FIRMWARE 1.0"
    LCDOUT  $FE, $C0, "PCBA 1.0 SN 0001"
    If PORTC.0 = 1 THEN SETUP
    Goto VERSION
        
    GOTO Main
    
    ;--- Send Data if Plugged and ready, otherwise discard ---------------------
    SendIfReady:
        IF Plugged AND TX_READY THEN DoUSBOut
    RETURN
    
    ;--- Wait till Ready to send of until unplugged ----------------------------
    WaitToSend:
        WHILE Plugged and !TX_READY : WEND
        IF TX_READY THEN GOSUB DoUSBOut
    RETURN
    
    ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
    HandleRX:
        ARRAYREAD  USBRXBuffer,[JMG, JMG1, IOUT1, PORTC.6, JMG3, JMG4]
        IOUT1 = USBRXBuffer(3)
        
       return
    All I want to do is send some AD values and a couple of Bytes containing temperatures to the PC, and set a slider in VB and send the 0 - 255 value back to IOUT1 byte in PBP and also turn on or off portc.6 in VB.

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: PIC USB to VB.NET

    The rx LED lights up as I click on buttons on the pc, so data must be getting to the pic, but I dont see it turning on or off the port pin as it should. So not sure what data is being sent or whats happening to it once it gets tot he PIC.

    Also, I dont see the rx LED lighting when I move the slider bar so there has to be an issue on the VB side.

    Can anyone help me out please? I'm a learn by example guy. I've figured out a few errors and got my self from some problems but I'm stuck now.

  4. #4
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: PIC USB to VB.NET

    It looks like there are 8 bytes. The first byte has to be 0 as to the last 2. So theroetically i should be able to just do something like this:

    BufferOut(0) = 0
    BufferOut(1) = 100
    BufferOut(2) = 200
    BufferOut(3) = 300
    BufferOut(4) = 400
    BufferOut(5) = 500
    BufferOut(6) = 600
    BufferOut(7) = 0
    BufferOut(8) = 0

    On the PIC end I should be able to use ARRAYWRITE [byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8]

    Should this work?

  5. #5
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240

    Default Re: PIC USB to VB.NET

    HI;

    To send data from PIC to PC, you must do something like this ( Allready posted in the code of the post #1 )

    Code:
    ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTA.2,PORTA.3, PORTA.4, PORTA.5,0,0]
    You don't have to worry about the first byte be equal to 0, only ont the PC to PIC side.

    If you want to send from PC to PIC, you must do something like this ( Allready posted in the code of the post #1 )

    Code:
    PublicSub WriteSomeData()
    ' Use to send data to the USB bus.
    ' data must be store in BufferOut array
    '
    ' Actual structure:
    ' -----------------
    BufferOut(0) = 0    ' first by is always the report ID
    BufferOut(1) = 127 ' value from 1º slider
    BufferOut(2) = 255 ' value from 2º slider
    BufferOut(3) = 10
    BufferOut(4) = 100
    BufferOut(5) = 178
    BufferOut(6) = 0
    BufferOut(7) = 0
    BufferOut(8) = 0
    hidWriteEx(VendorID, ProductID, BufferOut(0)) ' send it
    EndSub
    
    Thanks and Regards;
    Gadelhas

  6. #6
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Re: PIC USB to VB.NET

    Are the values in BufferOut(1) through BufferOut(5) decimal? Are they bytes or words?

    How do I receive these values and put them into VAR BYTES?

    Do I always need to send the 8 values of BufferOut or can I send say just BufferOut(3)?

    Can I send BufferOut(1) = "text here" for example?



    Thank you!!

  7. #7
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240

    Default Re: PIC USB to VB.NET

    Quote Originally Posted by jmgelba View Post
    Are the values in BufferOut(1) through BufferOut(5) decimal? Are they bytes or words?

    How do I receive these values and put them into VAR BYTES?

    Do I always need to send the 8 values of BufferOut or can I send say just BufferOut(3)?

    Can I send BufferOut(1) = "text here" for example?



    Thank you!!
    Hi, you are not reading the code that i posted.
    If you read the code carfully you see that in VB the BufferOut Array is declared asbyte, so you can only send bytes.
    Code:
    Dim BufferOut(BufferOutSize) AsByte
    On the PIC side you receive the bytes on the USBRXBuffer array, and then you do what you want with those bytes.
    Code:
      ARRAYREAD  USBRXBuffer,[PORTB, DUTY1.LowByte, DUTY1.HighByte, DUTY2.LowByte, DUTY2.HighByte]
    On the VB side you receive tte bytes on BufferIn array, and then you do what you want with thise bytes.
    Code:
    Dim BufferIn(BufferInSize) AsByte
    Since the Define of the USB_INSIZE and USB_OUTSIZE are equal to 8, you can only send and receive 8 bytes. You can change this, to multiples values, like 16, 32, 64. YOu need always to send all th ebytes that are defined. You you Define 8, you must send 8 bytes, if you define 16 you must send 16 bytes. For instance, if you have only 10 bytes to send, you must define you USB_sizes equal to 16, and complete the array with 0's.

    Can I send BufferOut(1) = "text here" for example?
    You cannot do that, because it excedes the number of bytes. BufferOut(1) is one byte only. You cand o just this, BufferOut(1)="t", or
    BufferOut = "0abcdefgh".

    I think that you should read both PIC and VB code that i posted and review review some principles of the PBP manual.
    Thanks and Regards;
    Gadelhas

Members who have read this thread : 0

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

Posting Permissions

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