Write to Port OnRxChar Event

Hi,

I'm solving problem where sometimes our reply to device doesn't get trough. This happens in less than 0.1% of cases but still are quite a problem

Is it okay send data on OnRxChar Event or should it be done outside of event?

for example we have
onRxChar..

 s := FSerial_VaComm.ReadText;
 received_data := received_data+ s; 
  if Data_is_ok(received_data)  then
    FSerial_VaComm.WriteText(ACK)
else
    FSerial_VaComm.WriteText(NACK)



It should be OK to write from OnRxChar. Do you check though you're not writing in a full write buffer?

You can check this with vacomm.WriteBufFree: integer;

in this case I have a very strong feeling that output buffer cannot be full, because reply is only ACK or NACK and previous acks have been received. 

I also made simple loop  test containing three states with that device and didn't get significant difference between replying outside on RxChar or inside onrxchar. Both cases run over 60k tests successfully. 


When you send the data, you should also get at some point that VaComm.WriteBufUsed gets back to zero when all bytes are transmitted. Do you see this? If some bytes are stuck in the VaComm write buffer, can there be some reason your receiver indicates it cannot longer accept more data?