Send data PIC to PC


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2009
    Posts
    5

    Default Send data PIC to PC

    Hi,
    I'm doing a program for viewing data from Pic to PC and backwards.
    When filling the fields of TextBox in VB6 application and press the "Send" button I see on the display the data correctly.
    But when it comes to receiving the data to be invented in the Subroutine "EnviarDatos" the Pic not visualize anything in the TextBox.
    Here I leave the program for the PIC and the subroutine VB6 "OnRead" for you dig where you're going to have a look at the ruling.

    in this line means: USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
    The USB 1 it means?

    ahhhhhh......


    When I put the command "USBInit" the computer does not recognize USB pic.
    But when I remove that command, it does not recognize but I have to put "GoSub DoUSBIn"



    Thanks again ....


    ______PIC_________________________________________ _________________________

    Device = 18F4550
    Xtal = 48

    USB_Descriptor = "Pruebas.inc"
    Declare LCD_Type Samsung
    Declare LCD_Interface 8
    Declare LCD_DTPort = PORTB
    Declare LCD_CS1Pin = PORTD.5
    Declare LCD_CS2Pin = PORTD.4
    Declare LCD_RWPin = PORTD.6
    Declare LCD_RSPin = PORTD.7
    Declare LCD_ENPin = PORTC.7
    Declare GLCD_CS_Invert On
    All_Digital = TRUE

    'SIZES OF USB BUFFER
    Symbol USBBufferSizeMax = 10
    Symbol USBBufferSizeTX = 10
    Symbol USBBufferSizeRX = 10
    Dim USBBuffer[USBBufferSizeMax] As Byte
    Dim USBBufferCount As Byte



    Symbol LED = PORTC.1 'LED will PORTC.1 CALL OUT
    Dim LEDUSB As Bit 'STATUS LED (OFF or ON) 1
    Dim A As Word 'MULTI-VARIABLE
    Dim B As Bit 'Biester VARIABLE IN WHICH RECEIVE THE BUTTON

    'REGISTROS Y BANDERAS
    Dim PP0 As Byte System ' EGISTRATION STATUS WITHIN THE PIC USBPOLL
    Symbol CARRY_FLAG = STATUS.0 ' IF HIGH IN STATE HAS NO PIC
    'CONTROL ON THE BUFFER
    Symbol ATTACHED_STATE = 6 'IF USB IS CONNECTED

    Cls 'CLEAN START TO DISPLAY
    Clear 'CLEAN THE RAM TO START

    Internal_Font = On
    Font_Addr = 1

    Print Cls,"Connecting ..."
    GoSub AttachToUSB
    High LED
    Print Cls,"OK"
    USBBuffer[0]= 0 'Flag data 0=Receive (PC>PIC)
    ' 1=Send (PIC>PC)
    ProgramLoop:
    GoSub DoUSBIn 'I will read the input buffer
    If USBBuffer[0]= 1 Then
    Print At 0,9, "Sending ..."
    GoSub EnviarDatos
    Else
    Print At 0,9, "Reading ..."
    Print At 0,8,Dec USBBuffer[0] 'I read the data from the PC and displayed on the GLCD
    Print At 2,1, Dec USBBuffer[2]
    Print At 3,1, Dec USBBuffer[3]
    Print At 4,1, Dec USBBuffer[4]
    Print At 5,1, Dec USBBuffer[5]
    Print At 2,8, Dec USBBuffer[6]
    Print At 3,8, Dec USBBuffer[7]
    Print At 4,8, Dec USBBuffer[8]
    Print At 5,8, Dec USBBuffer[9]
    DelayMS 1
    GoSub DoUSBIn
    End If
    Toggle LED
    GoTo ProgramLoop 'Closes the loop AFTER ALL THE WORK



    ' ************************************************** **********
    ' * RECEIPT OF DATA ROUTINE *
    ' ************************************************** **********
    DoUSBIn:
    USBBufferCount = USBBufferSizeTX
    USBSERVICE
    USBIn 1, USBBuffer, USBBufferSizeRX, DoUSBIn
    Return

    ' ************************************************** **********
    ' * DATA TRANSFER ROUTINE *
    ' ************************************************** **********
    DoUSBOut:
    USBBufferCount = USBBufferSizeTX
    USBSERVICE
    USBOut 1, USBBuffer, USBBufferSizeTX, DoUSBOut
    Return

    ' ************************************************** **********
    ' * Wait until the USB connects*
    ' ************************************************** **********
    AttachToUSB:
    Repeat
    USBPoll
    Until PP0 = ATTACHED_STATE
    Return

    EnviarDatos:
    USBBuffer[2] = 1
    USBBuffer[3] = 2
    USBBuffer[4] = 3
    USBBuffer[5] = 4
    USBBuffer[6] = 5
    USBBuffer[7] = 6
    USBBuffer[8] = 7
    USBBuffer[9] = 8
    DelayMS 1 'GIVE A TIME OF DELAY
    GoSub DoUSBOut 'Sending data in the buffer for the PC
    Return

    End
    Include "FONT.INC"

    _______ VB6 __________________________________________________

    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...
    Text1(1).Text = BufferIn(2)
    Text1(2).Text = BufferIn(3)
    Text1(3).Text = BufferIn(4)
    Text1(4).Text = BufferIn(5)
    Text1(5).Text = BufferIn(6)
    Text1(6).Text = BufferIn(7)
    Text1(7).Text = BufferIn(8)
    Text1(8).Text = BufferIn(9)
    End If
    End Sub

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Sorry, either you are on the wrong forum or you are using the wrong basic.
    This is a Pic Basic forum.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Send data PIC to PC

    The program is written in Basic PBP (mecanique) Crownhill Associates. The last part is written in VB6 in order that you observe the process of the program.
    I do not understand the problem ...

    Thanks

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    PBP is not from Crownhill.
    DIM and DECLARE are not part of PBP.
    As far as I know.....

    Maybe PROTRON ? PROTON ?
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    konter you have an array of text1(n).text boxes and, with your VB code, in every box you transfer just one byte, so you must have all the boxes on the form to see something.


    Code:
    Text1(1).Text = BufferIn(2)
    Text1(2).Text = BufferIn(3)
    Text1(3).Text = BufferIn(4)
    Text1(4).Text = BufferIn(5)
    Text1(5).Text = BufferIn(6)
    Text1(6).Text = BufferIn(7)
    Text1(7).Text = BufferIn(8)
    Text1(8).Text = BufferIn(9)

    It is much better with one single text box

    Code:
    Dim I as Integer
    Text1.text = ""
    ' first byte is the report ID, e.g. BufferIn(0) so you start with 1
    For I=1 to 9
    Text1.text = text1.text + BufferIn(I)
    next
    In the above example you will have all the bytes nicely added to text1.text box

    Al.
    Last edited by aratti; - 24th December 2009 at 09:09.
    All progress began with an idea

  7. #7
    Join Date
    Dec 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Thanks for the clarification, well I put it with intent for all who would help them to understand, because if everyone does not know how to program in VB.
    Anyway still not working,
    I put a Timer every 1ms buffer but I read nothing at all, for me the bug is in the sequence of programming the PIC, but no where with. "GoSub DoUSBOut" or "Gosub DoUSBIn" I've changed so many ways not to do.
    For the program to read the VB inside PIC and see it in textBox.

    THX

Similar Threads

  1. Forward Serial Data from pic to pc
    By Muller in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd September 2008, 21:46
  2. Replies: 11
    Last Post: - 12th July 2008, 02:36
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  4. send serial data to PIC 16f84 ausing VB6
    By win_832001 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2006, 21:14
  5. send and receive data using pic 16f84a
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2006, 20:12

Members who have read this thread : 1

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