Autor Beitrag
hansg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: So 02.03.03 12:29 
Hallo zusammen,

gibt es eine Möglichkeit festzustellen ob Serielle Schnittstellen schon von anderen Anwendungen belegt sind?

Moderiert von user profile iconTino: Titel geändert & Topic verschoben.

_________________
Gruß Hans
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: So 02.03.03 14:52 
Hi,

nur indem Du die Schnittstelle öffnest und auf eine Exception wartest.

Gruß,
Markus
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: So 02.03.03 14:55 
Hi,

wie kann ich diese dann abfangen um diese dann auszuwerten?

_________________
Gruß Hans
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: So 02.03.03 15:02 
Hi,

ich würde es mit try...except versuchen.

Markus
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: So 02.03.03 15:47 
hi,
danke für den Tip nur leider komme ich damit nicht weiter.
Wer hilft einem Anfänger z.B. mit einem BSP?

_________________
Gruß Hans
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: So 02.03.03 18:06 
Hi.

hansg hat folgendes geschrieben:

Wer hilft einem Anfänger z.B. mit einem BSP?


:roll:

Zum ursprünglichen Problem, versuch mal folgendes:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
procedure TForm1.Button1Click(Sender: TObject);

  function CommExists(CommPort: integer): boolean;
  var
    s: array[0..5] of char;
    i: cardinal;
    CommConfig: TCommConfig;
  begin
    s := 'COMx' + #0;
    s[3] := chr($31 + CommPort);
    i := SizeOf(CommConfig);
    Result := GetDefaultCommConfig(s, CommConfig, i);
  end;

var
  i: Integer;
  s: array[0..5] of char;
  Result: THandle;
begin
  Result := 0;
  for i := 1 to 10 do
  begin
    if CommExists(i - 1) then
    begin
      s := 'COMx'+#0;
      s[3] := chr($31 + i - 1);
      try
        Result := CreateFile(s, GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      finally
        if (Result <> INVALID_HANDLE_VALUE) then Label1.Caption := Label1.Caption + IntToStr(i) + ', ' else Label2.Caption := Label2.Caption + IntToStr(i) + ', ';
        CloseHandle(Result);
      end;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Label1.Caption := 'Verfügbar: ';
  Label2.Caption := 'Belegt: ';
end;


Gruß,
Markus
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: So 02.03.03 20:33 
Hi,
danke für den Code, habe Ihn mal kopiert und ausprobiert scheint zu funktionieren.
Da ich den Code nicht nur kopieren will sondern auch verstehen möchte (vom kopieren lernt man nix) wäre es nett wenn man mir eine kleine Erklärung dazu geben könnte.

_________________
Gruß Hans