• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
工作日志
工作日志
博客园    首页    新随笔    联系   管理    订阅  订阅
得到当前可使用的串口信息
得到当前可使用的串口信息
日期:2007-8-2 类别:硬件 作者: 推荐:本站 人气:1011


 



(********************************************************************
**
** GetAvailableComPorts -
**
** This is a procedure whose purpose is to determine
** which COM ports are available on the user's computer.  It then
** fills up the PortsComboBox with those available COM port numbers.
**
********************************************************************)

procedure TJeffsForm.GetAvailableComPorts();
var
  i : Integer;
  S : String;
  ComName: array[0..9] of Char;
  TheComHandle: Integer;

begin

        (*
        ** Okay, Clear everything in the PortsComboBox because
        ** we want to start off fresh.
        *)

        PortsComboBox.Clear();

        (*
        ** Windows 95/98 can only handle up to 50 COM ports.
        ** All we are doing here is checking to see if Windows
        ** "can" open up the COM port.  If so, then we know it's
** available.  And so we add it to our ComboBox list
** and of course close the COM port each time we check it.
*)

for i := 1 to 50 do begin
  
  StrFmt( ComName, '\\.\COM%d', [i] );
  
  TheComHandle := CreateFile
  (
  ComName,                        // name
                GENERIC_READ or GENERIC_WRITE,  // access attributes
                0,                              // no sharing
                nil,                            // no security
                OPEN_EXISTING,                  // creation action
                FILE_ATTRIBUTE_NORMAL or
  FILE_FLAG_OVERLAPPED,           // attributes
                0                               // no template
                );
  
  if ( TheComHandle <> INVALID_HANDLE_VALUE ) then begin
    
    S := Format('COM%d', [i]);
    PortsComboBox.Items.Add(S);
    
  end;
  
  CloseHandle( TheComHandle );
  
end; {end of for loop}

end;
posted on 2010-05-18 15:16  滴水藏海映太阳  阅读(259)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3