SetRThreshold does not works as expected

Tech-Archive recommends: Fix windows errors by optimizing your registry



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!
.



Relevant Pages

  • Re: send & MSG_DONTWAIT
    ... The application protocol can't control the receive window. ... That's why TCP permits the receiver to decide never to accept a ... "complete frame" if it doesn't want to. ... TCP transport and neither has the receiving application. ...
    (comp.unix.programmer)
  • [patch] r8169: fix crash when large packets are received
    ... Michael Tokarev reported receiving a large packet could crash ... When a frame larger than what was allocated by driver is received, ... Fix is to tell to NIC what is the maximum size a frame can be. ...
    (Linux-Kernel)
  • Re: SetRThreshold does not works as expected
    ... My application is receiving binary data from a device connected to ... The Frames have different lengths, so I Set SetRThreshold to 1, to ... Example: The device send me this frame: A2 03 A5 ... time OnCommEvent fires up: ...
    (microsoft.public.vc.mfc)
  • Re: send & MSG_DONTWAIT
    ... TCP transport and neither has the receiving application. ... That's why an "all or nothing" non-blocking send doesn't exist. ... the last 'complete frame' has been received and then, ...
    (comp.unix.programmer)
  • Re: 20 bit UART for 5912OSK
    ... I know that the UART is capable of handling more than the usual 8 data bits. ... I know I need to insert a start and stop bit to make it into a frame but I am not well versed in ANSI C. ... For 10 total bits this means the frequencies must agree within at least 5%, assuming exact accuracy in locating the start bit. ... "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. ...
    (comp.arch.embedded)