Re: recieving 3 value in uart
btw My coding style for com is a bit old fashioned. Largely because I have been doing this for a long time. As I have mentioned before the on Comm events was not always as realible as it is now and as mentioned here not all devices behave the same way. The methods I use have been working for me in every case for the last 15 years with evey kind of device I have tried, blue tooth, usb adapters, digi boards internal and external modems and so on. I haven't saw a single error in the code for over 14 years now and my major serial program that I released 14 years ago runs on hundreds if not thousands of systems without a single bug being reported after the first 3 months. [bugs related to init string for off brand modems under windows 95]
Re: recieving 3 value in uart
Quote:
Originally Posted by
WoF
@DataMiser: Your assumption is wrong.
You can do at ANY time a
a$=MSComm1.Input without producing an error, even if the input buffer has no characters. In this case .Input returns an empty string without giving an error.
The reason that RLine = RLine + MSComm1.Input produces an error must lie elsewhere. Port not accessible or something.
@feitanx: First I suggest you change the OnComm like this:
Code:
Private Sub MSComm1_OnComm()
Dim p%
Static RLine$
Select Case MSComm1.CommEvent
Case vbMSCommEvReceive
RLine = RLine + MSComm1.Input
p = InStr(RLine, vbCr) ' Put your break point here and see what you get.
If p Then ' a complete record with three numbers has been received now
Dim a$()
a = Split(Left$(RLine, p - 1), "/") 'split the line into the three numbers
If UBound(a) = 2 Then
Text1.Text = a(0) 'get first number
Text2.Text = a(1) 'get second number
Text3.Text = a(2) 'get third number
End If
RLine = Mid$(RLine, p + 1) 'reset the receiver variable for the next line
End If
Case Else
MsgBox "MSComm event: " + CStr(MSComm1.CommEvent), vbOKOnly, "Error"
End Select
End Sub
This will only input when a character is received.
Other mscomm events will be notified in a messagebox so as we can see what the error can be.
I think you have to declare the vbMSComm events. The constants do not seem to come automatically when MSComm control is put to the form. So you have to add these private constants:
Code:
Private Const vbMSCommEvSend = 1
Private Const vbMSCommEvReceive = 2
on top of your form's code.
There still error with this one, the error is still at "RLine = RLine + MSComm1.Input"
the error occur everytime I turn on the sending or I turn the uart sending on or I send data
Re: recieving 3 value in uart
So what really is wrong? In the other code the error is at "InBuff = MSComm1.Input"
I think the port is accessible as I can see the output through a program called RealTerm a bit similar to hyperterminal.
Re: recieving 3 value in uart
Just for curiousity try using the test for the buffer as I suggested.
Code:
If MSComm1.InBufferCount>0 then
RLine = RLine + MSComm1.Input
p = InStr(RLine, vbCr) ' Put your break point here and see what you get.
If p Then ' a complete record with three numbers has been received now
Dim a$()
a = Split(Left$(RLine, p - 1), "/") 'split the line into the three numbers
If UBound(a) = 2 Then
Text1.Text = a(0) 'get first number
Text2.Text = a(1) 'get second number
Text3.Text = a(2) 'get third number
End If
RLine = Mid$(RLine, p + 1) 'reset the receiver variable for the next line
End If
End If
Re: recieving 3 value in uart
btw what are your port settings at each end now?
Re: recieving 3 value in uart
Still error on this line " RLine = RLine + MSComm1.Input"
says error reading comm device
My setting is "9600,N,8,1" on both ends
maybe there are other settings that should be set, should I enable DTR and EOF? or any other settings that should be set
The error happens when I turn the UART sending on or when the UART is sending
Re: recieving 3 value in uart
Private Sub MSComm1_OnComm()
Dim p%
Static RLine$
Select Case MSComm1.CommEvent
Case vbMSCommEvReceive
RLine = RLine + MSComm1.Input
p = InStr(RLine, vbCr) ' Put your break point here and see what you get.
If p Then ' a complete record with three numbers has been received now
Dim a$()
a = Split(Left$(RLine, p - 1), "/") 'split the line into the three numbers
If UBound(a) = 2 Then
Text1.Text = a(0) 'get first number
Text2.Text = a(1) 'get second number
Text3.Text = a(2) 'get third number
End If
RLine = Mid$(RLine, p + 1) 'reset the receiver variable for the next line
End If
Case Else
MsgBox "MSComm event: " + CStr(MSComm1.CommEvent), vbOKOnly, "Error"
End Select
End Sub
regarding this code I always get an MSComme event:2 error message
although I dont get a "RLine = RLine + MSComm1.Input" error
Re: recieving 3 value in uart
That is not an error message. Apparently you do not have the constant defined
vbMSCommEvReceive=2
Re: recieving 3 value in uart
when I set the constant:
"Private Const vbMSCommEvSend = 1
Private Const vbMSCommEvReceive = 2"
I get an error on the:
"RLine = RLine + MSComm1.Input"
I still get an error on the same line "RLine = RLine + MSComm1.Input". How to fix this? I keep on getting the same error.
Should I enable the DTREnable settings?
Re: recieving 3 value in uart
Well if you tried the inbuffer count and still got an error then that would indicate to me that the driver for your USB device may be at fault.
Inbuffercount>0 insures that there is in fact data there waiting to be read and then if an attempt to read this data is causing an error something is going on outside your code, likely the driver for your device.
I would suggest checking for updated drivers and/or seeing if there is any forum set up for support on this device you are using.
Re: recieving 3 value in uart
Quote:
Originally Posted by
feitanx
Should I enable the DTREnable settings?
I doubt that it will help but it never hurts to try.
The fact that data is there and the read fails points to other issues however
Re: recieving 3 value in uart
btw what OS are you running?
what service pack are you using on VB6?
Re: recieving 3 value in uart
I'd agree that there could be a problem with the device driver, but only in conjunction with MSComm.
If you have the Case vbMSCommEvReceive clause, the statement
RLine = RLine + MSComm1.Input
is only executed when something was received. In this case also MSComm1.InBufferCount would be > 0.
Thus reading from MSComm1.Input should not produce an error. No handshake will remedy that matter.
What makes me wonder is, that the terminal program would receive everything properly...
Re: recieving 3 value in uart
I'm running on windows 7 , I dont know about the service pack but I'm using the portable version, can it affect?Please help
should the inputlen=0?
Re: recieving 3 value in uart
Unless I was wrong, I called it with #67
The USB connection is NOT the same as a hardware serial port, connected to the motherboard.
I've seen more problems with these then were worth even trying to fix.
Like in the old days. I was told that MIDI devices wouldn't work with USB, because they connected thru the serial port. Because I wanted to record MIDI on my laptop, I figured out how to do it. In time for the NEXT summer. :(
That was back in the Windows 3.1 days, though