<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><title></title>

<meta http-equiv="Content-Style-Type" content="text/css">
</head>
<body>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt">On 31 Aug 2020 at 9:38, Bo Berglund via fpc-pascal wrote:</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> On Fri, 21 Aug 2020 21:03:31 +0200, Bo Berglund via fpc-pascal</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> <fpc-pascal@lists.freepascal.org> wrote:</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> >Instead I need to add a thread for reading data so I can have an event</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> >driven reception of data. It would read available data and fire off a</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> >NotifyEvent to handle the incoming data in the main application.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> I have now started to implement a simple "fpserialport" class using</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> the built-in serial unit and I am trying to add a reading thread so I</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> can get an OnRxData event which is needed by many of the non-GUI</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> applications I want to port to Fpc/Lazarus.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt">I have been using the FPC serial unit for some years, and have never experienced any issues.</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt">Usually I read data this way (if it is text).</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt">I have been using this on both Windows and Linux (Raspberry Pi) for some years.</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt">This is a small bit of a specific program that reads answers on an RS485 bus.</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt">Carsten</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>Var</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>  vSioCnt:integer=0;</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>  vRetrySioRead:LongInt=0;</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>  vSioBuf:shortstring;</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>  vRs485Sio:LongInt=0;</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i><br>
</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i><br>
</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>  repeat</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>    vSioCnt:=serial.SerRead(vRs485Sio,vSioBuf[1],255);</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>    if vSioCnt>0 then                                     {Has 
data been read}</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>    begin</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>      setlength(vSioBuf,vSioCnt);</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>      vSioStringS:=vSioStringS+vSioBuf;       {Move data into ansi string}</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>      vRetrySioRead:=6;                                   {Try 
in 6/100 if more data is coming}</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>    end else if vRetrySioRead<>0 then sleep(10);                                         {Wait 
for 1/100 sec.}</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>    if vRetrySioRead<>0 then</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>      dec(vRetrySioRead);</i></b></span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><b><i>  until (vSioCnt<=0) and (vRetrySioRead=0);     {There was no more data}</i></b></span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt"><b><i><br>
</i></b></span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> Bo Berglund</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> Developer in Sweden</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> _______________________________________________</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org</span></font></div>
<div align="left"><font face="Arial" color="#7f0000" size="2"><span style=" font-size:10pt">> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</span></font></div>
<div align="left"><font face="Arial" size="2"><span style=" font-size:10pt"><br>
</span></font></div>
<div align="left">  </div>
</body>
</html>