what do you mean by break point?
can you show me the codes
Printable View
what do you mean by break point?
can you show me the codes
It is not code it is a basic debugging method. Click off to the left of a line of code or position your cursor on a line of code and hit F9. This will set a break point on that line. When the program is ran an comes to that line it will stop and you can see what the value of your vars are as well as confirm the code is being executed.
It is starting to seem like you have 0 experience writing and testing code. You really need to play around with it a bit rather than try to get someone to give you 100% working code as you will never learn anything that way.
I thought its a code because there is a break in c programming. anyway in the code a(0) is directly equated to a textbox, should I equate it to a variable first like num1?.
I did it, I break point the line, how to see the value? will it just popup?
place you mouse cursor over the var that you would like to check
keep in mind it has to be one where that was set prior to the current line
what do you mean? I just placed the mouse cursor on the line after I break point but nothing happens
Clearly you did not try very much or you would have saw what I mean.
Run the projram, when it hits the break point the program will stop and the current line will be highlighted. move your mouse over a var in the current line or one of the previous lines and you will see the value of the var.
Again this is basic debugging and you need to play around with this stuff in order to fully understand it. Same is true for the code you have been given here in this thread you need to play around make changes and see what happens so you actually understand how to do it yourself.
Still I did not any value when I place the mouse cursor in the var.
How the the comport by the way should I just leave it open?
Did the code hit the break point?
Which var(s) did you try to test?
Not sure what you mean by just leave it open. Clearly you can not receive any data via a closed port. Still you need to close the port when you are done with it. In many cases this would be when you close the program. In others it would be when you are done receiving data.
Show us the code you are using.
Show us where you put the break point.
What is your RThreshold setting on your MSComm control?
I did not set the RThreshold yet. What should be its setting?
I put the breakpoint in this part:
"Text1.Text = a(0) 'get first number" of the code.
from this code
Private Sub MSComm1_OnComm()
Dim p%
Static RLine$
RLine = RLine + MSComm1.Input
p = Instr(RLine, vbCr)
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 Sub
The RThreshold should be set to 1. If set to 0 the OnComm() event would never fire.
The code looks good so far. Try it with RThreshold = 1.
So I take it that you never hit the break point?
Code:Private Sub MSComm1_OnComm()
Dim p%
Static RLine$
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 Sub
I got an error on this line:
"RLine = RLine + MSComm1.Input"
says error reading comm device
the value of P when I breakpoint is 0
Try this:
Code:RLine = RLine & MSComm1.Input
Are you using a real hardware serial port or a usb adapter?
Still an error in:
"RLine = RLine & MSComm1.Input"
I'am using a Bluetooth serial port profile to connect serially . A Bluetooth module with a serial port profile is used, I connect to the Bluetooth module using a Bluetooth USB dongle.
Probably aren't even connecting thru the USB. Those can cause problems.
what do you mean? I can open the port
Please tell me what could be wrong. Please help.
the problem is most likely that the on comm event is firing for some reason other than data received and the code is trying to receive data when there is not data hence error reading serial port. Seems like I mentioned this could be a problem a few days ago. See post #7
a simple solution is to do a inbuffer check before trying to read any data from the port.
Add the test just before the input attempt and the corresponding end if at the bottom of the code just before the end sub
e.g.
Code:if MSComm1.InBufferCount>0 then
When using the onComm event to handle receiving of data the proper way is to use a case statement. Here is some sample code from MS.
http://support.microsoft.com/kb/194922Code:Private Sub MSComm1_OnComm()
Dim InBuff As String
Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement.
' This template is found in the Example
' section of the OnComm event Help topic
' in VB Help.
' Errors
Case comEventBreak ' A Break was received.
Case comEventCDTO ' CD (RLSD) Timeout.
Case comEventCTSTO ' CTS Timeout.
Case comEventDSRTO ' DSR Timeout.
Case comEventFrame ' Framing Error.
Case comEventOverrun ' Data Lost.
Case comEventRxOver ' Receive buffer overflow.
Case comEventRxParity ' Parity Error.
Case comEventTxFull ' Transmit buffer full.
Case comEventDCB ' Unexpected error retrieving DCB]
' Events
Case comEvCD ' Change in the CD line.
Case comEvCTS ' Change in the CTS line.
Case comEvDSR ' Change in the DSR line.
Case comEvRing ' Change in the Ring Indicator.
Case comEvReceive ' Received RThreshold # of chars.
InBuff = MSComm1.Input
Call HandleInput(InBuff)
Case comEvSend ' There are SThreshold number of
' characters in the transmit buffer.
Case comEvEOF ' An EOF character was found in the
' input stream.
End Select
End Sub
That said testign the InBufferCount as I mentioned will read the data only if data is there which will prevent the error mentioned but as you can see there are several other things that can/will cause the oncomm event to fire.
@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:
This will only input when a character is received.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
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:
on top of your form's code.Code:Private Const vbMSCommEvSend = 1
Private Const vbMSCommEvReceive = 2
Actually I got that directly from Microsoft. The error is caused by issuing a read when no data is present to be read. However I did not read far enough. This error happens only with some 3rd party serial drivers such as the one in use here and typically only happens when there is no data present and a read is issued.
btw if the port was not accessible the error would appear when an attempt is made to open the port.
Ah, ok. Didn't know that.
When you put an MSComm control on, and have standart serial ports you can read as often as you want from the .Input property without error.
But if this is a third party interface problem the above code will prevent that, beause it does only .Input when the fired event truly is a receive event.
On another note while in some or perhaps even many cases you can get away with reading from a port where no data is present it is bad practice to do so. VB let's you get away with a lot but not always. In this case MS says that the serial device must return Success when a read is issued but not all serial devices will do this if there is nothing to read and hence an error whereas if you check the buffer count first the read will not be issued when the buffer is empty and the error should nto occur.
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]
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.
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
btw what are your port settings at each end now?
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
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
That is not an error message. Apparently you do not have the constant defined
vbMSCommEvReceive=2
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?
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.
btw what OS are you running?
what service pack are you using on VB6?
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...
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?
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
What do you mean? can it still be fixed?
The pupose of the USB dongle is to connect to the bluetooth module which runs serial port profile, just like having a serial connection but through bluetooth. This is the setup.
But the thing is it should be able to read because the terminal program can read it.
Have you checked to see if there is a support forum for the hardware in question? Have you checked for drivers? Known issues and so on?
The hardware is just a USB dongle and a Bluetooth module it don't require a driver to run them.
Although I use a software to run the dongle, a software called Bluesoleil.
But this doesnt seem to affect.
What about portable versions and old version of Vb 6, will it affect?
It's not service pack 6, but If I use service pack 6 will it be better?
All USB devices require a driver.
I take it by your response that you have not checked for a support forum or drivers for this device.
You should be using SP6.
The USB device is just a USB dongle, it can run directly. The software I used to run it is Bluesoleil which can run any USB bluetooth dongle.
I will try to enquire if they have some issues similar to this.
So what are the other solution besides this?
You do not seem to understand. All USB devices require a driver. This driver may be included in windows but never the less it is required. I have no idea what this bluesoleil is or what you mean by it can run any USB bluetooth.
Your USB device supposedly is mimicing a serial port and translating that into blue tooth so it should be using a driver that causes it to show up in control panel as a serial port. If you are needing to run this software as well then that could be the root of the problem.
I have both serial USB devices and Serial Bluetooth devices both of which work fine with MSComm and neither require any software other than a driver which is required only by the USB devices in order for the system to know that they are serial ports.
At any rate the problem here would seem to be either that you do not have the proper driver installed or this bluesoleil software.
I think the driver is included in the windows and the software bluesoleil because they automatically install the dongle when it is detected.
I'm using a BLUETOOTH DONGLE by the way to connect to a module that mimics a serial port. The Bluesoleil software is used to detect and assign a port in the for the module.
So what could the problem with this?
Did you look for a support forum for your device?
no forum just email they say that they had no issue regarding similar to this one
The fact that a terminal program like realterm can receive and read the port, it puzzles me where the error could be?
We could start debugging the code, checking things closer.
If you have set up the OnComm() event like we discussed, you can put some debug statements in, like
Code:...
Case vbMSCommEvReceive
debug.print MSComm.InputLen
...