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

📄 d065.bmp.txt

📁 Visual C++通信编程实例
💻 TXT
字号:
bRead = rIRUE;
bResult = GetOverlappedResult(port->m_hComm,    //Handle to COMM port
                   &port->m_ov, //Overlappedstructure
                                                       &BytesRead,     //Stores number ofbytes read
                                                                                           IRUE);                    // Wait flag
            // deal with the error code
         if (!bResult)
         {
                   port->ProcessErrorMessage("GetOverlappedResults() in ReadFile()");
          }
        // close if ( !bRead)
LeaveCriticalSection(&port->m_csCommunicationSync);
                             //notify parent that a byte was received
         ::SendMessage《port->m_pOwner)->m_hWnd, WM_COMM_RXCHAR, (WPARAIVD
RXBuff, (LPARAM) pcnt->m_nPortNr);
                          } // end foreverloop
          }
    5)写数据程序。在CSerialPort类中,写数据调用WriteToPort豳数,通过SetEvent函数
设置写事件,通知辅助线程有数据需要发送。写数据函数代码如下:
// Write a string to the port
void CSeriaIPort::WriteToPort(char* string)
{
        assert(m_hComm l= 0);
          memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer》;
         strcpy(m_szWnteBuffer, string);
SetEvent(m_hWriteEvent);
}
数据字符写入函数:
void CSeriaIPort::WriteChar(CSerialPort* port)
{
         BOOL bWrite = TRUE;
         BOOL bResult = TRUE;
         DWORD BytesSent = 0;
    ResetEvent(port->m hWriteEvent);
// Gain ownership of the critical section
EnterCriO:calSection(&port->m_csCommunicationSync);
if (bWrite)
{
65

⌨️ 快捷键说明

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