读书人

怎么获取系统内串口的信息

发布时间: 2012-03-26 15:46:55 作者: rapoo

如何获取系统内串口的信息?
请问,
如何让程序根据所在系统的不同环境,
获得当前系统内串口的信息:

包括系统内串口的个数、都是第几个和第几个?

还有每个串口各自的状态(目前是否可用等 :) )等。

------------------------------------------------
如何在CB里实现这个功能?最好有个例子,谢谢。
------------------------------------------------


一经试过,成功给分,急,等待中......

[解决办法]
用CreateFile遍历打开这些串口就行了给你个函数,你尝试从com1-com255调用调用这个函数

function find_valid_port(com_portno: string): boolean;
var
hNewCommFile: THandle;
commprop: TCommProp;
begin
hNewCommFile := CreateFile(pchar( '\\.\ ' + com_portno),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,
0);
if hNewCommFile = INVALID_HANDLE_VALUE then
begin
result := false;
end
else
begin
GetCommProperties(hNewCommFile, commprop);
if commprop.dwProvSubType = PST_RS232 then
begin
closehandle(hNewCommFile);
result := true;
end
else
begin
closehandle(hNewCommFile);
Result := false;
end;
end;
end;

读书人网 >C++ Builder

热点推荐