[Lazarus] SdpoSerial port open problems
Bo Berglund
bo.berglund at gmail.com
Wed Feb 9 23:10:29 CET 2011
I have used SdpoSerial as the RS232 handler in a class which is used
in a test application.
In this I create the SdpoSerial component in code in the constructor
of my class like this:
FComm := TSdpoSerial.Create(NIL);
case Baud of
1200: FComm.BaudRate := br__1200;
2400: FComm.BaudRate := br__2400;
4800: FComm.BaudRate := br__4800;
9600: FComm.BaudRate := br__9600;
19200: FComm.BaudRate := br_19200;
38400: FComm.BaudRate := br_38400;
else
FComm.BaudRate := br_38400;
end;
FComm.DataBits := db8bits;
FComm.Parity := pNone;
FComm.StopBits := sbOne;
FComm.FlowControl := fcNone;
{$IFDEF LINUX}
FComm.Device:= '/dev/ttyS' + IntToStr(Port-1);
{$ELSE}
FComm.Device:= 'COM' + IntToStr(Port);
{$ENDIF}
FComm.OnRxData := @OnRxComm;
FComm.SynSer.Purge;
FCommTimeout := COMTIMEOUT;
Then I open the port like this:
function TSSComm.Connect: boolean;
begin
if not FComm.Active then
FComm.Open;
if FComm.Active then <== Always true even for bogus port!
FCommState := csOpen
else
begin
FCommState := csClosed;
Result := false;
exit;
end;
Result := FCommState = csOpen;
end;
I keep track of various communication states in the FCommState
variable (it is indicating the state in a state machine).
The problem I have is that even though I open a non-existing port the
SdpoSerial does not indicate this. Following the Open method Active is
true even though a completely bogus port number has been given!
Why is this and how can I fix it?
I need to know if the port is actually working or not....
--
Bo Berglund
Developer in Sweden
More information about the Lazarus
mailing list