请问我使用ACE编写了一个串口通信程序,使用了反应器,但是问题是有数据发过来input_handle方法始终不会被调用是怎么回事?
代码如下:
#include "ace/Connector.h"
#include "ace/DEV_Addr.h"
#include "ace/DEV_Connector.h"
#include "ace/TTY_IO.h"
#include "ace/Reactor.h"
#include "ace/Svc_Handler.h"
#include <iostream>
typedef ACE_Connector<MyHandler,ACE_DEV_CONNECTOR> MyConnector;
class MyHandler:public ACE_Svc_Handler<ACE_DEV_STREAM,ACE_NULL_SYNCH>
{
private:
//ACE_TTY_IO recv;
char sizeBuffer[10];
public:
MyHandler()
{
ACE_TTY_IO::Serial_Params S_Params;
S_Params.baudrate = 9600;
S_Params.xonlim = 0;
S_Params.xofflim = 0;
S_Params.readmincharacters = 0;
S_Params.readtimeoutmsec = 1000;
S_Params.parityenb = true;
S_Params.paritymode = "EVEN";
S_Params.ctsenb = false;
S_Params.rtsenb = false;
S_Params.xinenb = false;
S_Params.xoutenb = false;
S_Params.modem = false;
S_Params.rcvenb = true;
S_Params.dsrenb = false;
S_Params.dtrdisable = false;
S_Params.databits = 8;
S_Params.stopbits = 1;
//S_Params.parityenb = true; //奇偶校验
this->peer().control(ACE_TTY_IO::SETPARAMS,&S_Params);
}
int open(void*)
{
ACE_DEBUG((LM_ERROR,"COM OPEN"));
this->peer().send("hello",sizeof("hello"));
ACE_Reactor::instance()->register_handler(this,ACE_Event_Handler::READ_MASK);
return 0;
}
int handle_input(ACE_HANDLE)
{
if(this->peer().recv(sizeBuffer,sizeof(sizeBuffer)) < 0)
ACE_DEBUG ((LM_ERROR,ACE_TEXT("%p\n")));
else
ACE_DEBUG ((LM_ERROR,ACE_TEXT("Receive:%s\n"),sizeBuffer));
return 0;
}
};
int main(int argc,char* argv[])
{
MyConnector conn;
MyHandler *eh = new MyHandler;
ACE_DEV_Addr comaddr("COM1");
if(conn.connect(eh,comaddr) < 0)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Connect Error!")),
1);
ACE_Reactor::instance()->run_reactor_event_loop();
return 0;
}
|