谁知道怎么读出电脑上所有的modem和它对应的串口号(100)

  • 主题发起人 主题发起人 lw5202468
  • 开始时间 开始时间
L

lw5202468

Unregistered / Unconfirmed
GUEST, unregistred user!
谁知道怎么读出电脑上所有的modem和它对应的串口号
 
1、检索电脑上所有串口2、给串口发送AT命令,等待应答,在预定时间返回的就是Modem,否则就不是或者没上电下面是我在一个小程序上用过的串口检索函数function TfrmMain.EnumSerialPort(S: TStrings): Boolean;var DeviceInfoData : SP_DEVINFO_DATA;
hDevInfo : Cardinal;
DataT : Cardinal;
I : Integer;
Buf : array[0..255] of Char;
begin
Result := False;
hDevInfo := SetupDiGetClassDevs(@GUID_DEVCLASS_PORTS, nil, 0, DIGCF_PRESENT);
if hDevInfo <> INVALID_HANDLE_VALUE then
begin
I := 0;
DeviceInfoData.cbSize := SizeOf(SP_DEVINFO_DATA);
{ 枚举设备信息 } while SetupDiEnumDeviceInfo(hDevInfo, i, @DeviceInfoData)do
begin
{ 获取设备信息包括GUID和名称 } SetupDiGetDeviceRegistryProperty(hDevInfo, @DeviceInfoData, SPDRP_FRIENDLYNAME, @DataT, PByte(@Buf), Sizeof(Buf), nil);
Inc(I);
if Pos('COM', Buf) > 0 then
S.Add(Buf);
end;
if (GetLastError = NO_ERROR) or (GetLastError = ERROR_NO_MORE_ITEMS) then
Result := True;
{ 释放 DeviceInfoData, hDevInfo } SetupDiDestroyDeviceInfoList(hDevInfo);
end;
end;
 
调用这个函数SetupDiGetClassDevs 要在USES里加什么呀
 
unit SetupAPI;interfaceuses Windows;const GUID_DEVCLASS_1394 :TGUID= '{6BDD1FC1-810F-11D0-BEC7-08002BE2092F}';
GUID_DEVCLASS_ADAPTER :TGUID= '{4D36E964-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_APMSUPPORT :TGUID= '{D45B1C18-C8FA-11D1-9F77-0000F805F530}';
GUID_DEVCLASS_BATTERY :TGUID= '{72631E54-78A4-11D0-BCF7-00AA00B7B32A}';
GUID_DEVCLASS_CDROM :TGUID= '{4D36E965-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_COMPUTER :TGUID= '{4D36E966-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_DECODER :TGUID= '{6BDD1FC2-810F-11D0-BEC7-08002BE2092F}';
GUID_DEVCLASS_DISKDRIVE :TGUID= '{4D36E967-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_DISPLAY :TGUID= '{4D36E968-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_FDC :TGUID= '{4D36E969-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_FLOPPYDISK :TGUID= '{4D36E980-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_GPS :TGUID= '{6BDD1FC3-810F-11D0-BEC7-08002BE2092F}';
GUID_DEVCLASS_HDC :TGUID= '{4D36E96A-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_HIDCLASS :TGUID= '{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}';
GUID_DEVCLASS_IMAGE :TGUID= '{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}';
GUID_DEVCLASS_INFRARED :TGUID= '{6BDD1FC5-810F-11D0-BEC7-08002BE2092F}';
GUID_DEVCLASS_KEYBOARD :TGUID= '{4D36E96B-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_LEGACYDRIVER :TGUID= '{8ECC055D-047F-11D1-A537-0000F8753ED1}';
GUID_DEVCLASS_MEDIA :TGUID= '{4D36E96C-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_MEDIUM_CHANGER :TGUID= '{CE5939AE-EBDE-11D0-B181-0000F8753EC4}';
GUID_DEVCLASS_MODEM :TGUID= '{4D36E96D-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_MONITOR :TGUID= '{4D36E96E-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_MOUSE :TGUID= '{4D36E96F-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_MTD :TGUID= '{4D36E970-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_MULTIFUNCTION :TGUID= '{4D36E971-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_MULTIPORTSERIAL:TGUID= '{50906CB8-BA12-11D1-BF5D-0000F805F530}';
GUID_DEVCLASS_NET :TGUID= '{4D36E972-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_NETCLIENT :TGUID= '{4D36E973-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_NETSERVICE :TGUID= '{4D36E974-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_NETTRANS :TGUID= '{4D36E975-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_NODRIVER :TGUID= '{4D36E976-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_PCMCIA :TGUID= '{4D36E977-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_PORTS :TGUID= '{4D36E978-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_PRINTER :TGUID= '{4D36E979-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_PRINTERUPGRADE :TGUID= '{4D36E97A-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_SCSIADAPTER :TGUID= '{4D36E97B-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_SMARTCARDREADER:TGUID= '{50DD5230-BA8A-11D1-BF5D-0000F805F530}';
GUID_DEVCLASS_SOUND :TGUID= '{4D36E97C-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_SYSTEM :TGUID= '{4D36E97D-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_TAPEDRIVE :TGUID= '{6D807884-7D21-11CF-801C-08002BE10318}';
GUID_DEVCLASS_UNKNOWN :TGUID= '{4D36E97E-E325-11CE-BFC1-08002BE10318}';
GUID_DEVCLASS_USB :TGUID= '{36FC9E60-C465-11CF-8056-444553540000}';
GUID_DEVCLASS_VOLUME :TGUID= '{71A27CDD-812A-11D0-BEC7-08002BE2092F}';const DIGCF_PRESENT = $0002;
DIGCF_ALLCLASSES = $0004;
DIF_PROPERTYCHANGE = 18;
DICS_ENABLE = 1;
DICS_FLAG_GLOBAL = 1;
DICS_DISABLE = 2;const SPDRP_DEVICEDESC = $00000000;
// DeviceDesc (R/W) {$EXTERNALSYM SPDRP_DEVICEDESC} SPDRP_HARDWAREID = $00000001;
// HardwareID (R/W) {$EXTERNALSYM SPDRP_HARDWAREID} SPDRP_COMPATIBLEIDS = $00000002;
// CompatibleIDs (R/W) {$EXTERNALSYM SPDRP_COMPATIBLEIDS} SPDRP_UNUSED0 = $00000003;
// unused {$EXTERNALSYM SPDRP_UNUSED0} SPDRP_SERVICE = $00000004;
// Service (R/W) {$EXTERNALSYM SPDRP_SERVICE} SPDRP_UNUSED1 = $00000005;
// unused {$EXTERNALSYM SPDRP_UNUSED1} SPDRP_UNUSED2 = $00000006;
// unused {$EXTERNALSYM SPDRP_UNUSED2} SPDRP_CLASS = $00000007;
// Class (R--tied to ClassGUID) {$EXTERNALSYM SPDRP_CLASS} SPDRP_CLASSGUID = $00000008;
// ClassGUID (R/W) {$EXTERNALSYM SPDRP_CLASSGUID} SPDRP_DRIVER = $00000009;
// Driver (R/W) {$EXTERNALSYM SPDRP_DRIVER} SPDRP_CONFIGFLAGS = $0000000A;
// ConfigFlags (R/W) {$EXTERNALSYM SPDRP_CONFIGFLAGS} SPDRP_MFG = $0000000B;
// Mfg (R/W) {$EXTERNALSYM SPDRP_MFG} SPDRP_FRIENDLYNAME = $0000000C;
// FriendlyName (R/W) {$EXTERNALSYM SPDRP_FRIENDLYNAME} SPDRP_LOCATION_INFORMATION = $0000000D;
// LocationInformation (R/W) {$EXTERNALSYM SPDRP_LOCATION_INFORMATION} SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = $0000000E;
// PhysicalDeviceObjectName (R) {$EXTERNALSYM SPDRP_PHYSICAL_DEVICE_OBJECT_NAME} SPDRP_CAPABILITIES = $0000000F;
// Capabilities (R) {$EXTERNALSYM SPDRP_CAPABILITIES} SPDRP_UI_NUMBER = $00000010;
// UiNumber (R) {$EXTERNALSYM SPDRP_UI_NUMBER} SPDRP_UPPERFILTERS = $00000011;
// UpperFilters (R/W) {$EXTERNALSYM SPDRP_UPPERFILTERS} SPDRP_LOWERFILTERS = $00000012;
// LowerFilters (R/W) {$EXTERNALSYM SPDRP_LOWERFILTERS} SPDRP_BUSTYPEGUID = $00000013;
// BusTypeGUID (R) {$EXTERNALSYM SPDRP_BUSTYPEGUID} SPDRP_LEGACYBUSTYPE = $00000014;
// LegacyBusType (R) {$EXTERNALSYM SPDRP_LEGACYBUSTYPE} SPDRP_BUSNUMBER = $00000015;
// BusNumber (R) {$EXTERNALSYM SPDRP_BUSNUMBER} SPDRP_ENUMERATOR_NAME = $00000016;
// Enumerator Name (R) {$EXTERNALSYM SPDRP_ENUMERATOR_NAME} SPDRP_SECURITY = $00000017;
// Security (R/W, binary form) {$EXTERNALSYM SPDRP_SECURITY} SPDRP_SECURITY_SDS = $00000018;
// Security (W, SDS form) {$EXTERNALSYM SPDRP_SECURITY_SDS} SPDRP_DEVTYPE = $00000019;
// Device Type (R/W) {$EXTERNALSYM SPDRP_DEVTYPE} SPDRP_EXCLUSIVE = $0000001A;
// Device is exclusive-access (R/W) {$EXTERNALSYM SPDRP_EXCLUSIVE} SPDRP_CHARACTERISTICS = $0000001B;
// Device Characteristics (R/W) {$EXTERNALSYM SPDRP_CHARACTERISTICS} SPDRP_ADDRESS = $0000001C;
// Device Address (R) {$EXTERNALSYM SPDRP_ADDRESS} SPDRP_UI_NUMBER_DESC_FORMAT = $0000001E;
// UiNumberDescFormat (R/W) {$EXTERNALSYM SPDRP_UI_NUMBER_DESC_FORMAT} SPDRP_MAXIMUM_PROPERTY = $0000001F;
// Upper bound on ordinals {$EXTERNALSYM SPDRP_MAXIMUM_PROPERTY}type HDEVINFO = type Cardinal;
DI_FUNCTION = type Cardinal;
PSP_DEVINFO_DATA = ^SP_DEVINFO_DATA;
SP_DEVINFO_DATA = packed record cbSize: DWORD;
ClassGuid: TGUID;
DevInst: DWORD;
Reserved: Longint;
end;
PSP_CLASSINSTALL_HEADER = ^SP_CLASSINSTALL_HEADER;
SP_CLASSINSTALL_HEADER = packed record cbSize: DWORD;
InstallFunction: DI_FUNCTION;
{ (DIF code) } end;
PSP_PROPCHANGE_PARAMS = ^SP_PROPCHANGE_PARAMS;
SP_PROPCHANGE_PARAMS = packed record ClassInstallHeader: SP_CLASSINSTALL_HEADER;
StateChange: DWORD;
Scope: DWORD;
HwProfile: DWORD;
end;
PSP_CLASSIMAGELIST_DATA = ^SP_CLASSIMAGELIST_DATA;
SP_CLASSIMAGELIST_DATA = packed record cbSize: DWORD;
ImageList: HWND;
Reserved: DWORD;
end;
function SetupDiGetClassDevs(const ClassGuid: PGUID;
Enumerator: PChar;
hwndParent: HWND;
Flags: DWORD): HDEVINFO;
stdcall;
external 'Setupapi.dll' name 'SetupDiGetClassDevsA';function SetupDiEnumDeviceInfo(DeviceInfoSet: HDEVINFO;
MemberIndex: DWORD;
DeviceInfoData: PSP_DEVINFO_DATA): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiEnumDeviceInfo';function SetupDiGetDeviceRegistryProperty(DeviceInfoSet: HDEVINFO;
DeviceInfoData: PSP_DEVINFO_DATA;
Propertys: DWORD;
PropertyRegDataType: PWORD;
PropertyBuffer: PByte;
PropertyBufferSize: DWORD;
RequiredSize: PWORD): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiGetDeviceRegistryPropertyA';function SetupDiDestroyDeviceInfoList(DeviceInfoSet: HDEVINFO): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiDestroyDeviceInfoList';function SetupDiClassNameFromGuid(ClassGuid: PGUID;
ClassName: PChar;
ClassNameSize: DWORD;
RequiredSize: PDWORD): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiClassNameFromGuidA';function SetupDiSetClassInstallParams(DeviceInfoSet: HDEVINFO ;
DeviceInfoData: PSP_DEVINFO_DATA;
ClassInstallParams: PSP_CLASSINSTALL_HEADER;
ClassInstallParamsSize: DWORD): BOOL stdcall;
external 'Setupapi.dll' name 'SetupDiSetClassInstallParamsA';function SetupDiCallClassInstaller(InstallFunction: DI_FUNCTION;
DeviceInfoSet: HDEVINFO;
DeviceInfoData: PSP_DEVINFO_DATA): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiCallClassInstaller';function SetupDiGetClassImageList(ClassImageListData: PSP_CLASSIMAGELIST_DATA): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiGetClassImageList';function SetupDiDestroyClassImageList(ClassImageListData: PSP_CLASSIMAGELIST_DATA): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiDestroyClassImageList';function SetupDiGetClassImageIndex(ClassImageListData: PSP_CLASSIMAGELIST_DATA;
ClassGuid: PGUID;
ImageIndex: PINT): BOOL;
stdcall;
external 'Setupapi.dll' name 'SetupDiGetClassImageIndex';implementationend.
 
谢谢了啊 可以运行了 就是只能读出通讯串口COM1
 
后退
顶部