PDA

View Full Version : Send data PIC to PC



konter
- 23rd December 2009, 05:29
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

mackrackit
- 23rd December 2009, 08:38
Sorry, either you are on the wrong forum or you are using the wrong basic.
This is a Pic Basic forum.

konter
- 24th December 2009, 04:29
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

mackrackit
- 24th December 2009, 04:41
PBP is not from Crownhill.
DIM and DECLARE are not part of PBP.
As far as I know.....

Maybe PROTRON ? PROTON ?

Archangel
- 24th December 2009, 06:49
Try here: http://www.picbasic.org/forum/

aratti
- 24th December 2009, 09:00
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.




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




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.

konter
- 25th December 2009, 22:04
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