To receive serial input you have to use the MSComm control.
You go to Project->Components and add 'Microsoft Comm Control 6.0' to your toolbox.
Now you have MSComm available and can put one to your Form for usage.
Check the parameters and settings.
To receive characters you set the .RThreshold property to 1.
This has the effect that for every received character the OnComm() event of the control will fire.
Assume your control is Named MSComm1, then you might use this very basic code to receive characters:
Code:
Private Sub MSComm1_OnComm()
Static a$
a$ = a$ + MSComm1.Input
If Len(a$) = 3 Then
debug.print a$
a$=""
End If
End Sub
Instread of debug.print a$ you would probably do something else with the three received characters.
Don't forget to either check the oncomm to see why it fired or check the inbuffercount before issuing the input command otherwise you could be trying to read when there is nothing there to read.
Yes. That'd be the next step of higher sophistication using a Select Case to react on distinct reasons of the OnComm() to have fired.
But the above simple code still would work fine. If there is no .Input available, well, then there is none. It will wait for the next valid character, until they are three.
What I mean is that I will receive 3 different values in uart in ASCII and convert each of them to another value. Is the code still fit? or it needs a modification
And also the value that I will be receiving comes from a source that keeps on transmitting.
Last edited by feitanx; June 5th, 2010 at 08:08 AM.
If you are able to send this format
234/345/456
123/345/678
everything is rather easy, provided you send complete lines with 3 numbers each.
After the third number a vbCrLf must be sent to definitely delimit a group of 3 numbers.
In OnComm you can do then:
Code:
Private Num1%, Num2%, Num3%
Private RLine$
Private Sub MSComm1_OnComm()
RLine = RLine + MSComm1.Input
If Len(RLine>2) Then
If Right(RLine,2) = vbCrLf Then ' a complete record with three numbers has been received now
dim a$()
a = Split(RLine, "/") 'split the line into the three numbers
Num1 = a(0) 'get first number
Num2 = a(1) 'get second number
Num3 = a(2) 'get third number
RLine = "" 'reset the receiver variable for the next line
End If
End If
End Sub
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.