On 31 Aug 2020 at 9:38, Bo Berglund via fpc-pascal wrote:

> On Fri, 21 Aug 2020 21:03:31 +0200, Bo Berglund via fpc-pascal
> <fpc-pascal@lists.freepascal.org> wrote:
> 
> >Instead I need to add a thread for reading data so I can have an event
> >driven reception of data. It would read available data and fire off a
> >NotifyEvent to handle the incoming data in the main application.
> 
> I have now started to implement a simple "fpserialport" class using
> the built-in serial unit and I am trying to add a reading thread so I
> can get an OnRxData event which is needed by many of the non-GUI
> applications I want to port to Fpc/Lazarus.
> 

I have been using the FPC serial unit for some years, and have never 
experienced any issues.
Usually I read data this way (if it is text).
I have been using this on both Windows and Linux (Raspberry Pi) for some years.
This is a small bit of a specific program that reads answers on an RS485 bus.

Carsten

Var
  vSioCnt:integer=0;
  vRetrySioRead:LongInt=0;
  vSioBuf:shortstring;
  vRs485Sio:LongInt=0;


  repeat
    vSioCnt:=serial.SerRead(vRs485Sio,vSioBuf[1],255);
    if vSioCnt>0 then                           {Has data been read}
    begin
      setlength(vSioBuf,vSioCnt);
      vSioStringS:=vSioStringS+vSioBuf;       {Move data into ansi string}
      vRetrySioRead:=6;                                 {Try in 6/100 if more 
data is coming}
    end else if vRetrySioRead<>0 then sleep(10);                                
        {Wait for 1/100 sec.}
    if vRetrySioRead<>0 then
      dec(vRetrySioRead);
  until (vSioCnt<=0) and (vRetrySioRead=0);     {There was no more data}




> Bo Berglund
> Developer in Sweden
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to