Can someone help me with the sourcecode?
Printable View
Can someone help me with the sourcecode?
Maybe. If you first post the Code you need help with...
I want to receive 3 values and display it in VB can you help with the source code, an example code will help
I have no idead on the code because I dont know how to do vb6 with serial communication. where to start? how to use mscomm?
google will get you several examples as will a search of this site
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:
Instread of debug.print a$ you would probably do something else with the three received 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
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.
Depends on how you are sending them. If you can put a \ character in between each part, you could receive one packet and split it up
I'am sending them in different line. Like:
342
345
423
I use the this format in sending. I would like to assign variable to each of them.
OR should I send the data in this format 345\324\435?
PLease help
Here's a sample for you.
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
WHAT is VbCrlf? I'am receiving it from a micro-controller with c programming.