nrCommm.AfterReceive is too slow, how can i speed it up

Started by thorsten, November 07, 2018, 12:02:55 pm

Previous topic - Next topic

thorsten

Hello,

i need a soloution to check an Comunication between 2 Devices.



Device1  <->  RS485ComPort ( PC with nrComm ) RS485ComPort  <->  Device2

If i use the Event   nrCommm.AfterReceive the Device2 go in TimeOut.

I use 2 nrComms:
procedure TForm1.nrComm1AfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
begin
     nrComm2.SendData(Buffer, Received);
end;


and
procedure TForm1.nrComm2AfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
begin
     nrComm1.SendData(Buffer, Received);
end;


Is it possible to speed up this function or is there another way here?

Thorsten

thorsten

I try this to speed it up.

// Testfunktion to SpeedUp
procedure TForm1.nrComm1TraceState(Com: TObject; Event: TTraceStates);
var
inBuffer : array[0..255] of byte;
inZahl   : cardinal;

begin

  if tsRxChar  in Event then
  begin
  Memo5.Lines.Add('tsRxChar');
   nrComm1.Read(@inBuffer,1);
    nrComm2.SendData(@inBuffer,1);
  end;

end;


However, the event was not active, "Memo5.Lines.Add ('tsRxChar');" was never reached

I need an idea to accelerate the whole thing.


Thorsten

Roman Novgorodov

Hello

I do not understand why you do that.

Let me explain a little details.

The tsRxChar flag appears if there are some data in input buffer of port.
TnrComm monitors tsRxChar flag in separated thread and handles all incoming bytes.
These bytes are available in OnAfterReceive event.
You do not need to monitor tsRxFlag and read data from serial port buffer.

Please take a look at codes_demo   Demos\Codes\codes_demo.dpr

You can not to do that faster than the TnrComm internal thread.

Also you can clear Terminal property and set UseMainThread to False for increase speed of incoming data processing.

And then TnrComm.OnTraceState is not occurs on tsRxFlag state, only OnAfterReceive raises on  tsRxFlag.

Hope this helps.

Roman Novgorodov
DeepSoftware llc

DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.