checkcom.cpp

来自「Linux环境下的串口通讯程序」· C++ 代码 · 共 52 行

CPP
52
字号
//---------------------------------------------------------------------------#include <clx.h>#pragma hdrstop#include "checkcom.h"#include <sys/time.h>#include <sys/types.h>
#include <unistd.h>#include <signal.h>#pragma package(smart_init)//---------------------------------------------------------------------------//   Important: Methods and properties of objects in CLX can only be//   used in a method called using Synchronize, for example:////      Synchronize(&UpdateCaption);////   where UpdateCaption could look like:////      void __fastcall TCheckCom::UpdateCaption()//      {//        Form1->Caption = "Updated in a thread";//      }//---------------------------------------------------------------------------int p_com_fd;__fastcall TCheckCom::TCheckCom(bool CreateSuspended)    : TThread(CreateSuspended){}//---------------------------------------------------------------------------void __fastcall TCheckCom::Execute(){    fd_set rfd;    int max_fd;

    while(true)
    {
        if(Terminated)
            break;
        FD_ZERO(&rfd);
        FD_SET(p_com_fd, &rfd);
        max_fd = p_com_fd + 1;
        select(max_fd, &rfd, NULL, NULL, NULL);
        if(FD_ISSET(p_com_fd, &rfd))
            raise(SIGUSR1);
    }
}
//--------------------------------------------------------------------------- 

⌨️ 快捷键说明

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