Changeset 404 for PinConnection


Ignore:
Timestamp:
Aug 13, 2012, 10:03:31 AM (12 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/USerialPort.pas

    r283 r404  
    77uses
    88  Classes, SysUtils, SynaSer, StdCtrls, Dialogs, UCommon, UThreading,
    9   DateUtils;
     9  DateUtils, FileUtil;
    1010
    1111type
     
    7474    property BaudRateNumeric: Integer read GetBaudRateNumeric write SetBaudRateNumeric;
    7575    property OnReceiveData: TReceiveDataEvent read FOnReceiveData write FOnReceiveData;
     76    procedure LoadAvailableToStrings(Strings: TStrings; Check: Boolean = False);
    7677    constructor Create;
    7778    destructor Destroy; override;
     
    169170  FreeAndNil(FReceiveThread);
    170171  CloseSocket;
     172end;
     173
     174procedure TSerialPort.LoadAvailableToStrings(Strings: TStrings; Check: Boolean = False);
     175var
     176  I: Integer;
     177  TestPort: TSerialPort;
     178  Files: TStringList;
     179begin
     180  Strings.Clear;
     181  {$IFDEF Windows}
     182  if Check then
     183  try
     184    TestPort := TSerialPort.Create;
     185    for I := 0 to Strings.Count - 1 do
     186    with TestPort do begin
     187      Name := Strings[I];
     188      Active := True;
     189      if Active then begin
     190        Strings.AddObject(Name, TObject(I));
     191      end;
     192      Active := False;
     193    end;
     194  finally
     195    TestPort.Free;
     196  end else begin
     197    for I := 1 to 255 do
     198      Strings.AddObject('COM' + IntToStr(I), nil);
     199  end;
     200  {$ENDIF}
     201  {$IFDEF Linux}
     202  if Check then begin
     203    Files := FindAllFiles('/dev', 'tty*', False);
     204    Strings.Assign(Files);
     205    Files.Free;
     206  end else begin
     207    for I := 1 to 63 do
     208      Strings.AddObject('/dev/ttyS' + IntToStr(I), nil);
     209  end;
     210  {$ENDIF}
    171211end;
    172212
Note: See TracChangeset for help on using the changeset viewer.