VaComm misses some incoming data

have been experiencing a problem and am unable so far to solve it
so my project is badly held up. I am running TMS async v 2.1.0.1 under
C++ buiilder 10.3.3 Community edition. I have external hardware sending
RS232 data to C++ Builder running on a Dell vostro 230 with windows 7 64
bit.

The incoming data stream is being detected by the
VaComm1Rxchar routine and ceRxChar is set TRUE in the MonitorEvents
property. I find that it occasionally (about 10% of the time) misses
some incoming data bytes and initially ascribed this to the warning that
is in the manual that this may happen if RXChar is used for processing
the data and is taking too long. I have a counter in my external
embedded software that verifies that the correct number of bytes are
being sent to the PC. For test I have stripped down my VaComm1Rxchar
routine in C++ Builder so that it only handles the initial handshaking
to the external hardware and then only counts the number of incoming
bytes. When it receives the DATA_FINISHED code it displays the number of
bytes received. It still misses some bytes sometimes so I thought the
rest of my program may be distracting the serial port in some way.  I
would like to allow the data to accumulate in the VaComm buffer instead
and then read it out from there. However, The call to
Form1->VaComm1->ReadBufUsed() consistently returns zero although
the manual says that the onRxChar event is the 'Event triggered when a
character was received and placed in the input buffer'.
The stripped down code I am using for the VaComm1Rxchar routine is as below:

void __fastcall TForm1::VaComm1RxChar(TObject *Sender, int Count)
{
    int16_t bufcount;

    Form1->VaComm1->ReadChar(global_rs232_response);
    if(global_rs232_response ==  DATA_ACKNOWLEDGED)
    {
        Form1->VaComm1->WriteChar(DATA_ACKNOWLEDGED);
    }
    else
    {
        if((global_rs232_response !=  DATA_FINISHED)
                            && (global_rs232_response != DATA_ACKNOWLEDGED))
        {
            ++global_diagnostic;
        }
    }

    if(global_rs232_response ==  DATA_FINISHED)
    {
        bufcount = (int16_t)Form1->VaComm1->ReadBufUsed();
        Form1->Label4->Caption = bufcount;
      Form1->Label8->Caption = global_diagnostic;
    }
}     

Can you make any suggestion as to why I am missing some bytes sometimes and why the buffer appears not to be receiving the data?

The most common reason for data to be missed is a read buffer overflow.

How much data is the device sending? How fast is it sending data compared to the speed you read out?

The external hardware sends 1152 bytes. The send and receive baud rates are set at 9600 baud. The  data is read as fast as VaComm1RxChar() and readChar() can respond to it. After the data is read then ReadBufUsed always returns zero.
I suspect that I do not really understand what VaComm1 is doing. Does it remove each byte from the buffer when ReadChar() reads it into a variable or should the data remain in the buffer in which case how can I access it?
If I switch off ceRxChar in MonitorEvents after the initial handshaking and connection to the external hardware  is done should the data then accumulate in the buffer from that point?  If so then how can I detect that the DATA_FINISHED byte has been received so that I can start reading the buffer?

regards.

The data is removed from the buffer. 
Can you visualize the value for ReadBufUsed() as well as ReadBufFree() for every character read, i.e. also not only when (global_rs232_response ==  DATA_FINISHED) and check if this value ReadBufFree() is never close to zero?
 

Hello Bruno. Sorry for the slow reply but I have been diverted onto other things for the last week or so.  I get the impression that VaComm1->MonitorEvents is a structure. I guess that before I can check the amount of data in the buffer I need to turn off the ceRxChar member of MonitorEvents otherwise the data is removed from the buffer as soon as it is received. However, I do not know what syntax to use in order to switch the members of MonitorEvents on or off. I have no help file to prompt me in this respect. Should there be a helpfile attached to TMSAsync? If so where can I find it and how can I install it?

There is a hardware buffer and a software buffer. The hardware buffer is typically much smaller (8 or 16 bytes is typical). Data loss is in most cases not related to hardware buffer overflow. TVaComm uses internally a thread to keep reading the hardware buffer and fill the software buffer. ReadBufUsed / ReadBufFree indicates the number of bytes in this software buffer. 

The developers guide for TMS Async is here:
http://www.tmssoftware.biz/download/manuals/TMS%20Async.pdf