本文整理自网络,侵删。
//检测串口function ComPortAvailable(Port: Pchar): boolean;var DeviceName: Array[0..80] of char; ComFile: THandle;begin StrPCopy(DeviceName, Port); ComFile:= CreateFile(DeviceName, GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); Result:= ComFile <> INVALID_HANDLE_VALUE; CloseHandle(ComFile);end;
var Locator,RET,Tmp: OleVariant; Enum: IEnumVariant; Value: Cardinal;begin (************* 查询串口详细信息 ********) Locator := CreateOleObject('WbemScripting.SWbemLocator'); Ret := Locator.ConnectServer('.', '', '', '').ExecQuery('SELECT * FROM Win32_SerialPort'); Enum:= IUnknown(RET._NewEnum) as IEnumVariant; while (Enum.Next(1, Tmp, Value) = S_OK) do memorec.Lines.Add(Tmp.Name+' '+Tmp.DeviceID+' '+Tmp.CreationClassName+' '+Tmp.PNPDeviceID+' '+Tmp.ProviderType);end;
相关阅读 >>
更多相关阅读请进入《Delphi》频道 >>