Click to See Complete Forum and Search --> : MSComm, Timer and OnComm Event problem
moydheen
March 21st, 2001, 08:34 PM
Hi Codegurus,
I'm communicating through a serial port using mscomm control. I tried both the timer and the oncomm event for receiving the messages from the serial port.
The problem is:
1. I have a button in my form when i press the button it will send a message for eg:"A" to the serial port and to the corresponding device. The device will send me back the answer as "B".
2. The above step is working fine initially. But Some Times if i press the button, I'm getting the old pressed message only. I mean if recd a message 10 secs back, the same message is coming again instead of original expected message.
I dunno where the problem is.
Any Help in this will be greatly appreciated.
Thanks!!
moydheen
ksup
March 21st, 2001, 10:50 PM
Use in mscomm_oncom()
if mscomm.comevent=comRecieve then str = str & mscomm.input}}do your stuff clear the str you can use mscomm.inBufferCount =0 to clear the buffer. you can also do it like mscom.output = "hello": then a loop with str = str & mscomm.input in it break when you get enough chrs
Markus W.
March 22nd, 2001, 02:21 AM
There may be several reasons for your problem.
- do you send what you intend to send?
- does your device reply what you expect to get?
- do you read all data from serial input buffer (InputLen property = 0)
- try to clear serial input buffer and any related string buffer before sending
Perhaps you can post some code fragment how you send/receive?
moydheen
March 22nd, 2001, 11:53 AM
Thanks for ur reply!!!
"Try to clear serial input buffer and any related string buffer before sending"
Is there any way to clear the serial input buffer, becoz I checked my code line by line, where actualy I'm getting problem is at the line
Private Sub tmrWaitInput_Timer()
strReceived = mscomm1.Input 'Here I'm getting problem
End sub
In the above code when i get into that line, instead of showing the newly received buffer content, its showing the old one, after one more iteration sometimes fewmore iterations its showing the actual newly received content.
Thanks!!!
shiek
Markus W.
March 23rd, 2001, 01:15 AM
You can clear the serial input buffer by InBufferCount property.
MSDN
InBufferCount refers to the number of characters that have been received by the modem and are waiting in the receive buffer for you to take them out. You can clear the receive buffer by setting the InBufferCount property to 0.
But normaly, and if InputLen property is set to 0, you should get all data by Input property. So the serial buffer should be clear after reading.
Dave Mountain
August 1st, 2001, 06:33 AM
Wonder if you've come across my problem in your MSComm work :-
I send a string of say 50 characters to my 'OnComm' event handler . The event triggers for every 8 characters i.e I get 7 receive events. (6*8 + 1*2) If I put a breakpoint in the code just before reading the input then I get the whole string read for a single receive event (which is what I want) Some sort of timing problem ?? I have 'InputLen = 0' and 'RThreshold = 1'. Any ideas ??
Thanks in advance,
Dave.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.