// EMS.h: interface for the CEMS class.
//
//////////////////////////////////////////////////////////////////////
#pragma once

#include "RunTask.h"
#include "Input.h"
#include "Output.h"
#include "commondef.h"

class CEMS : public CRunTask
{
public:
    bool CanMachineRun();
    bool IsEMSEnable() const;
    void UpdateMachineStart();
    void UpdateMachineStop();
    void UpdateUnitCount();
    void InitParameters();
    UINT RunThread();
    void SetEMSOutput(int nNo, COutput* copOutput);
    void SetEMSInput(int nNo, CInput* cipInput);
    CEMS();
    virtual ~CEMS();
    void SetGuiWindow(HWND hwnd);

private:
    void CheckHostAllowMachineToRun();
    void CheckMachineStatus();
    void CheckUnitCountUpdate();
    void GetMainApp();

    CEvt m_evtSendUnitPulse;
    CEvt m_evtMachineStop;
    CEvt m_evtMachineStart;

    HWND m_hwndMainApp;

    CInput* m_cipEMSStatus;
    COutput* m_copEMSCount;

    bool m_bEMSEnable;
    bool m_bMsgSendOn;
    bool m_bMsgSendOff;

    int m_iEmsPulse;
};
