105 lines
2.5 KiB
C
105 lines
2.5 KiB
C
|
#pragma once
|
|||
|
#include <windows.h>
|
|||
|
#include <atlbase.h>
|
|||
|
#include "../Communication/Snap7/s7_client.h"
|
|||
|
#include <condition_variable>
|
|||
|
#include <shared_mutex>
|
|||
|
#include <queue>
|
|||
|
#include "../Communication/S7Command.h"
|
|||
|
#include "../Communication/BaseClient.h"
|
|||
|
#include "../config/bean/CommunicationCfg.h"
|
|||
|
#include "../config/bean/IOCfg.h"
|
|||
|
//#include "SysParam.h"
|
|||
|
//#include "SignalState.h"
|
|||
|
//#include "AxisState.h"
|
|||
|
//#include "Axis.h"
|
|||
|
//#include "EnvState.h"
|
|||
|
#include "Command/PLCReceiver.h"
|
|||
|
#include "command/PLCInvoker.h"
|
|||
|
#include "../config/bean/CoverCfg.h"
|
|||
|
|
|||
|
|
|||
|
using namespace std;
|
|||
|
class CoreCommunication :public IConnect,public PLCReveiver
|
|||
|
{
|
|||
|
public:
|
|||
|
CoreCommunication();
|
|||
|
~CoreCommunication();
|
|||
|
void Init();
|
|||
|
void InitCommand();
|
|||
|
//void AddCmd(Command* cmd);
|
|||
|
void Startup();
|
|||
|
void Shutdown();
|
|||
|
|
|||
|
|
|||
|
virtual void CtrlStart() { Startup(); };
|
|||
|
virtual void CtrlStop() { Shutdown(); };
|
|||
|
|
|||
|
//void SetIOCfgWrapper(IOCfgWrapper* io) { m_IOCfgWrapper = io; }
|
|||
|
//void SetSysParamWrapper(SysParamWrapper* param) { m_SysParamWrapper = param; }
|
|||
|
//void SetPLCAxis(PLCAxis* axis) { m_Axis = axis; }
|
|||
|
//void SetAlarmStateWrapper(SignalStateWrapper* param) { m_AlarmStateWrapper = param; };
|
|||
|
//void GetAlarmState(SignalState& alarmState);
|
|||
|
//void GetEnvState(EnvState& envState);
|
|||
|
//void SetAxisRecordWrapper(AxisRecordWrapper* record) { m_AxisrecordWrapper = record; }
|
|||
|
|
|||
|
virtual bool IsServerConnected() {
|
|||
|
return m_S7Client->Connected;
|
|||
|
};
|
|||
|
|
|||
|
bool IsConnect() {
|
|||
|
return m_BaseStat.isConnected && m_S7Client->Connected;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private:
|
|||
|
static DWORD WINAPI ReadProc(CoreCommunication* _this);
|
|||
|
void ReadRun();
|
|||
|
|
|||
|
static DWORD WINAPI WriteProc(CoreCommunication* _this);
|
|||
|
void WriteRun();
|
|||
|
|
|||
|
static DWORD WINAPI AssistProc(CoreCommunication* _this);
|
|||
|
void AssistRun();
|
|||
|
|
|||
|
//static void ProcReadPLC(void *pobject, Command* pcommand);
|
|||
|
//static void ProcReadPLCData(void *pobject, Command* pcommand);
|
|||
|
|
|||
|
Command* GetSendCycleCommand();
|
|||
|
void UpdateCycleCommands();
|
|||
|
|
|||
|
public:
|
|||
|
BaseStat m_BaseStat;
|
|||
|
bool m_IsSmart;
|
|||
|
std::shared_mutex m_ValueMtx;
|
|||
|
private:
|
|||
|
HANDLE m_ReadThread;
|
|||
|
HANDLE m_WriteThread;
|
|||
|
HANDLE m_AssistThread;
|
|||
|
|
|||
|
|
|||
|
vector<Command*> m_CycleCommands;
|
|||
|
|
|||
|
|
|||
|
std::mutex m_ReadWriteMutex;
|
|||
|
|
|||
|
bool m_RunFlag;
|
|||
|
bool m_AssistRunFlag;
|
|||
|
|
|||
|
TSnap7Client *m_S7Client;
|
|||
|
CommunicationCfg* m_Config;
|
|||
|
|
|||
|
//IOCfgWrapper* m_IOCfgWrapper;
|
|||
|
//SysParamWrapper* m_SysParamWrapper;
|
|||
|
//SignalStateWrapper* m_AlarmStateWrapper;
|
|||
|
|
|||
|
CoverCfg* m_CoverCfg;
|
|||
|
//PLCAxis* m_Axis;
|
|||
|
//AxisRecordWrapper* m_AxisrecordWrapper;
|
|||
|
|
|||
|
PLCInvoker* m_Invoker;
|
|||
|
static const unsigned int READ_INFO_ITEM_COUNT = 6;
|
|||
|
static const unsigned int READ_DATA_ITEM_COUNT = 1;
|
|||
|
};
|
|||
|
|