📄 serialport.htm
字号:
</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> </p>
<p><b><a name="GetStatus"></a>CSerialPort::GetStatus</b></p>
<p><b>void GetStatus(COMMSTAT& </b><i>stat</i><b>)<br>
</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> </p>
<p><b><a name="GetState"></a>CSerialPort::GetState</b></p>
<p><b>void GetState(DCB& </b><i>dcb</i><b>)<br>
</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> </p>
<p><b><a name="SetState"></a>CSerialPort::SetState</b></p>
<p><b>void SetState(DCB& </b><i>dcb</i><b>)<br>
</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> </p>
<p><b><a name="Escape"></a>CSerialPort::Escape</b></p>
<p><b>void Escape(DWORD </b><i>dwFunc</i><b>)<br>
</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> </p>
<p><b><a name="ClearDTR"></a>CSerialPort::ClearDTR</b></p>
<p><b>void ClearDTR()<br>
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> </p>
<p><b><a name="ClearRTS"></a>CSerialPort::ClearRTS</b></p>
<p><b>void ClearRTS()<br>
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> </p>
<p><b><a name="SetDTR"></a>CSerialPort::SetDTR</b></p>
<p><b>void SetDTR()<br>
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> </p>
<p><b><a name="SetRTS"></a>CSerialPort::SetRTS</b></p>
<p><b>void SetRTS()<br>
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> </p>
<p><b><a name="SetXOFF"></a>CSerialPort::SetXOFF</b></p>
<p><b>void SetXOFF()<br>
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> </p>
<p><b><a name="SetXON"></a>CSerialPort::SetXON</b></p>
<p><b>void SetXON()<br>
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> </p>
<p><b><a name="GetProperties"></a>CSerialPort::GetProperties</b></p>
<p><b>void GetProperties(COMMPROP& </b><i>properties</i><b>)<br>
</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> </p>
<p><b><a name="GetModemStatus"></a>CSerialPort::GetModemStatus</b></p>
<p><b>void GetModemStatus(DWORD& </b><i>dwModemStatus</i><b>)<br>
</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> </p>
<p><b><a name="SetTimeouts"></a>CSerialPort::SetTimeouts</b></p>
<p><b>void SetTimeouts(COMMTIMEOUTS& </b><i>timeouts</i><b>)<br>
</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> </p>
<p><b><a name="GetTimeouts"></a>CSerialPort::GetTimeouts</b></p>
<p><b>void GetTimeouts(COMMTIMEOUTS& </b><i>timeouts</i><b>)<br>
</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> </p>
<p><b><a name="Set0Timeout"></a>CSerialPort::Set0Timeout</b></p>
<p><b>void Set0Timeout()<br>
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> </p>
<p><b><a name="Set0WriteTimeout"></a>CSerialPort::Set0WriteTimeout</b></p>
<p><b>void Set0WriteTimeout()<br>
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> </p>
<p><b><a name="Set0ReadTimeout"></a>CSerialPort::Set0ReadTimeout</b></p>
<p><b>void Set0ReadTimeout()<br>
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> </p>
<p><b><a name="SetMask"></a>CSerialPort::SetMask</b></p>
<p><b>void SetMask(DWORD </b><i>dwMask</i><b>)<br>
</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> </p>
<p><b><a name="GetMask"></a>CSerialPort::GetMask</b></p>
<p><b>void GetMask(DWORD& </b><i>dwMask</i><b>)<br>
</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> </p>
<p><b><a name="WaitEvent"></a>CSerialPort::WaitEvent</b></p>
<p><b>void WaitEvent(DWORD& </b><i>dwMask</i><b>)<br>
BOOL WaitEvent(DWORD& </b><i>dwMask</i><b>, OVERLAPPED& </b><i>overlapped</i><b>)<br>
</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> </p>
<p><b><a name="Flush"></a>CSerialPort::Flush</b></p>
<p><b>void Flush()<br>
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> </p>
<p><b><a name="Purge"></a>CSerialPort::Purge</b></p>
<p><b>void Purge(DWORD </b><i>dwFlags</i><b>)<br>
</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> </p>
<p><b><a name="TerminateOutstandingWrites"></a>
CSerialPort::TerminateOutstandingWrites</b></p>
<p><b>void TerminateOutstandingWrites()<br>
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> </p>
<p><b><a name="TerminateOutstandingReads"></a>
CSerialPort::TerminateOutstandingReads</b></p>
<p><b>void TerminateOutstandingReads()<br>
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> </p>
<p><b><a name="ClearWriteBuffer"></a>CSerialPort::ClearWriteBuffer</b></p>
<p><b>void ClearWriteBuffer()<br>
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>
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> </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>
</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> </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>
throw( CSerialException* );</b></p>
<p><b>Parameters</b></p>
<p><i>dwErrorCode</i> </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
"CSerialPort::OnCompletion" 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>
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> </p>
</strong>
<p><b><a name="DataWaiting"></a>CSerialPort::DataWaiting</b></p>
<p><b>BOOL DataWaiting(DWORD <i>dwTimeout</i>);<br>
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> </p>
<strong>
<p> </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> </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 + -