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

📄 serialport.htm

📁 串口编程控件,可以读取串口发出的数据,并且可以向串中写入数据
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>CSerialPort v1.22</title>
<link rel="stylesheet" type="text/css" href="naughter.css">
</head>

<body bgcolor="#FFFFFF">

<h2><strong><img border="0" src="serialport.gif" alt="serialport.gif" width="40" height="38">CSerialPort 
v1.22</strong></h2>

<p>Welcome to CSerialPort, a freeware MFC class to wrap access to the Win32 APIs 
dealing with serial ports. </p>

<p>&nbsp;</p>

<table>
<TBODY>
  <tr>
    <td><a href="#Features">Features</a></td>
  </tr>
  <tr>
    <td><a href="#Usage">Usage</a></td>
  </tr>
  <tr>
    <td><a href="#Copyright">Copyright</a></td>
  </tr>
  <tr>
    <td><a href="#History">History</a></td>
  </tr>
  <tr>
    <td><a href="#APIReference">API Reference</a></td>
  </tr>
  <tr>
    <td><a href="#Enhancements">Planned Enhancements</a></td>
  </tr>
  <tr>
    <td><a href="#Contact">Contacting the Author</a></td>
  </tr>
</TBODY>
</table>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<h2><a name="Features"></a><strong>Features</strong>


</h2>


<ul>
  <li>Simple and clean C++ interface. </li>
  <li>Uses C++ exceptions in preference to the normal win32 return value 
	mechanism. This ensures that code which uses CSerialPort is more robust. </li>
  <li>Unicode enabled, supports linking to MFC statically and all code compiles 
	cleanly at warning level 4. </li>
  <li>Supports overlapped, blocking and call-back usage models of the serial 
	port. (Call-back is only supported on NT). </li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<h2><a name="Usage"></a><strong>Usage</strong>

</h2>

<ul>
  <li>To use the class in your code simply include serialport.cpp in your 
	project and #include serialport.h in which ever of your modules needs to 
	make calls to the class. </li>
  <li>As of v1.19 you will need an up to date Platform SDK
    installed to compile the code if you are using Visual C++ 6 (February 2003 
	was the last version which was compatible with VC 6).</li>
  <li>To see the code in action have a look at the module &quot;app.cpp&quot; in the 
	sample app. </li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<h2><b><a name="Copyright"></a>Copyright</b></h2>
<ul>
  <li>You are allowed to include the source code in
    any product (commercial, shareware, freeware or otherwise) when your product
    is released in binary form.</li>
  <li>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.</li>
  <li>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.</li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<h2><a name="History"></a><strong>History</strong></h2>

<p><strong>V1.0 (31 May 1999)</strong> 

<ul>
  <li>Initial public release. </li>
</ul>

<p><strong>V1.01 (3 June 1999)</strong> 

<ul>
  <li>Fixed problem with code using CancelIo function which does not exist on 
	95.</li>
  <li>Fixed leaks which can occur in sample app when an exception is thrown</li>
</ul>

<p><strong>V1.02 (16 June 1999)</strong> 

<ul>
  <li>Fixed a bug whereby CString::ReleaseBuffer was not being called in 
	CSerialException::GetErrorMessage</li>
</ul>

<p><strong>V1.03 (29 September 1999)</strong> 

<ul>
  <li> Fixed a simple copy and paste bug in CSerialPort::SetDTR</li>
</ul>

<p><strong>V1.04 (8 March 2000)</strong> 

<ul>
  <li>Links in the documentation now work &lt;g&gt;.</li>
</ul>

<p><strong>V1.05 (8 May 2000)</strong> 

<ul>
  <li>Fixed an unreferenced variable in CSerialPort::GetOverlappedResult in VC 6</li>
</ul>

<p><strong>V1.06 (12 June 2000)</strong> 

<ul>
  <li>Fixed another unreferenced variable problem in 
	CSerialPortApp::InitInstance in VC 6.</li>
</ul>

<p><strong>3 July 2000</strong> 

<ul>
  <li>Minor update to the documentation.</li>
</ul>

<p><strong>V1.07 (10 December 2000)</strong> 

<ul>
  <li>Made class destructor virtual.</li>
</ul>

<p><strong>V1.08 (15 January 2001)</strong> 

<ul>
  <li> Attach method now also allows you to specify whether the serial port is 
	being attached to in overlapped mode</li>
  <li>Removed some ASSERTs which were unnecessary in some of the functions</li>
  <li>Updated the Read method which uses OVERLAPPED IO to also return the bytes 
	read. This allows calls to WriteFile with a zeroed overlapped structure 
	(This is required when dealing with TAPI and serial communications)</li>
  <li>Now includes copyright message in the source code and documentation.</li>
</ul>

<p><strong>V1.09 (24 March 2001)</strong> 

<ul>
  <li> Added a BytesWaiting method</li>
</ul>

<p><strong>V1.10 (4 April 2001)</strong> 

<ul>
  <li> Provided an overridden version of BytesWaiting which specifies a timeout.</li>
</ul>

<p><strong>V1.11 (23 April 2001)</strong> 

<ul>
  <li> Fixed a memory leak in DataWaiting method.</li>
</ul>

<p><strong>V1.12 (1 May 2002)</strong> 

<ul>
  <li> Fixed a problem in Open method which was failing to initialize the DCB 
	structure incorrectly, when calling GetState. Thanks to Ben Newson for this 
	fix.</li>
</ul>

<p><strong>V1.13 (29 May 2002)</strong> 

<ul>
  <li>Fixed an problem where the GetProcAddress for CancelIO was using the wrong 
	calling convention.</li>
</ul>

<p><strong>V1.14 (7 August 2002)</strong> 

<ul>
  <li>Changed the declaration of CSerialPort::WaitEvent to be consistent with 
	the rest of the methods in CSerialPort which can operate in &quot;OVERLAPPED&quot; 
	mode. A note about the usage of this: If the method succeeds then the 
	overlapped operation has completed synchronously and there is no need to do 
	a WaitForSingle/MultipleObjects. If any other unexpected error occurs then a 
	CSerialException will be thrown. See the implementation of the 
	CSerialPort::DataWaiting which has been rewritten to use this new design 
	pattern. Thanks to Serhiy Pavlov for spotting this inconsistency.</li>
</ul>

<p><strong>V1.15 (20 September 2002)</strong> 

<ul>
  <li> Addition of an additional ASSERT in the internal _OnCompletion function.</li>
  <li>Addition of an optional out parameter to the Write method which operates 
	in overlapped mode. Thanks to Kevin Pinkerton for this addition.</li>
</ul>

<p><strong>5 March 2003</strong><ul>
  <li> Updated the documentation for the function CSerialPort::GetStatus.</li>
</ul>

<p><strong>v1.16 (10 April 2006)</strong><ul>
  <li> Updated copyright details.</li>
	<li> Addition of a CSERIALPORT_EXT_CLASS and CSERIALPORT_EXT_API macros 
	which makes the class easier to use in an extension dll.</li>
	<li> Removed derivation of CSerialPort from CObject as it was not really 
	needed.</li>
	<li> Fixed a number of level 4 warnings in the sample app.</li>
	<li> Reworked the overlapped IO methods to expose the LPOVERLAPPED structure 
	to client code.</li>
	<li> Updated the documentation to use the same style as the web site.</li>
	<li> Did a spell check of the HTML documentation.</li>
	<li> Updated the documentation on possible blocking in Read/Ex function. 
	Thanks to D Kerrison for reporting this issue.</li>
	<li> Fixed a minor issue in the sample app when the code is compiled using 
	/Wp64</li>
</ul>

<p><strong>v1.17 (2 June 2006)</strong><ul>
  <li> Removed the bOverlapped as a member variable from the class. There was no 
	real need for this setting, since the SDK functions will perform their own 
	checking of how overlapped operations should </li>
	<li> Fixed a bug in GetOverlappedResult where the code incorrectly checking 
	against the error ERROR_IO_PENDING instead of ERROR_IO_INCOMPLETE. Thanks to 
	Sasho Darmonski for reporting this bug.</li>
	<li> Reviewed all TRACE statements for correctness.</li>
</ul>

<p><strong>v1.18 (5 June 2006)</strong><ul>
	<li>Fixed an issue with the creation of the internal event object. It was 
	incorrectly being created as an auto-reset event object instead of a manual 
	reset event object. Thanks to Sasho Darmonski for reporting this issue.</li>
</ul>

<p><strong>v1.19 (24 June 2006)</strong><ul>
	<li>Fixed some typos in the history list. Thanks to Simon Wong for reporting 
	this.</li>
	<li>Made the class which handles the construction of function pointers at 
	runtime a member variable of CSerialPort</li>
	<li>Made AfxThrowSerialPortException part of the CSerialPort class. Thanks 
	to Simon Wong for reporting this.</li>
	<li>Removed the unnecessary CSerialException destructor. Thanks to Simon 
	Wong for reporting this.</li>
	<li>Fixed a minor error in the TRACE text in CSerialPort::SetDefaultConfig. 
	Again thanks to Simon Wong for reporting this. </li>
	<li>Code now uses new C++ style casts rather than old style C casts where 
	necessary. Again thanks to Simon Wong for reporting this.</li>
	<li>CSerialException::GetErrorMessage now uses the strsafe functions. This 
	does mean that the code now requires the Platform SDK if compiled using VC 
	6.</li>
</ul>

<p><strong>v1.20 (25 June 2006)</strong><ul>
	<li>Combined the functionality of the CSerialPortData class into the main 
	CSerialPort class.</li>
	<li>Renamed AfxThrowSerialPortException to ThrowSerialPortException and made 
	the method public.</li>
</ul>

<p><strong>v1.21 (5 November 2006)</strong><ul>
	<li>Minor update to stdafx.h of sample app to avoid compiler warnings in VC 
	2005.</li>
	<li>Reverted the use of the strsafe.h header file. Instead now the code uses 
	the VC 2005 Safe CRT and if this is not available, then we fail back to the 
	standard CRT.</li>
</ul>

<p><strong>v1.22 (25 January 2007)</strong><ul>
	<li>Minor update to remove strsafe.h from stdafx.h of the sample app.</li>
	<li>Updated copyright details.</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>

<p>&nbsp;</p>

<h2><a name="APIReference"></a><strong>API Reference</strong></h2>

<p>The API consists of the classes: CSerialException and the CSerialPort class. 
They have the following member functions and variables:</p>

<p><strong><a href="#CSerialException">CSerialException::CSerialException</a><br>
<a href="#GetErrorMessage">
CSerialException::GetErrorMessage</a><br>
<a href="#m_dwError">
CSerialException::m_dwError</a><br>
<a href="#CSerialPort">
CSerialPort::CSerialPort</a><br>
<a href="#~CSerialPort">CSerialPort::~CSerialPort</a><br>
<a href="#Open">
CSerialPort::Open</a><br>
<a href="#Close">
CSerialPort::Close</a><br>
<a href="#Attach">
CSerialPort::Attach</a><br>
<a href="#Detach">
CSerialPort::Detach</a><br>
<a href="#operator HANDLE">
CSerialPort::operator HANDLE</a><br>
<a href="#IsOpen">
CSerialPort::IsOpen</a><br>
<a href="#Dump">
CSerialPort::Dump</a><br>
<a href="#Read">
CSerialPort::Read</a><br>
<a href="#Read">
CSerialPort::ReadEx</a><br>
<a href="#Write">
CSerialPort::Write</a><br>
<a href="#Write">
CSerialPort::WriteEx</a><br>
<a href="#TransmitChar">
CSerialPort::TransmitChar</a><br>
<a href="#GetOverlappedResult">
CSerialPort::GetOverlappedResult</a><br>
<a href="#CancelIo">
CSerialPort::CancelIo</a><br>
<a href="#GetConfig">
CSerialPort::GetConfig</a><br>
<a href="#GetDefaultConfig">
CSerialPort::GetDefaultConfig</a><br>
<a href="#SetConfig">
CSerialPort::SetConfig</a><br>
<a href="#SetDefaultConfig">
CSerialPort::SetDefaultConfig</a><br>
<a href="#ClearBreak">
CSerialPort::ClearBreak</a><br>
<a href="#SetBreak">
CSerialPort::SetBreak</a><br>
<a href="#ClearError">
CSerialPort::ClearError</a><br>
<a href="#GetStatus">
CSerialPort::GetStatus</a><br>
<a href="#GetState">
CSerialPort::GetState</a><br>
<a href="#SetState">
CSerialPort::SetState</a><br>
<a href="#Escape">
CSerialPort::Escape</a><br>

⌨️ 快捷键说明

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