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

📄 serialport.htm

📁 串口编程控件,可以读取串口发出的数据,并且可以向串中写入数据
💻 HTM
📖 第 1 页 / 共 3 页
字号:
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the ClearCommError SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="GetStatus"></a>CSerialPort::GetStatus</b></p>
<p><b>void GetStatus(COMMSTAT&amp; </b><i>stat</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Another way of returning information which the SDK call ClearCommError 
returns. See the Win32 SDK documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="GetState"></a>CSerialPort::GetState</b></p>
<p><b>void GetState(DCB&amp; </b><i>dcb</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the GetCommState SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="SetState"></a>CSerialPort::SetState</b></p>
<p><b>void SetState(DCB&amp; </b><i>dcb</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the SetCommState SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="Escape"></a>CSerialPort::Escape</b></p>
<p><b>void Escape(DWORD </b><i>dwFunc</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the EscapeCommFunction SDK function call. See the Win32 
SDK documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="ClearDTR"></a>CSerialPort::ClearDTR</b></p>
<p><b>void ClearDTR()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Escape function using the constant CLRDTR which lowers the DTR 
line.</p>

<p>&nbsp;</p>

<p><b><a name="ClearRTS"></a>CSerialPort::ClearRTS</b></p>
<p><b>void ClearRTS()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Escape function using the constant CLRRTS which lowers the RTS 
line.</p>

<p>&nbsp;</p>

<p><b><a name="SetDTR"></a>CSerialPort::SetDTR</b></p>
<p><b>void SetDTR()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Escape function using the constant SETDTR which raises the DTR 
line.</p>

<p>&nbsp;</p>

<p><b><a name="SetRTS"></a>CSerialPort::SetRTS</b></p>
<p><b>void SetRTS()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Escape function using the constant SETRTS which raises the RTS 
line.</p>

<p>&nbsp;</p>

<p><b><a name="SetXOFF"></a>CSerialPort::SetXOFF</b></p>
<p><b>void SetXOFF()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Escape function using the constant SETXOFF which causes 
transmission to act as if an XOFF character has been received..</p>

<p>&nbsp;</p>

<p><b><a name="SetXON"></a>CSerialPort::SetXON</b></p>
<p><b>void SetXON()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Escape function using the constant SETXON which causes transmission 
to act as if an XON character has been received..</p>

<p>&nbsp;</p>

<p><b><a name="GetProperties"></a>CSerialPort::GetProperties</b></p>
<p><b>void GetProperties(COMMPROP&amp; </b><i>properties</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the GetCommProperties SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="GetModemStatus"></a>CSerialPort::GetModemStatus</b></p>
<p><b>void GetModemStatus(DWORD&amp; </b><i>dwModemStatus</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the GetCommModemStatus SDK function call. See the Win32 
SDK documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="SetTimeouts"></a>CSerialPort::SetTimeouts</b></p>
<p><b>void SetTimeouts(COMMTIMEOUTS&amp; </b><i>timeouts</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the SetCommTimeouts SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="GetTimeouts"></a>CSerialPort::GetTimeouts</b></p>
<p><b>void GetTimeouts(COMMTIMEOUTS&amp; </b><i>timeouts</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the GetCommTimeouts SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="Set0Timeout"></a>CSerialPort::Set0Timeout</b></p>
<p><b>void Set0Timeout()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Configure both send and receive timeouts to be 0. This cause writes to return 
immediately and for reads to return with whatever data is waiting in the receive 
buffer rather than wait for the specified amount of bytes to arrive.</p>

<p>&nbsp;</p>

<p><b><a name="Set0WriteTimeout"></a>CSerialPort::Set0WriteTimeout</b></p>
<p><b>void Set0WriteTimeout()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Configures the send timeouts to be 0. This cause writes to return 
immediately.</p>

<p>&nbsp;</p>

<p><b><a name="Set0ReadTimeout"></a>CSerialPort::Set0ReadTimeout</b></p>
<p><b>void Set0ReadTimeout()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Configure the receive timeout to be 0. This cause reads to return with 
whatever data is waiting in the receive buffer rather than wait for the 
specified amount of bytes to arrive.</p>

<p>&nbsp;</p>

<p><b><a name="SetMask"></a>CSerialPort::SetMask</b></p>
<p><b>void SetMask(DWORD </b><i>dwMask</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the SetCommMask SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="GetMask"></a>CSerialPort::GetMask</b></p>
<p><b>void GetMask(DWORD&amp; </b><i>dwMask</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the GetCommMask SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="WaitEvent"></a>CSerialPort::WaitEvent</b></p>
<p><b>void WaitEvent(DWORD&amp; </b><i>dwMask</i><b>)<br>
BOOL WaitEvent(DWORD&amp; </b><i>dwMask</i><b>, OVERLAPPED&amp; </b><i>overlapped</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Return Value</b></p>
<p>TRUE if the overlapped read completely synchronously, FALSE if the operation 
is to be completed asynchronously.</p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the WaitCommEvent SDK function call. The second version of 
WaitEvent is the overlapped version which will return immediately and you can 
wait for the manual reset event member of the OVERLAPPED structure to become 
signalled in your code. See the Win32 SDK documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="Flush"></a>CSerialPort::Flush</b></p>
<p><b>void Flush()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the FlushFileBuffers SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="Purge"></a>CSerialPort::Purge</b></p>
<p><b>void Purge(DWORD </b><i>dwFlags</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the PurgeComm SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="TerminateOutstandingWrites"></a>
CSerialPort::TerminateOutstandingWrites</b></p>
<p><b>void TerminateOutstandingWrites()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Purge function using the constant PURGE_TXABORT which terminates 
all outstanding write operations and returns immediately, even if the write 
operations have not been completed.</p>

<p>&nbsp;</p>

<p><b><a name="TerminateOutstandingReads"></a>
CSerialPort::TerminateOutstandingReads</b></p>
<p><b>void TerminateOutstandingReads()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Purge function using the constant PURGE_RXABORT which terminates 
all outstanding read operations and returns immediately, even if the read 
operations have not been completed.</p>

<p>&nbsp;</p>

<p><b><a name="ClearWriteBuffer"></a>CSerialPort::ClearWriteBuffer</b></p>
<p><b>void ClearWriteBuffer()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Purge function using the constant PURGE_TXCLEAR which clears the 
output buffer (if the device driver has one)..</p>

<p></p>

<p><b><a name="ClearReadBuffer"></a>CSerialPort::ClearReadBuffer</b></p>
<p><b>void ClearReadBuffer()<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Calls the Purge function using the constant PURGE_RXCLEAR which clears the 
input buffer (if the device driver has one)..</p>

<p>&nbsp;</p>

<p><b><a name="Setup"></a>CSerialPort::Setup</b></p>
<p><b>void Setup(DWORD </b><i>dwInQueue<b>, </b> </i><b>DWORD
</b><i>dwOutQueue</i><b>)<br>
&nbsp;&nbsp;&nbsp;</b> <b> throw( CSerialException* );</b></p>
<p><b>Remarks</b></p>
<p>Simple wrapper for the SetupComm SDK function call. See the Win32 SDK 
documentation for further details.</p>

<p>&nbsp;</p>

<p><b><a name="OnCompletion"></a>CSerialPort::OnCompletion</b></p>
<p><b>virtual void OnCompletion(DWORD
</b><i>dwErrorCode</i>,<b> DWORD </b><i>dwCount</i><b>, LPOVERLAPPED </b><i>
lpOverlapped</i><b>);<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Parameters</b></p>
<p><i>dwErrorCode</i>&nbsp;&nbsp;</p>
<p>Specifies the I/O completion status. This parameter may be one of the 
following values:</p>
<table width="582">
  <tbody>
    <tr vAlign="top">
      <td width="151">
        <p>Value</p>
      <td width="417">
        <p>Meaning</p>
    <tr vAlign="top">
      <td width="151">
        <p>0</p>
      <td width="417">
        <p>The I/O was successful.</p>
    <tr vAlign="top">
      <td width="151">
        <p>ERROR_HANDLE_EOF</p>
      <td width="417">
        <p>The ReadFileEx function tried to read past the end of the file.</p>
    </tr>
  </tbody>
</table>
<p><i>dwCount</i> Specifies the number of bytes transferred. If an error occurs, 
this parameter is zero</p>

<p><i>lpOverlapped</i>  Points to the OVERLAPPED structure specified by the 
asynchronous I/O function.</p>
<p><b>Remarks</b></p>
<p>This function is called as the completion routine for any asynchronous calls 
to WriteEx or ReadEx. In your derived class from CSerialPort, you can override 
this function to perform your own specific code in reaction to an asynchronous 
call completing. Don't forget to call the parent version namely this function 
&quot;CSerialPort::OnCompletion&quot; as it handles the cleanup of the memory allocated 
for the lpOverlapped parameter.</p>

<strong>

<p></p>

</strong>

<p><b><a name="BytesWaiting"></a>CSerialPort::BytesWaiting</b></p>
<p><b>
DWORD BytesWaiting();<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Return Value</b></p>
<p>The number of bytes waiting to be read from the serial port</p>
<p><b>Remarks</b></p>
<p>The function returns the number of bytes waiting to be read from the serial 
port</p>

<strong>

<p>&nbsp;</p>

</strong>

<p><b><a name="DataWaiting"></a>CSerialPort::DataWaiting</b></p>
<p><b>BOOL DataWaiting(DWORD <i>dwTimeout</i>);<br>
&nbsp;&nbsp;&nbsp; throw( CSerialException* );</b></p>
<p><b>Parameters</b></p>
<p><i>dwTimeout</i> Specifies The timeout to wait in 
milliseconds to determine if data has arrived.</p>
<p><b>Return Value</b></p>
<p>TRUE if data has arrived in the specified timeout interval, otherwise FALSE.</p>
<p><b>Remarks</b></p>
<p>The function waits for the specified interval to see if data has arrived on 
the serial port.</p>

<p></p>

<p>&nbsp;</p>

<strong>

<p>&nbsp;</p>

</strong>

<h2><b><a name="Enhancements"></a>Planned Enhancements</b></h2>

<ul>
  <li>Provide a better sample app. At the moment, it's very much a test program 
	which tests all of the functions. </li>
  <li>If you have any other suggested improvements, please let me know so that I 
	can incorporate them into the next release.
  </li>
</ul>

<strong>

<p></p>

</strong>

<p></p>

<strong>

<p>&nbsp;</p>

</strong>

<h2><b><a name="Contact"></a>Contacting the Author</b></h2>

<p>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>
25 January 2006</p>
</body>
</html>

⌨️ 快捷键说明

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