Home > Back-end >  Ask a access COM port and LPT port of the code
Ask a access COM port and LPT port of the code

Time:10-22

at work and on the Internet looking for a long time didn't turn to code,,,,

Any player can provide some written by Delphi procedure to the information of all series of parallel computer,,,

CodePudding user response:

Can take a serial port from the registry list

 procedure TFormCom. EnumComPorts (Ports: TStrings); 
Var
KeyHandle: hkeys;
ErrCode, Index: Integer;
ValueName, Data: string;
ValueLen, DataLen, ValueType: DWORD;
TmpPorts: TStringList;
The begin
ErrCode:=RegOpenKeyEx (HKEY_LOCAL_MACHINE, 'HARDWARE \ DEVICEMAP \ SERIALCOMM', 0,
KEY_READ KeyHandle);

If ErrCode & lt;> ERROR_SUCCESS then
Raise the Exception. The Create (' error opening a serial port list of registry entries');

TmpPorts:=TStringList. Create;
Try
Index:=0;
Repeat
ValueLen:=256;
DataLen:=256;
SetLength (ValueName, ValueLen);
SetLength (Data, DataLen);
ErrCode:=RegEnumValue (KeyHandle, Index, PChar (ValueName),
Cardinal (ValueLen), nil, @ ValueType and PByte (PChar (Data)), @ DataLen);

If ErrCode=ERROR_SUCCESS then
The begin
SetLength (Data, DataLen);
TmpPorts. Add (Data);
Inc (Index);
End
Else if ErrCode & lt;> ERROR_NO_MORE_ITEMS then
//raise Exception. The Create (' error opening a serial port list of registry entries');
Raise the Exception. The Create (' no use serial port);

Until (ErrCode & lt;> ERROR_SUCCESS);

TmpPorts. Sort;
Ports. The Assign (TmpPorts);
The finally
RegCloseKey (KeyHandle);
TmpPorts. Free;
end;
end;
  • Related