MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030")); this->resize(800,400); createActions(); createMenus(); creatviewandscene(); creatbuttons(); creatsplitter(); //串口设置 // commthread = new commThread; // commthread->start(); //启动线程 // commthread->stopped=1; //初始化变量 // commthread->write_rs=0; // commthread->read_rs=0; // QTimer *time = new QTimer(this); //新建定时类 // time->start(50); //50ms定时 hcomm=new Posix_QextSerialPort("/dev/ttyS0",QextSerialBase::Polling); hcomm->open(QIODevice::ReadWrite); hcomm->setBaudRate(BAUD9600); hcomm->setDataBits(DATA_8); hcomm->setParity(PAR_NONE);//校验位无 hcomm->setStopBits(STOP_1);//1位停止位 hcomm->setFlowControl(FLOW_OFF);//无数据流控制 hcomm->setTimeout(10);//延时 time = new QTimer(this); //新建定时类 time->start(50); //50ms定时 creatconnect(); }
void ReceiveThread::run() { std::cout<<"in ReceiveThread:: run ++++++++++++++"<<std::endl; if(receiveSocket==NULL) { receiveSocket = new QTcpSocket; creatconnect(); } if(tryNewConnect()) emit connected(); else { std::cout<<"in ReceiveThread::run, send ConnectError "<<std::endl; emit ConnectError(); return ; } exec(); //receiveSocket->waitForDisconnected(); //emit receiveData(); }
void ReceiveThread::StartRun(ConnectInfo &robotinfo) { std::cout<<"ReceiveThread::StartRun-------- "<<std::endl; receiveRobot->Copy(robotinfo); if(receiveSocket==NULL) { std::cout<<"in ReceiveThread::StartRun,new QTcpSocket "<<std::endl; receiveSocket = new QTcpSocket; creatconnect(); } if(tryNewConnect()) emit connected(); else { std::cout<<"in ReceiveThread::StartRun, ConnectError "<<std::endl; emit ConnectError(); return ; } //exec(); }