From 0480c73f3fdf9e02768093b5de12e8132348a86f Mon Sep 17 00:00:00 2001 From: Uladzimir Karpenka Date: Sat, 2 May 2026 13:39:46 +0300 Subject: [PATCH] fix build on windows --- CATSerial.pas | 26 ++++++++++++++++++++------ CATTcp.pas | 19 ++++++++++--------- MainForm.pas | 3 ++- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/CATSerial.pas b/CATSerial.pas index 0e5b9b0..499a0bc 100644 --- a/CATSerial.pas +++ b/CATSerial.pas @@ -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; diff --git a/CATTcp.pas b/CATTcp.pas index dd4df03..640a223 100644 --- a/CATTcp.pas +++ b/CATTcp.pas @@ -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; diff --git a/MainForm.pas b/MainForm.pas index 856b21e..1d76489 100644 --- a/MainForm.pas +++ b/MainForm.pas @@ -30,7 +30,8 @@ uses Settings, WebServer, CATEngine, CATSerial, CATTcp, - SpectrumView; + SpectrumView, + WinFirewall; const CLR_BG = TColor($00101010);