SetRThreshold does not works as expected
- From: clinisbut <clinisbut@xxxxxxxxx>
- Date: Tue, 22 Jan 2008 06:05:25 -0800 (PST)
My application is receiving binary data from a device connected to
uart and have to analyze it byte to byte to identify frames.
I'm using MSCom Object from Active-X.
This is the code I use to open the serial port:
m_Comm.SetCommPort( 7 );
m_Comm.SetSettings( "4800,o,8,1" );
m_Comm.SetInputMode( 1 );
m_Comm.SetRThreshold( 1 ); //Event when data received every 1 byte
m_Comm.SetInputLen( 1024 );
m_Comm.SetInBufferCount( 0 );
m_Comm.SetPortOpen( true );
The Frames have different lengths, so I Set SetRThreshold to 1, to
OnCommEvent fires every single byte is received.
That's what I want to achieve.
The first "problem" is that OnCommEvent doesn't fires up every 1 byte,
well... only sometimes, usually it fires up every 2-3 bytes, but this
is not a problem if I receive the entire frame in little pieces.
Example: The device send me this frame: A2 03 A5
I receive this:
1 time OnCommEvent fires up: A2 //I get only 1 byte, that is
correct
2 time OnCommEvent fires up: 03 A5 //Although I receive 2 bytes, I
finally receive the entire frame, that's not a problem
Although this is not a hard problem, I would like to know why this is
happening. I setted SetRThreshold to 1, I don't understand this
behaviour.
The second problem is more serious.
The device sends me a frame every time the computer asks for
something, else it's in silence.
Well, the problem is sometimes I don't receive the entire frame, just
a piece. I get the other piece joined with the next answer from
device.
Example:
I ask for something an Device send me this frame: A2 03 A5
I receive this:
1º time OnCommEvent fires up: A2
2º time OnCommEvent fires up: 03
And that's all, I can't get byte "A5" until next answer from Device.
See it:
I make another request to Device: A3 04 A6
I receive this:
1º time OnCommEvent fires up: A5
2º time OnCommEvent fires up: A3 04
3º time OnCommEvent fires up: A6
I can assure that device send me the entire frame the first time.
I know there is a better way to read and write from serial ports, but
this is my only problem, I don't want to rewrite almost the entire
code of my app just for this problem until have no alternative.
I'm tracing with m_Comm.GetInBufferCount() and in the last example
shows this:
I ask for something an Device send me this frame: A2 03 A5
I receive this:
1º time OnCommEvent fires up: //GetInBufferCount() returns 1, the byte
received is A2
2º time OnCommEvent fires up: //GetInBufferCount() returns 1 , the
byte received is 03
And that's all, I can't get byte "A5" until next answer from Device.
See it:
I make another request to Device: A3 04 A6
I receive this:
1º time OnCommEvent fires up: //GetInBufferCount() returns 1, the
byte received is A5
2º time OnCommEvent fires up: //GetInBufferCount() returns 2, the
bytes received are A3 04
3º time OnCommEvent fires up: //GetInBufferCount() returns 1, the byte
received is A6
GetInBuffer() always returns the correct value acording the bytes I
receive from uart, but this doesn't mean that's the correct value!
.
- Follow-Ups:
- Re: SetRThreshold does not works as expected
- From: Alexander Grigoriev
- Re: SetRThreshold does not works as expected
- Prev by Date: Re: Reentrancy issue
- Next by Date: Re: SetRThreshold does not works as expected
- Previous by thread: Reentrancy issue
- Next by thread: Re: SetRThreshold does not works as expected
- Index(es):
Relevant Pages
|