fix build on windows

This commit is contained in:
2026-05-02 13:39:46 +03:00
parent e9d6b70de9
commit 0480c73f3f
3 changed files with 32 additions and 16 deletions
+20 -6
View File
@@ -21,9 +21,10 @@ unit CATSerial;
interface
uses
Classes, SysUtils, SyncObjs,
Classes, SysUtils,
Serial, // FPC cross-platform serial unit
{$IFDEF MSWINDOWS}Windows,{$ENDIF}
SyncObjs,
CATEngine;
const
@@ -120,10 +121,10 @@ begin
{$ENDIF}
case cfg.Parity of
cspNone: par := NoneParity;
cspOdd: par := OddParity;
cspEven: par := EvenParity;
else par := NoneParity;
cspNone: par := Serial.NoneParity;
cspOdd: par := Serial.OddParity;
cspEven: par := Serial.EvenParity;
else par := Serial.NoneParity;
end;
SerSetParams(h, cfg.BaudRate, cfg.DataBits, par, cfg.StopBits, []);
@@ -166,7 +167,11 @@ begin
end;
finally
SerClose(FHandle);
{$IFDEF MSWINDOWS}
FOwner.Handle := INVALID_HANDLE_VALUE;
{$ELSE}
FOwner.Handle := -1;
{$ENDIF}
end;
end;
@@ -177,7 +182,11 @@ begin
inherited Create;
FEngine := AEngine;
FConfig := ACfg;
{$IFDEF MSWINDOWS}
FHandle := INVALID_HANDLE_VALUE;
{$ELSE}
FHandle := -1;
{$ENDIF}
FLock := TCriticalSection.Create;
FActive := False;
end;
@@ -211,11 +220,16 @@ end;
procedure TCATSerialPort.SendStr(const S: string);
var buf: AnsiString;
begin
{$IFDEF MSWINDOWS}
if FHandle = INVALID_HANDLE_VALUE then Exit;
{$ELSE}
if FHandle < 0 then Exit;
{$ENDIF}
FLock.Acquire;
try
buf := AnsiString(S);
SerWrite(FHandle, buf[1], Length(buf));
if Length(buf) > 0 then
SerWrite(FHandle, buf[1], Length(buf));
except
// ignore write errors (port may have been closed)
end;
+10 -9
View File
@@ -20,13 +20,14 @@ unit CATTcp;
interface
uses
Classes, SysUtils, SyncObjs,
Classes, SysUtils,
WebUtils, // SockClose, SockShutdown, SOCK_INVALID
{$IFDEF MSWINDOWS}
Windows, WinSock2
Windows, WinSock2,
{$ELSE}
BaseUnix, Sockets
{$ENDIF},
BaseUnix, Sockets,
{$ENDIF}
SyncObjs,
CATEngine;
const
@@ -251,23 +252,23 @@ end;
procedure TCATTcpClientThread.SendData(const Msg: string; const IdLimit: TStringList);
var
i: Integer;
send: Boolean;
i: Integer;
doSend: Boolean;
begin
if IdLimit = nil then begin
SendStr(Msg);
Exit;
end;
send := False;
doSend := False;
FIdLock.Acquire;
try
for i := 0 to FClientIds.Count-1 do
if IdLimit.IndexOf(FClientIds[i]) >= 0 then begin
send := True;
doSend := True;
Break;
end;
finally FIdLock.Release; end;
if send then SendStr(Msg);
if doSend then SendStr(Msg);
end;
function TCATTcpClientThread.IsMarkedForDelete: Boolean;
+2 -1
View File
@@ -30,7 +30,8 @@ uses
Settings,
WebServer,
CATEngine, CATSerial, CATTcp,
SpectrumView;
SpectrumView,
WinFirewall;
const
CLR_BG = TColor($00101010);