⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enumser.htm

📁 六种列举当前所有的串口方法
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<title>EnumSerialPorts v1.11</title>
</head>

<body bgcolor="#FFFFFF">

<p align="left"><img src="enumser.gif" width="32" height="32"> <font color="#000000"
size="6" face="Arial"><strong>EnumSerialPorts v1.11</strong></font></p>

<p><font color="#000000" face="Arial" size="3">Welcome to EnumSerialPorts, A simple
set of MFC functions to enumerate the serial ports installed on your machine.</font></p>

<p>&nbsp;</p>

<table>
  <tr>
    <td><font face="Arial"><a href="#Features">Features</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Usage">Usage</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Copyright">Copyright</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#History">History</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#APIReference">API Reference</a></font></td>
  </tr>
  <tr>
    <td><font face="Arial"><a href="#Contact">Contacting the Author</a></font></td>
  </tr>
</table>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><a name="Features"></a><big><strong><big>Features</big></strong></big>
</font>

<ul>
  <li><font color="#000000" face="Arial" size="3">Simple C++ class interface.</font></li>
  <li><font color="#000000" face="Arial" size="3">The code works on both Windows 95/98, NT, 
  2000, XP and 2003.</font></li>
  <li><font color="#000000" face="Arial" size="3">The code is fully Unicode compliant and
    include Unicode built options in the workspace file.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><a name="Usage"></a><font face="Arial"><big><big><strong>Usage</strong></big></big></font>

<ul>
  <li><font color="#000000" face="Arial" size="3">To use the functions in your code simply
    include enumser.cpp in your project and #include enumser.h in which ever of your modules
    needs to make calls to the function.</font></li>
  <li><font face="Arial">You will need to have a recentish copy of the Platform 
  SDK installed to use all the methods of the class.</font></li>
  <li><font face="Arial">Your code will need to include MFC either statically or dynamically.</font></li>
  <li><font face="Arial">To see the class in action, have a look at the main function in the
    module &quot;main.cpp&quot;.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><b><font face="Arial" size="5"><a name="Copyright"></a>Copyright</font></b></p>
<ul>
  <li><font face="Arial" size="3">You are allowed to include the source code in
    any product (commercial, shareware, freeware or otherwise) when your product
    is released in binary form.</font></li>
  <li><font face="Arial" size="3">You are allowed to modify the source code in
    any way you want except you cannot modify the copyright details at the top
    of each module.</font></li>
  <li><font face="Arial" size="3">If you want to distribute source code with
    your application, then you are only allowed to distribute versions released
    by the author. This is to maintain a single distribution point for the
    source code.</font></li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><big><a name="History"></a></big><font color="#000000" size="5"><strong>History</strong></font></font></p>

<p><font color="#000000" face="Arial" size="3"><strong>v1.0 (3 November 1998)</strong></font>

<ul>
  <li><font color="#000000" face="Arial" size="3">Initial public release.</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.01 (23 February 1999)</strong></font>

<ul>
  <li><font color="#000000" face="Arial" size="3">Code now uses QueryDosDevice
    if running on NT to determine which serial ports are available. This avoids having to open the
    ports at all. It should operate a lot faster in addition.</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.02 (12 December 1999)</strong></font>

<ul>
  <li><font face="Arial">Fixed a problem in the Win9x code path when trying to
    detect deactivated IRDA-ports.  When trying to open those, you will get the error-code
    ERROR_GEN_FAILURE.&nbsp;</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.03 (17 May 2000)</strong></font>

<ul>
  <li><font face="Arial">Code now uses GetDefaultCommConfig in all cases to detect                          the ports.</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.04 (29 March 2001)</strong></font>

<ul>
  <li><font face="Arial"> Reverted code to use CreateFile or QueryDosDevice as it is                          much faster than using the GetDefaultCommConfig
    method.</font></li>
  <li><font face="Arial">Updated copyright message.</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.05 (25 June 2001)</strong></font>

<ul>
  <li>
    <p class="crt"><font face="Arial"> Guess what, You now have the choice of using the GetDefaultCommConfig
    thro the use of three versions of the function. You take your pick.</font></li>
  <li>
    <p class="crt"><font face="Arial">Fixed problem where port fails to be reported thro the CreateFile
    mechanism when the error code is ERROR_SHARING_VIOLATION i.e. someone has the port already open.</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.06 (11 August 2001)</strong></font>

<ul>
  <li>
    <p class="crt"><font face="Arial"> Made code path which uses QueryDosDevice more robust by checking to                          make sure the device name is of the form "COMxyz.." where xyz are numeric.</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.07 (13 August 2001)</strong></font>

<ul>
  <li>
    <p class="crt"><font face="Arial"> Made the code in IsNumeric more robust when sent an empty string</font></li>
  <li>
    <p class="crt"><font face="Arial">Optimized the code in EnumerateSerialPorts2 somewhat. Thanks to Dennis                          Lim for these suggestions.</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.08 (22 May 2003)</strong></font>

<ul>
  <li>
    <p class="crt"><font face="Arial">Updated copyright details.</font></li>
  <li>
    <p class="crt"><font face="Arial">Addition of a EnumerateSerialPorts4 which 
    uses Device Manager API</font></li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.09 (20 September 2003)</strong></font>

<ul>
  <li>

<p class="crt"><font face="Arial">Addition of a &quot;EnumerateSerialPorts5&quot; method. 
This method (hopefully the last method!) uses EnumPorts and was provided by Andi 
Martin.</font></p>

  </li>
</ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.10 (12 December 2003)</strong></font>

<ul>
  <li><font face="Arial">Updated the sample app to VC 6. </font></li>
  <li><font face="Arial">Addition of a &quot;EnumerateSerialPorts6&quot; (See 
Note 4 below) which uses WMI. </font></li>
  <li><font face="Arial">You can now optionally exclude each function 
using preprocessor defines of the form &quot;NO_ENUMSERIAL_USING_XYX&quot;. </font>
  </li>
  <li><font face="Arial">Made the functions members of a C++ class and renamed 
  them to using more meaningful names </font></li>
  </ul>

<p><font color="#000000" face="Arial" size="3"><strong>v1.11 (13 May 2004)</strong></font>

<ul>
  <li><font face="Arial">Extended CEnumerateSerial::UsingSetupAPI to now also 
  return the friendly name of the port. Thanks to Jay C. Howard for prompting 
  this update.</font></li>
  </ul>
  <p>&nbsp;<p class="crt"><font face="Arial"><a name="APIReference"></a><big><big><strong>API
Reference</strong></big></big></font></p>

<p><strong><font face="Arial"><big>CEnumerateSerial::UsingCreateFile</big></font></strong></p>

<p><strong><font face="Arial">BOOL CEnumerateSerial::UsingCreateFile(CUIntArray&amp;&nbsp; ports);</font></strong></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>ports</em> Upon return this array will contain the port numbers
of all the serial ports installed on the computer</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">This function uses the CreateFile method of detecting
serial ports. This will work on all Win32 OS'es, but requires actually opening 
the port.</font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial"><big>CEnumerateSerial::UsingQueryDosDevice</big></font></strong></p>

<p><strong><font face="Arial">BOOL CEnumerateSerial::UsingQueryDosDevice(CUIntArray&amp;&nbsp; ports);</font></strong></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>ports</em> Upon return this array will contain the port numbers
of all the serial ports installed on the computer</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">This function uses the QueryDosDevice method of detect
serial ports. Please note that this only works correctly on NT, Windows 2000, XP 
or 2003.</font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial"><big>CEnumerateSerial::UsingGetDefaultCommConfig</big></font></strong></p>

<p><strong><font face="Arial">BOOL CEnumerateSerial::UsingGetDefaultCommConfig(CUIntArray&amp;&nbsp; ports);</font></strong></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>ports</em> Upon return this array will contain the port numbers
of all the serial ports installed on the computer</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">This function uses the GetDefaultCommConfig method of 
detect serial ports. Please note that this is the most compatible way of detecting
serial ports and will work on all Win32 OS'es but also happens to be the
slowest.</font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial"><big>CEnumerateSerial::UsingSetupAPI</big></font></strong></p>

<p><strong><font face="Arial">BOOL CEnumerateSerial::UsingSetupAPI(CUIntArray&amp;&nbsp; ports, 
CStringArray&amp; sFriendlyNames);</font></strong></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>ports</em> Upon return this array will contain the port numbers
of all the serial ports installed on the computer</font></p>

<p><font face="Arial"><i>sFriendlyNames</i> Upon return this array will contain 
the Friendly names as appears in the Device Manager corresponding to the serial 
ports returned in <i>&quot;ports&quot;</i>.</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">This function uses the Device Manager &quot;SetupDi..&quot;&nbsp; 
APIs to detect serial ports. Please note that this will not work on Win95 or NT 
4, and will only work on Windows 98 or later or Windows 2000 or later on the NT 
kernel.</font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial"><big>CEnumerateSerial::UsingEnumPorts</big></font></strong></p>

<p><strong><font face="Arial">BOOL CEnumerateSerial::UsingEnumPorts(CUIntArray&amp;&nbsp; ports);</font></strong></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>ports</em> Upon return this array will contain the port numbers
of all the serial ports installed on the computer</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">This function uses the Win32 SDK call &quot;EnumPorts&quot;&nbsp; 
APIs to detect serial ports. This will work on all Win32 OS'es.</font></p>

<p>&nbsp;</p>

<p><strong><font face="Arial"><big>CEnumerateSerial::UsingWMI</big></font></strong></p>

<p><strong><font face="Arial">BOOL CEnumerateSerial::UsingWMI(CUIntArray&amp;&nbsp; ports);</font></strong></p>

<p><font face="Arial"><strong>Parameters</strong></font></p>

<p><font face="Arial"><em>ports</em> Upon return this array will contain the port numbers
of all the serial ports installed on the computer</font></p>

<p><font face="Arial"><strong>Remarks</strong></font></p>

<p><font face="Arial">This function uses the WMI COM interfaces to detect serial ports. 
This will only work on Windows NT 4 SP4, Windows 2000, XP or 2003 (i.e versions 
of Windows on which WMI is available).</font></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><font face="Arial"><a name="Contact"></a><font color="#000000" size="4"><strong>CONTACTING
THE AUTHOR</strong></font></font></p>

<p><font color="#000000" face="Arial" size="3">PJ Naughter<br>
Email: <a href="mailto:pjna@naughter.com">pjna@naughter.com</a><br>
Web: <a href="http://www.naughter.com">http://www.naughter.com</a><br>
13 May 2004</font></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -