亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? vcthread.cpp

?? c++實(shí)現(xiàn)的一個(gè)個(gè)串口通訊類
?? CPP
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
///////////////////////////////////////////////////////////////
// 文件名: ApexComm.cpp
// 功能:注冊(cè)控件類
// 作者:陳++
// 時(shí)間:2004.4.15-1999.4.22 創(chuàng)建
//       2004.5.15修改,整理
///////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "vcThread.h"
#include "define.h"

IMPLEMENT_DYNAMIC(TReadThread, CWinThread)

////////////////////////////////////////////////////////
//  過(guò)程: TReadThread.Thread
//
//  目的: 讀線程運(yùn)行并執(zhí)行相應(yīng)的功能.
//
//  參數(shù):
//    None.
//
//  返回值:
//    None.
//
//  注釋:
//
//    The Read Thread uses overlapped ReadFile and sends any data
//    read from the comm port to the Comm32Window.  This is
//    eventually done through a PostMessage so that the Read Thread
//    is never away from the comm port very long.  This also provides
//    natural desynchronization between the Read thread and the UI.
//
//    If the CloseEvent object is signaled, the Read Thread returns.
//
//        Separating the Read and Write threads is natural for a application
//    where there is no need for synchronization between
//    reading and writing.  However, if there is such a need (for example,
//    most file transfer algorithms synchronize the reading and writing),
//     it would make a lot more sense to have a single thread to handle
//    both reading and writing.
//

TReadThread::TReadThread()
{

}

BOOL TReadThread::InitInstance()
{
   char szInputBuffer[TINPUTBUFFERSIZE];
   DWORD nNumberOfBytesRead;
   HANDLE HandlesToWaitFor[3];
   DWORD dwHandleSignaled;
   DWORD fdwEvtMask;
   // Needed for overlapped I/O (ReadFile)
   OVERLAPPED overlappedRead;
   // Needed for overlapped Comm Event handling.
   OVERLAPPED overlappedCommEvent;
   memset( &overlappedRead,0, sizeof(overlappedRead));
   memset( &overlappedCommEvent,0, sizeof(overlappedCommEvent));
   // Lets put an event in the Read overlapped structure.
   overlappedRead.hEvent = CreateEvent( NULL, true, false, NULL);
   if (overlappedRead.hEvent == 0 )
   {
      PostHangupCall();
      goto EndReadThread;
   }
   ResetEvent(overlappedRead.hEvent);
   // And an event for the CommEvent overlapped structure.
   overlappedCommEvent.hEvent = CreateEvent( NULL, true, false, NULL);
   if (overlappedCommEvent.hEvent == 0 )
   {
      PostHangupCall();
      goto EndReadThread;
   }
   ResetEvent(overlappedCommEvent.hEvent);
   // We will be waiting on these objects.
   HandlesToWaitFor[0] = m_hCloseEvent;
   HandlesToWaitFor[1] = overlappedCommEvent.hEvent;
   HandlesToWaitFor[2] = overlappedRead.hEvent;
   // Setup CommEvent handling.
   // Set the comm mask so we receive error signals.
   if (! SetCommMask(m_hCommFile, EV_ERR | EV_RLSD | EV_RING | EV_CTS | EV_DSR)) 
   {
      PostHangupCall();
      goto EndReadThread;
   }

   // Start waiting for CommEvents (Errors)
   if (! SetupCommEvent( &overlappedCommEvent,  fdwEvtMask ) )
      goto EndReadThread;

   // Start waiting for Read events.
   if (! SetupReadEvent( &overlappedRead,
      szInputBuffer, TINPUTBUFFERSIZE,
      nNumberOfBytesRead ) )
      goto EndReadThread;
   // Keep looping until we break out.
   while (true)
   {
      // Wait until some event occurs (data to read; error; stopping).
      dwHandleSignaled = WaitForMultipleObjects(3, HandlesToWaitFor,false, INFINITE);
      // Which event occured?
      switch (dwHandleSignaled) 
      {
      case  WAIT_OBJECT_0:     // Signal to end the thread.
         // Time to return.
         goto EndReadThread;         
      case WAIT_OBJECT_0 + 1: // CommEvent signaled.
         // Handle the CommEvent.
         if (! HandleCommEvent( &overlappedCommEvent, fdwEvtMask, true ) )
            goto EndReadThread;
         // Start waiting for the next CommEvent.
         if (! SetupCommEvent( &overlappedCommEvent, fdwEvtMask ) )
            goto EndReadThread;
         break;
      case WAIT_OBJECT_0 + 2: // Read Event signaled.
         // Get the new data!
         if (! HandleReadEvent( &overlappedRead,szInputBuffer,
            TINPUTBUFFERSIZE,nNumberOfBytesRead )) 
            goto EndReadThread;
         // Wait for more new data.
         if (! SetupReadEvent( &overlappedRead,szInputBuffer, TINPUTBUFFERSIZE,
            nNumberOfBytesRead ) )
            goto EndReadThread;
         break;
      case WAIT_FAILED:       // Wait failed.  Shouldn't happen.
         PostHangupCall();
         goto EndReadThread;         
      default:    // This case should never occur.
         PostHangupCall();
         goto EndReadThread;
      } //{case dwHandleSignaled}
   } //{while True}
   // Time to clean up Read Thread.
EndReadThread:
   PurgeComm( m_hCommFile, PURGE_RXABORT + PURGE_RXCLEAR );
   CloseHandle( overlappedRead.hEvent );
   CloseHandle( overlappedCommEvent.hEvent );
   return false;
}


///////////////////////////////////////////////////////
//讀線程類提供的方法
//
//  函數(shù): SetupCommEvent(LPOVERLAPPED, LPDWORD)
//
//  目的: Sets up the overlapped WaitCommEvent call.
//
//  參數(shù):
//    lpOverlappedCommEvent - Pointer to the overlapped structure to use.
//    lpfdwEvtMask          - Pointer to DWORD to received Event data.
//
//  返回值:
//    TRUE if able to successfully setup the WaitCommEvent.
//    FALSE if unable to setup WaitCommEvent, unable to handle
//    an existing outstanding event or if the CloseEvent has been signaled.
//
//  注釋:
//
//    This function is a helper function for the Read Thread that sets up
//    the WaitCommEvent so we can deal with comm events (like Comm errors)
//    if they occur.
//

bool TReadThread::SetupCommEvent( OVERLAPPED* lpOverlappedCommEvent,DWORD & lpfdwEvtMask)
{
   DWORD dwLastError;
   //Result = false;

StartSetupCommEvent:   
   //確定關(guān)閉事件還沒有被啟動(dòng),查看它的目的是為了防止關(guān)閉事件遞歸調(diào)用.
   //當(dāng)返回值不為WAIT_TIMEOUT時(shí)表明關(guān)閉事件已被啟動(dòng)
   if (WAIT_TIMEOUT != WaitForSingleObject( m_hCloseEvent,0 ) )
      return false;
   // Start waiting for Comm Errors.
   if (WaitCommEvent( m_hCommFile, &lpfdwEvtMask, lpOverlappedCommEvent ) )
   {
      // This could happen if there was an error waiting on the
      // comm port.  Lets try and handle it.
      if (! HandleCommEvent( NULL, lpfdwEvtMask, false ) )
      {
         //{??? GetOverlappedResult does not handle "NULL" as defined by Borland}
         return false;
      }
      // What could cause infinite recursion at this point?
      goto StartSetupCommEvent;
   }

   // We expect ERROR_IO_PENDING returned from WaitCommEvent
   // because we are waiting with an overlapped structure.
   dwLastError = GetLastError();
   // LastError was ERROR_IO_PENDING, as expected.
   if (dwLastError == ERROR_IO_PENDING)    
      return true;
   
   // Its possible for this error to occur if the
   // service provider has closed the port.  Time to end.
   if (dwLastError == ERROR_INVALID_HANDLE )
      return false;
   // Unexpected error. No idea what could cause this to happen.
   PostHangupCall();
   return false;
}//{TReadThread.SetupCommEvent}


//////////////////////////////////////////////////////////
//  函數(shù): SetupReadEvent(LPOVERLAPPED, LPSTR, DWORD, LPDWORD)
//
//  目的: Sets up an overlapped ReadFile
//
//  參數(shù):
//    lpOverlappedRead      - address of overlapped structure to use.
//    lpszInputBuffer       - Buffer to place incoming bytes.
//    dwSizeofBuffer        - size of lpszInputBuffer.
//    lpnNumberOfBytesRead  - address of DWORD to place the number of read bytes.
//
//  返回值:
//    TRUE if able to successfully setup the ReadFile.  FALSE if there
//    was a failure setting up or if the CloseEvent object was signaled.
//
//  注釋:
//
//    This function is a helper function for the Read Thread.  This
//    function sets up the overlapped ReadFile so that it can later
//    be waited on (or more appropriatly, so the event in the overlapped
//    structure can be waited upon).  If there is data waiting, it is
//    handled and the next ReadFile is initiated.
//    Another possible reason for returning FALSE is if the comm port
//    is closed by the service provider.
//
//

bool TReadThread::SetupReadEvent( OVERLAPPED* lpOverlappedRead,LPSTR lpszInputBuffer,DWORD dwSizeofBuffer,DWORD & lpnNumberOfBytesRead)
{
   DWORD dwLastError;
   //Result = False;
StartSetupReadEvent:
   // Make sure the CloseEvent hasn't been signaled yet.
   // Check is needed because this function is potentially recursive.
   if (WAIT_TIMEOUT != WaitForSingleObject(m_hCloseEvent,0) )
      return false;
   // Start the overlapped ReadFile.
   if (ReadFile( m_hCommFile,
      lpszInputBuffer, dwSizeofBuffer,
      &lpnNumberOfBytesRead, lpOverlappedRead ) )
   {
      // This would only happen if there was data waiting to be read.
      // Handle the data.
      if (! HandleReadData( lpszInputBuffer, lpnNumberOfBytesRead ) )
         return false;
      // Start waiting for more data.
      goto StartSetupReadEvent;
   }
   // ReadFile failed.  Expected because of overlapped I/O.
   dwLastError = GetLastError();
   // LastError was ERROR_IO_PENDING, as expected.
   
   if (dwLastError == ERROR_IO_PENDING )   
      return true;
   
   // Its possible for this error to occur if the
   // service provider has closed the port.  Time to end.
   if (dwLastError == ERROR_INVALID_HANDLE )
      return false;
   // Unexpected error come here. No idea what could cause this to happen.
   PostHangupCall();
   return false;
}//{TReadThread.SetupReadEvent}


///////////////////////////////////////////////////////
//  函數(shù): HandleCommEvent(LPOVERLAPPED, LPDWORD, BOOL)
//
//  目的: 處理標(biāo)準(zhǔn)的通訊事件.
//
//  參數(shù):
//    lpOverlappedCommEvent - Pointer to the overlapped structure to use.
//    lpfdwEvtMask          - Pointer to DWORD to received Event data.
//    fRetrieveEvent        - Flag to signal if the event needs to be
//                            retrieved, or has already been retrieved.
//
//  返回值:
//    TRUE if able to handle a Comm Event.
//    FALSE if unable to setup WaitCommEvent, unable to handle
//    an existing outstanding event or if the CloseEvent has been signaled.
//
//  注釋:
//
//    This function is a helper function for the Read Thread that (if
//    fRetrieveEvent == TRUE) retrieves an outstanding CommEvent and
//    deals with it.  The only event that should occur is an EV_ERR event,
//    signalling that there has been an error on the comm port.
//
//    Normally, comm errors would not be put into the normal data stream
//    as this sample is demonstrating.  Putting it in a status bar would
//    be more appropriate for a real application.
//

bool TReadThread::HandleCommEvent(OVERLAPPED* lpOverlappedCommEvent,DWORD & lpfdwEvtMask,bool fRetrieveEvent)
{
   DWORD dwDummy;
   DWORD dwErrors;
   DWORD dwLastError;
   // If this fails, it could be because the file was closed (and I/O is
   // finished) or because the overlapped I/O is still in progress.  In
   // either case (or any others) its a bug and return FALSE.
   if (fRetrieveEvent) 
   {
      if (! GetOverlappedResult( m_hCommFile,lpOverlappedCommEvent, &dwDummy, false))
      {
         dwLastError = GetLastError();
         // Its possible for this error to occur if the
         // service provider has closed the port.  Time to end.
         if (dwLastError == ERROR_INVALID_HANDLE )
            return false;
         PostHangupCall();//ERROR_IO_INCOMPLETE
         return false;
      }
   }
   // Was the event an error? EV_ERR 0x80
   if ((lpfdwEvtMask && EV_ERR) != 0 )
   {
      // Which error was it?
      if (! ClearCommError( m_hCommFile, &dwErrors, NULL ) )
      {
         dwLastError = GetLastError();
         // Its possible for this error to occur if the
         // service provider has closed the port.  Time to end.
         if (dwLastError == ERROR_INVALID_HANDLE )
            return false;
         PostHangupCall ();
         return false;

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色域天天综合网| 久久综合狠狠综合久久综合88| 色94色欧美sute亚洲线路二 | 日韩一二三四区| 欧美一级高清片| 日本一区二区免费在线| 91麻豆精品久久久久蜜臀| 成人av网站免费观看| 欧美日韩一区二区三区不卡| 欧美一区二区三区四区高清| 久久久久国产精品厨房| 亚洲激情av在线| 喷白浆一区二区| eeuss鲁一区二区三区| 欧美综合一区二区三区| 精品福利av导航| 亚洲愉拍自拍另类高清精品| 久久99精品国产| 欧美视频完全免费看| 久久久www免费人成精品| 亚洲一区二区视频| 国产激情视频一区二区三区欧美| 在线一区二区视频| 久久亚洲精精品中文字幕早川悠里 | 色婷婷av一区| 久久久777精品电影网影网 | 五月综合激情婷婷六月色窝| 老色鬼精品视频在线观看播放| 狠狠色综合日日| 7777精品伊人久久久大香线蕉超级流畅| 欧美一区二区久久| 亚洲精品乱码久久久久| 国产精品影视天天线| 欧美夫妻性生活| 亚洲一区二区三区四区的| 不卡视频免费播放| 国产欧美一区在线| 国产精品18久久久久久vr| 国产999精品久久久久久绿帽| 91视频观看视频| 国产精品无遮挡| 成人午夜激情片| 中文一区二区在线观看| 成人国产一区二区三区精品| 欧美成人bangbros| 国产一区二区三区视频在线播放| 欧美一区二区三区免费大片| 爽好多水快深点欧美视频| 欧美蜜桃一区二区三区 | 国内精品免费**视频| 欧美三级日韩三级国产三级| 一区二区三区毛片| 欧美区在线观看| 久国产精品韩国三级视频| 精品久久久久久久人人人人传媒| 国产一区二区视频在线播放| 国产精品素人一区二区| av一二三不卡影片| 午夜欧美电影在线观看| 欧美电影免费观看完整版| 日本韩国一区二区| 日韩**一区毛片| 国产日韩欧美综合在线| 色八戒一区二区三区| 精品中文字幕一区二区小辣椒| 国产无人区一区二区三区| 欧美综合在线视频| 久久成人av少妇免费| 中文字幕日韩精品一区| 6080日韩午夜伦伦午夜伦| a美女胸又www黄视频久久| 日韩精品电影在线| 中文字幕免费一区| 制服丝袜国产精品| 91蜜桃传媒精品久久久一区二区| 免费观看91视频大全| 欧美日韩午夜影院| 视频一区视频二区中文| 日韩美女精品在线| 久久久噜噜噜久噜久久综合| 色欧美乱欧美15图片| 福利电影一区二区三区| 日韩 欧美一区二区三区| 亚洲精品乱码久久久久| 国产精品婷婷午夜在线观看| 精品少妇一区二区三区| 欧美日韩不卡一区二区| 91国产丝袜在线播放| 不卡一卡二卡三乱码免费网站 | 国产精品77777竹菊影视小说| 亚洲国产欧美在线| 亚洲一区二区在线播放相泽| 日韩精品五月天| 国产精品三级av在线播放| 日韩一区国产二区欧美三区| 欧美亚洲日本一区| 欧美日韩中文另类| 欧洲亚洲精品在线| 欧美日韩在线三级| 欧美午夜精品电影| 欧美午夜在线一二页| 欧美午夜不卡在线观看免费| 在线观看日韩国产| 欧美精品在欧美一区二区少妇| 在线免费不卡视频| 777午夜精品免费视频| 日韩一区二区在线观看视频| 久久亚洲综合色一区二区三区| 亚洲丝袜自拍清纯另类| 久久蜜桃av一区二区天堂| 中文字幕第一区综合| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 成人18视频在线播放| 色偷偷一区二区三区| 欧美日韩另类一区| 国产一区二区h| 日韩专区中文字幕一区二区| 日韩和欧美的一区| 激情av综合网| 99久久婷婷国产| 欧美精品粉嫩高潮一区二区| 欧美va亚洲va| 一区二区三区中文字幕在线观看| 婷婷综合五月天| 国产99久久久国产精品潘金网站| 91福利在线观看| 久久久不卡网国产精品二区 | 日本人妖一区二区| 成人黄色大片在线观看| 91精品国产综合久久久久久久 | 欧美视频一区二区三区四区| 久久亚洲免费视频| 日本欧美韩国一区三区| 91蜜桃在线免费视频| 欧美国产综合一区二区| 偷窥少妇高潮呻吟av久久免费| 成年人午夜久久久| 久久精品在这里| 久久成人免费网| 欧美视频一区二区三区四区| 中文字幕在线一区| 国内精品伊人久久久久影院对白| 欧美日韩国产一级二级| 夜夜嗨av一区二区三区四季av| 波多野洁衣一区| 久久久91精品国产一区二区精品 | 国产一区二区不卡| 精品久久久久香蕉网| 蜜桃久久精品一区二区| 欧美亚洲禁片免费| 亚洲r级在线视频| 欧美怡红院视频| 一区二区三区在线视频播放| 日韩欧美一区二区视频| 成人亚洲精品久久久久软件| 蜜臀av一区二区在线免费观看| 97久久精品人人澡人人爽| 中文字幕第一区二区| 一本久久精品一区二区| 一区二区三区国产精品| 欧美精品在线视频| 精品写真视频在线观看| 欧美国产精品v| 欧洲在线/亚洲| 日本在线不卡视频| 2023国产精品| 国产v综合v亚洲欧| 亚洲精品v日韩精品| 欧美日本一道本在线视频| 天使萌一区二区三区免费观看| 日韩一区二区免费视频| 国产伦理精品不卡| 亚洲乱码国产乱码精品精可以看 | 精品日产卡一卡二卡麻豆| 国产精品996| 亚洲国产sm捆绑调教视频| 日韩欧美123| 99精品视频在线播放观看| 日韩影院免费视频| 国产精品传媒在线| 91精品在线麻豆| 成a人片国产精品| 毛片av一区二区| 亚洲综合丝袜美腿| 久久精品亚洲精品国产欧美| 欧美年轻男男videosbes| 成人一区二区三区中文字幕| 婷婷国产v国产偷v亚洲高清| 国产精品网站在线| 精品国产1区二区| 亚洲欧洲性图库| 欧美va在线播放| 欧美二区在线观看| 欧美中文字幕不卡| 成人av电影免费在线播放| 久久91精品久久久久久秒播| 日韩激情一区二区| 亚洲成人三级小说| 亚洲一卡二卡三卡四卡| 综合激情成人伊人|