View Issue Details

IDProjectCategoryView StatusLast Update
0036566FPCRTLpublic2020-01-13 17:21
ReporterArmin LinderAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformRaspberry Pi 3+OSRaspbianOS Version10 (Buster)
Product Version3.0.4Product Build3.0.4+dfsg-22+rpii 
Target VersionFixed in Version 
Summary0036566: serReadTimeout hangs indefinitely if serial device is disconnected
DescriptionI use this line of code to read serial data from a serial device (/dev/ttyACM0)

Const
  GAUGE_VALUE_LENGTH = 8; // Sign + 5 Digits + CR + LF
  GAUGE_RESPONSE_TIMEOUT = 500;
  MAX_BUFFER = 100;

var
  ByteBuffer: array[0..MAX_BUFFER] of byte;
  StringBuffer: ShortString absolute ByteBuffer;

... (loop until terminated)
    if _ComHandle <> 0 then
    begin
      // query the gauge
      SerFlushInput(_ComHandle);
      StringBuffer := '?';
      SerWrite(_ComHandle, StringBuffer[1], 1);
      // read response
      // For debugging -----
      isReading(true);
      // End debugging -----
      StringBuffer[0] := chr(SerReadTimeout(_ComHandle, ByteBuffer[1], GAUGE_VALUE_LENGTH, GAUGE_RESPONSE_TIMEOUT));
      // For debugging -----
      isReading(false);
      Sleep(500);
      // End debugging -----
      if Length(StringBuffer) = GAUGE_VALUE_LENGTH then
        begin
        SetGaugeValue(strToInt(LeftStr(StringBuffer,6)));
        end
      else
        CloseCom();
    end;
...

Generally this routine works well on WIndows (10) and Raspbian. Unfortunately, on Raspbian, if I disconnect the device, upon next call of this command, it does never return, nor throw any exception --> the program hangs. Re-Plugging the device doesn't help, I need to restart the program. On Windows everything works, after the timeout has expired, the call returns 0.
Steps To ReproduceCall SerReradTimeout in a loop and disconnect the device. the call won't ever return.
Additional InformationIf this info isn't enough to reproduce the problem I will happily drag together a short sample.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2020-01-13 16:41 Armin Linder New Issue