thread.h
#ifndef _CORRECTPOSITION_H__ #define _CORRECTPOSITION_H__ #include <process.h> #include <iostream> typedef void *HANDLE; class CorrectPosition { public: CorrectPosition(); ~CorrectPosition(); void start(); void Resume(); void Suspend(); void run(); HANDLE getThread(); private: HANDLE hThread; volatile bool m_bRun; static void agent(void *p); }; #endifthread.cpp
#include "CorrectPosition.h" #include "autoCalibrate.h" CorrectPosition::CorrectPosition():m_bRun(false) { } CorrectPosition::~CorrectPosition() { } void CorrectPosition::start() { if(m_bRun) return; hThread = (HANDLE)_beginthread(agent, 0, (void*)this); m_bRun = (NULL != hThread); return; } void CorrectPosition::run() { std::cout << "Enter the CorrectPosition Thtead" << std::endl; if (ROBOT_ID & 0x01) { if (CalibrateKernel(1)) { //printf("矫正1车成功\n"); } else printf("图像矫正1车失败\n"); //mySerialPort_ID_1.syncOnce(); } if (ROBOT_ID & 0x02) { if (CalibrateKernel(2)) { // } else printf("图像矫正2车失败\n"); //mySerialPort_ID_2.syncOnce(); } } void CorrectPosition::Resume() { if(NULL == hThread || !m_bRun) return; ::ResumeThread(hThread); } void CorrectPosition::Suspend() { if(NULL == hThread || !m_bRun) return; ::SuspendThread(hThread); } void CorrectPosition::agent(void *p) { CorrectPosition *agent = (CorrectPosition *)p; agent->run(); } HANDLE CorrectPosition::getThread() { return hThread; }