📄 subject_60227.htm
字号:
<p>
序号:60227 发表者:賴京州 发表日期:2003-11-12 13:57:39
<br>主题:能否討論一下在讀 i/o port 中ReadFile函數的用法,msdn太簡了!
<br>内容:能否討論一下在讀 i/o port 中ReadFile函數的用法,msdn太簡了!<BR><BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:golen 回复日期:2003-11-12 14:12:48
<br>内容:这个本来就简单。哈哈。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bottle_fish 回复日期:2003-11-12 14:14:56
<br>内容:Input and Output<BR>The I/O functions read and write data to and from files and devices. File I/O operations take place in text mode or binary mode. The Microsoft run-time library has three types of I/O functions: <BR><BR>Stream I/O functions treat data as a stream of individual characters.<BR><BR><BR>Low-level I/O functions invoke the operating system directly for lower-level operation than that provided by stream I/O.<BR><BR><BR>Console and port I/O functions read or write directly to a console (keyboard and screen) or an I/O port (such as a printer port). <BR>Warning Because stream functions are buffered and low-level functions are not, these two types of functions are generally incompatible. For processing a particular file, use either stream or low-level functions exclusively.<BR><BR>is it simple?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:賴京州 回复日期:2003-11-12 14:29:51
<br>内容: EnterCriticalSection(&port->m_csCommunicationSync);<BR><BR> // ClearCommError() will update the COMSTAT structure and<BR> // clear any other errors.<BR> <BR> bResult = ClearCommError(port->m_hComm, &dwError, &comstat);<BR><BR> LeaveCriticalSection(&port->m_csCommunicationSync);<BR><BR> // start forever loop. I use this type of loop because I<BR> // do not know at runtime how many loops this will have to<BR> // run. My solution is to start a forever loop and to<BR> // break out of it when I have processed all of the<BR> // data available. Be careful with this approach and<BR> // be sure your loop will exit.<BR> // My reasons for this are not as clear in this sample <BR> // as it is in my production code, but I have found this <BR> // solutiion to be the most efficient way to do this.<BR> <BR> if (comstat.cbInQue == 0)<BR> {<BR> // break out when all bytes have been read<BR> break;<BR> }<BR> <BR> EnterCriticalSection(&port->m_csCommunicationSync);<BR><BR> if (bRead)<BR> {<BR> bResult = ReadFile(port->m_hComm, // Handle to COMM port <BR> &RXBuff, // RX Buffer Pointer<BR> 1, // Read one byte<BR> &BytesRead, // Stores number of bytes read<BR> &port->m_ov); // pointer to the m_ov structure<BR> // deal with the error code <BR> if (!bResult) <BR> { <BR> switch (dwError = GetLastError()) <BR> { <BR> case ERROR_IO_PENDING: <BR> { <BR> // asynchronous i/o is still in progress <BR> // Proceed on to GetOverlappedResults();<BR> bRead = FALSE;<BR> break;<BR> }<BR> default:<BR> {<BR> // Another error has occured. Process this error.<BR> port->ProcessErrorMessage("ReadFile()");<BR> break;<BR> } <BR> }<BR> }<BR> else<BR> {<BR> // ReadFile() returned complete. It is not necessary to call GetOverlappedResults()<BR> bRead = TRUE;<BR> }<BR> } // close if (bRead)<BR><BR> if (!bRead)<BR> {<BR> bRead = TRUE;<BR> bResult = GetOverlappedResult(port->m_hComm, // Handle to COMM port <BR> &port->m_ov, // Overlapped structure<BR> &BytesRead, // Stores number of bytes read<BR> TRUE); // Wait flag<BR><BR> // deal with the error code <BR> if (!bResult) <BR> {<BR> port->ProcessErrorMessage("GetOverlappedResults() in ReadFile()");<BR> } <BR> } // close if (!bRead)<BR> <BR> LeaveCriticalSection(&port->m_csCommunicationSync);<BR><BR> // notify parent that a byte was received<BR> ::SendMessage((port->m_pOwner)->m_hWnd, WM_COMM_RXCHAR, (WPARAM) RXBuff, (LPARAM) port->m_nPortNr);<BR> } // end forever loop<BR>return RXBuff;
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -