You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include "skt.h"
#include "sysapi.h"
#include <list>
using std::list;
class CVision
{
public:
CVision();
virtual ~CVision(void);
int Init(const char* pszip, ushort port);
int Deinit();
int getSocket() { return _socket; }
bool IsConn() { return SOCKET_CONNECTED == _status; }
void Connect(); //手动连接 -- 由线程执行
void RecvMsg(char* s = NULL, int nsize = 0); //接收消息 -- 由线程执行
int Process(); //拍照处理,等待拍照结果返回 0标识成功 内部阻塞
int Send(const char* s);
int WaitResult(char* s, int timeout); //接收处理结果 一旦接收成功_szres将清空
protected:
void setReply() { sys_SetEvent(_hReply); }
void resetReply() { sys_ResetEvent(_hReply); }
void waitReply() { sys_WaitForSingleObject(_hReply); }
void ClearMsg();
void RecvMsgB(char* s, int nsize); //接收消息
void Disconnect(); //断开处理
int SendMsg(const char *pszFormat, ...); //发送消息
int FindEnd(char* pszmsg); //查找结束符,并清零
int ParseMsg(char* pszmsg); //解析并处理消息
private:
Handle _hReply; //接收返回完成
Handle _hSection; //临界区
int _status; //连接状态
int _socket; //socket句柄
int _skt; //skt句柄
int _port; //客户端端口
int _len; //当前消息长度
int _size; //缓冲区大小
char* _msg; //单条消息缓冲区
int _index; //首次接收
int _ires; //拍照结果返回
list<char*> _lstmsg; //结果返回
};