得到当前可使用的串口信息

时间:2010-02-03 12:46:33  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:ailable COM port numbers.********************)procedure TJeffsForm.GetAvailableComPorts();var  i : Integer;  S : String;  ComName: array[0..9] of Char;  TheComHandle: Integer;begin        (* ...
  正文:(****
**
** 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; "得到当前可使用的串口信息"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12752.html


关键字:

关于《得到当前可使用的串口信息》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td