#pragma once #ifndef _INCLUDE_COREWORK_TEST_H #define _INCLUDE_COREWORK_TEST_H #include "skt.h" #include "ipvar.h" #include "sysapi.h" #include "corework.h" #include "user.h" #include #define TESTCT 100000 //初始测试CT using std::string; class CProduct; class CTest { public: TestMachine _data; //治具数据 CTest(); ~CTest(void); cstr getAte() { return _data.ate; } int getIndex() { return _index; } int getSocket() { return _socket; } int getStatus() { return _data.status; } CProduct* getProduct() { return _p; } CProduct* popProduct() { CProduct* p = _p; _p = NULL; return p; } void loadCounter(); void saveCounter(); void resetCounter(); void Open(const char* pszip = 0); //服务端IP void Close(); //关闭 void Connect(); //手动连接 -- 由线程执行 void Process(); //其它处理 -- 由线程执行 void RecvMsg(); //接收消息 -- 由线程执行 ulong startCT() { return _startct; } ulong lastCT() { return _data.lastct; } bool IsReady() { return TestIdle == _data.status; } bool IsRunning(){ return TestRunning == _data.status; } bool Enabled() { return 1 == _data.benable; } bool IsOpen() { return _skt != INVALID_SKT; } bool IsConn() { return SOCKET_CONNECTED == _status; } bool IsRegOk() { return 0 == _regtm; } bool IsNormal() { return SOCKET_CONNECTED == _status && 0 == _regtm; } //是否可以正常使用 //设置下一次放入产品不开始测试 -- 用于缓存 void setNextNoTest() { _notest = true; } bool IsNextNoTest() { return _notest; } void PutProduct(CProduct* p); //放入产品 int SetVarStatus(const char* szvar); //外部调用,不可用遍历线程调以下接口 int StartTest(CProduct* p, const char* machine, const char* pszcfg, const char* pszcfg2, const char* site, const char* project, int bmes, int bmtcp, int bdualmode, const char* sublotname, int bupnoise); int Home(); int Reset(); int Pause(int bpause = 1); int EnableGrip(int benable = 1); int SendGR(const char* s); //获取测试项 返回字符串长度 int getRusult() { return _result; } int GetResultCsvInfo(char* pbuffer = 0, int nsize = 0); int GetResultFailInfo(char* pbuffer = 0, int nsize = 0); int GetResultTestInfo(char* pbuffer = 0, int nsize = 0); void operator =(CTest &r); protected: void setReply() { sys_SetEvent(_hReply); } void resetReply() { sys_ResetEvent(_hReply); } bool waitReply() { return 0 == sys_WaitForSingleObject(_hReply, 10000); } bool IsReplyed() { return 0 == sys_WaitForSingleObject(_hReply, 0); } void unlock() { sys_SetEvent(_hSend); } bool lock() { return 0 == sys_WaitForSingleObject(_hSend, 10000); } bool trylock() { return 0 == sys_WaitForSingleObject(_hSend, 0); } void ClearFlag(); //清空标识 void ChkRegist(); //检测注册超时 void QueryStatus(); //查询治具状态 void ChkReplyTimeout(); //检测回复超时 void UpdateStatus(TestStatus status); //更新治具状态 int SendMsg(const char *pszFormat, ...); //发送消息 int FindEnd(char* pszmsg); //查找结束符,并清零 void ParseMsg(char* pszmsg); //解析并处理消息 void ParseRegister(char* pszcmd); //解析注册消息 void ParseStatusReply(char* pszcmd); //治具状态回复 void ParseStartReply(char* pszcmd); //启动测试回复 void ParseResultReply(char* pszcmd); //询问结果回复 void ParseResult(char* pszcmd); //解析结果 void ParseErrorReply(char* pszcmd); //错误代码回复 void ParseIntReply(char* pszcmd); //结果回复 void ParseWriteLog(char* pszcmd); //解析测试日志 void ParseGR(char* pszmsg); //解析视觉指令 void ParseRIO(char* pszmsg); //远程读取IO void ParseWIO(char* pszmsg); //远程写入IO void CalcRowColumn(int takeindex, char* rowcol); //有索引值计算行列 private: CProduct* _p; //产品数据 int _index; //治具索引 int _cmdres; //指令返回结果 uint _startct; //开始测试时间 uint _qstatus; //查询状态时间 uint _regtm; //连接上2s内必须注册,否则断开 uint _qstart; //发送指令计时 Handle _hReply; //接收返回完成 Handle _hSend; //发送事件 Handle _hSection; //临界区 ipvar* _pvar; //保存状态 bool _notest; //本次不测试,仅用于缓存 bool _btesting; //是否测试中 int _status; //连接状态 int _socket; //socket句柄 int _skt; //skt句柄 int _len; //当前消息长度 int _size; //缓冲区大小 char* _msg; //单条消息缓冲区 char _client[MAX_NAME_LEN]; //客户端ip:port //记录信息 int _result; //1ok 0ng string _csvInfo; string _failItems; string _testItems; string _csvTitle; char _daypath[MAX_NAME_LEN]; //按天生成的文件夹 \\20210916 const char* _pCurCmd; //当前发送指令 -- 等待返回 }; #endif //防止重复包含