PDA

View Full Version : Serin to Vb



Johansch
- 27th June 2007, 17:11
Hi,

I am testing the serin function with a vb program that I have written.
When I send 123456789 for example I then only get back 13579 and I am losing 2468 all the even nubers? I am using the pic16f84a and the code is like this

include "16f84a.inc"


B0 var Byte

Srt:Pause 1000
serout portb.7,N2400,["Hello 123",13,10]
goto wait1

wait1: Serin portb.6,N2400,B0

loop: Serout portb.7,N2400,[B0]
Goto wait1

Can any one help
Please !

Thanks

skimask
- 27th June 2007, 18:06
When I send 123456789 for example I then only get back 13579 and I am losing 2468 all the even nubers?

Probably because, when your program receives "1", it sends out "1", but at the same time, it can't receive "2" because it's busy sending "1". Then it's done sending "1", "2" has already past by but "3" gets received. Then "3" gets sent, but now "4" is on the way. But "4" gets missed because "3" is being sent out.

Try 'pacing' your sending program. Send the characters with a bit of a delay.
Or receive a bunch of characters at a time using the STR instead of a single byte at a time.

Johansch
- 28th June 2007, 16:36
Hi skimask,

Thanks for your replay!
Ok I have tried both timing and STR function, but no luck all I want to do is to loop the data back that I have send to the pic. I am new to micro programming, so maybe I am not placing the timing in the right place?
Do you maybe have a example for me?

Thanks

mackrackit
- 28th June 2007, 17:03
Sounds like a problem in the VB code.

How do you have it setup?

Ron Marcus
- 28th June 2007, 17:42
B0 var Byte

Srt:Pause 1000
serout portb.7,N2400,["Hello 123",13,10]
goto wait1

wait1: Serin portb.6,N2400,B0

loop: Serout portb.7,N2400,[B0]
Goto wait1

Can any one help
Please !

Create an array like
B var byte[16]
array_count var byte
Then use serin with a time out. I don't have the book so you need to do a little tweaking.

Receive:
array_count = 0
get_byte:
Serin portb.6,N2400,500,send_char,B[array_count] ;wait for char for 500 ms, then send received chars.
send_char:
if array_count = 0 then get_byte
Serout...blah blah
goto Receive

Ron

Johansch
- 29th June 2007, 14:21
I don't think vb is the problem. I have treid 3 different serial vb examples and all off them is the same, but here is the code

Private Sub Command2_Click()
MSComm1.Output = Text3.Text + vbCr
End Sub


Private Sub Form_Load()
MSComm1.PortOpen = True

End Sub


Private Sub Timer1_Timer()
Dim stemp As String

MSComm1.InputLen = 0
If MSComm1.InBufferCount Then
With frmMain
stemp = stemp + MSComm1.Input

List1.AddItem stemp

Text1.Text = stemp & vbCrLf
Text2.Text = stemp

End With
End If

End Sub

Johan

skimask
- 29th June 2007, 14:27
Well, what happens if you just forget about vB for awhile, and just use Hyperterminal (or whatever)...
In other words, can you make it work the other way around, the PIC echo's everything the PC sends to it....

Johansch
- 29th June 2007, 14:57
Yes with hyperterminal my pic do echo the characters back that I am typing in, but with hyperterminal am I not sending byte by byte as a type ? still new with this
The only way I get this to work is to create a B0 to B9 var, but with the end program I am not going to know how manny characters i am going to get
Will pic's with a Uart maybe help me?

mister_e
- 29th June 2007, 15:11
You don't want to use Timer for that but CommEvents and comEVReceive.

http://www.rentron.com/receiving_data.htm

If you want, i have few PDF, just drop me your e-mail in my PM.

T.Jackson
- 29th June 2007, 16:34
Forget about MSComm & timers. Have a look here: http://www.picbasic.co.uk/forum/showthread.php?t=6356