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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
procedure TMain.AutoDetectionClick(Sender: TObject);
var
Val : TStringList;
ScanPorts : Boolean;
NomCOM : array[1..256] of String;
i, result, NbreCOM : Integer;
tampon : String;
begin
//ports_connectes
With TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('HARDWARE\DEVICEMAP\SERIALCOMM', false);
try
Val := TStringList.Create;
finally
GetValueNames(Val);
NbreCOM := Val.Count;
//definir_COM
For i := 0 to (Val.Count - 1) do
begin
tampon := ReadString(Val.Strings[i]);
NomCOM[i + 1] := tampon;
end;
end;
Val.Free;
CloseKey;
finally
Free;
end;
If NbreCOM = 0 then
begin
AbortProcedure := True;
MessageDlg('Aucun périphérique détecté !', MtWarning, [MbOk], 0);
end
else
begin
//analyse_ports
ScanPorts := True;
AbortProcedure := False;
i := 1;
While (ScanPorts) or (i <= NbreCOM) or (not AbortProcedure) do
begin
With ComPort1 do If Copy(NomCOM[i], 0, 3) = 'COM' then
begin
If Connected then Connected := False;
Port := NomCOM[i];
PosRX := 0;
ValeurRXChar := '';
try
Connected := True;
WriteStr('AT+GMM' + Chr(13));
finally
//accepter_port?
If (ValeurRXChar <> '') and (ValeurRXChar <> OldValeurRXChar) then
begin
result := MessageDlg('Accepter la connexion sur '+ Port + ' : ' + ValeurRXChar, MtConfirmation, [MbYes, MbNo, MbCancel], 0);
//produit_accepte
If result = mrYes then ScanPorts := False;
//procedure_annulee
If result = mrCancel then AbortProcedure := True;
end;
end;
inc(i);
end;
end;
end;
end;
procedure TMain.ComPort1RxChar(Sender: TObject; Count: Integer);
begin
//recupValeur
If PosRX = 1 then
begin
ComPort1.ReadStr(ValeurRXChar, Count);
OldValeurRXChar := ValeurRXChar;
end;
inc(PosRX);
end; |
Partager