Stub CAT serial on macOS

This commit is contained in:
2026-05-24 16:31:49 +03:00
parent ffb735756e
commit 03693dc0f4
+24
View File
@@ -18,11 +18,17 @@ unit CATSerial;
{$MODE Delphi} {$MODE Delphi}
{$ENDIF} {$ENDIF}
{$IFDEF DARWIN}
{$DEFINE CAT_SERIAL_STUB}
{$ENDIF}
interface interface
uses uses
Classes, SysUtils, Classes, SysUtils,
{$IFNDEF CAT_SERIAL_STUB}
Serial, // FPC cross-platform serial unit Serial, // FPC cross-platform serial unit
{$ENDIF}
{$IFDEF MSWINDOWS}Windows,{$ENDIF} {$IFDEF MSWINDOWS}Windows,{$ENDIF}
SyncObjs, SyncObjs,
CATEngine; CATEngine;
@@ -43,6 +49,10 @@ type
Parity: TCATSerialParity; Parity: TCATSerialParity;
end; end;
{$IFDEF CAT_SERIAL_STUB}
TSerialHandle = PtrInt;
{$ENDIF}
TCATSerialPort = class; TCATSerialPort = class;
{ TCATSerialThread — per-port listener thread } { TCATSerialThread — per-port listener thread }
@@ -107,11 +117,16 @@ end;
function TCATSerialThread.TryOpenPort: Boolean; function TCATSerialThread.TryOpenPort: Boolean;
var var
{$IFNDEF CAT_SERIAL_STUB}
cfg: TCATSerialConfig; cfg: TCATSerialConfig;
h: TSerialHandle; h: TSerialHandle;
par: TParityType; par: TParityType;
{$ENDIF}
begin begin
Result := False; Result := False;
{$IFDEF CAT_SERIAL_STUB}
Exit;
{$ELSE}
cfg := FOwner.Config; cfg := FOwner.Config;
h := SerOpen(cfg.PortName); h := SerOpen(cfg.PortName);
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
@@ -131,6 +146,7 @@ begin
FHandle := h; FHandle := h;
FOwner.Handle := h; FOwner.Handle := h;
Result := True; Result := True;
{$ENDIF}
end; end;
procedure TCATSerialThread.ProcessBuffer; procedure TCATSerialThread.ProcessBuffer;
@@ -156,6 +172,9 @@ var
ch: Byte; ch: Byte;
n: LongInt; n: LongInt;
begin begin
{$IFDEF CAT_SERIAL_STUB}
Exit;
{$ELSE}
if not TryOpenPort then Exit; if not TryOpenPort then Exit;
try try
while not Terminated do begin while not Terminated do begin
@@ -173,6 +192,7 @@ begin
FOwner.Handle := -1; FOwner.Handle := -1;
{$ENDIF} {$ENDIF}
end; end;
{$ENDIF}
end; end;
{ ── TCATSerialPort ────────────────────────────────────────────────────────── } { ── TCATSerialPort ────────────────────────────────────────────────────────── }
@@ -220,6 +240,9 @@ end;
procedure TCATSerialPort.SendStr(const S: string); procedure TCATSerialPort.SendStr(const S: string);
var buf: AnsiString; var buf: AnsiString;
begin begin
{$IFDEF CAT_SERIAL_STUB}
Exit;
{$ELSE}
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
if FHandle = INVALID_HANDLE_VALUE then Exit; if FHandle = INVALID_HANDLE_VALUE then Exit;
{$ELSE} {$ELSE}
@@ -234,6 +257,7 @@ begin
// ignore write errors (port may have been closed) // ignore write errors (port may have been closed)
end; end;
FLock.Release; FLock.Release;
{$ENDIF}
end; end;
{ ── TCATSerialManager ─────────────────────────────────────────────────────── } { ── TCATSerialManager ─────────────────────────────────────────────────────── }