// RSLaser.h: interface for the CRSLaser class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_RSLASER_H__BC34682C_121B_4DB5_8AAE_86951A0409CE__INCLUDED_)
#define AFX_RSLASER_H__BC34682C_121B_4DB5_8AAE_86951A0409CE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "VisionNW.h"
#include "Utility.h"

#ifdef  BUILD_COMMDLL
#define     COMMDLL_DLLCLASS    __declspec(dllexport)
#else
#define     COMMDLL_DLLCLASS    __declspec(dllimport)
#endif

enum LOT_TYPE
{
    LOT,
    LOT2,
    LOT3
};

enum
{
    LASER_MARK_TIMEOUT,
    LASER_MARK_COMPLETE,
    LASER_MARK_IN_PROGRESS,
    LASER_MARK_ALARM,
};

class COMMDLL_DLLCLASS CRSLaser : public CVisionNW
{
public:
    HANDLE       GetMarkingInProgressHandle();
    HANDLE       GetAlarmHandle();
    int          WaitMarkInProgress(DWORD dwTimeout);
    int          IsAlarm(DWORD dwTimeout);
    int          WaitMarkComplete(DWORD dwTimeout);
    CString      GetReceiveData();
    bool         Send(CString csMsg);
    bool         MeasurePower(DWORD dwTimeout);
    virtual void ReceiveComm(const char *cpcBuffer, int nSize);
    bool         SetSetting(CString csSetting, int nRequired, DWORD dwTimeout);
    bool         SetDeviceID(int nOriginLocation, CString csDeviceIDData, DWORD dwTimeout);
    bool         SetBin(int nOriginLocation, CString csBinData, DWORD dwTimeout);
    bool         SetMatrixPosition(double dX, double dY, double dAngle, DWORD dwTimeout);
    bool         SetPositionAndOccupation(CString csMsg, DWORD dwTimeout);
    bool         SetPart(int nPartNo, DWORD dwTimeout);
    bool         SetOccupation(CString csMsg, DWORD dwTimeout);
    double       GetPowerValue(DWORD dwTimeout);
    int          IsPowerAutoMode(DWORD dwTimeout);
    int          IsPowerOK(DWORD dwTimeout);
    CString      GetLayoutFile(DWORD dwTimeout);
    CString      GetLotID(DWORD dwTimeout);
    bool         GetAlarm(int &nAlarmNo, CString &csAlarmMsg, DWORD dwTimeout);
    int          IsMarkingEnd(DWORD dwTimeout);
    int          IsJobEnd(DWORD dwTimeout);
    int          IsSystemReady(DWORD dwTimeout);
    bool         StopMark();
    bool         StartMark();
    bool         CancelJob();
    bool         LoadJob();
    bool         SetVariable(CString csVariableName,  CString csData, DWORD dwTimeout);
    bool         SetLotFile(CString csLotFilename, DWORD dwTimeout);
    bool         SetLayout(CString csLotNo, long lLotQty, CString csLayoutFilename, CString csVariableData, int nLotType, DWORD dwTimeout);
    bool         Connect(int nPortNo, CString csIPAddress, bool bServer = TRUE);
    void         Disconnect();
    bool         IsClientConnected();
    bool         IsServerActive();
    bool         IsConnectedToServer();
    CRSLaser();
    virtual ~CRSLaser();

    HANDLE GetMarkingEndHandle();

protected:
    bool GetPowerStatus(DWORD dwTimeout);
    bool GetNextData(char *Token);
    bool SendMsg(CString csMsg, DWORD dwTimeout);
    bool DecodeStatus(char *Token);
    bool GetStatus(CString csStatusName, DWORD dwTimeout);

    HANDLE m_hAck;
    HANDLE m_hNack;
    HANDLE m_hStatusReady;
    HANDLE m_hSystemReady;
    HANDLE m_hJobEnd;
    HANDLE m_hMarkingEnd;
    HANDLE m_hMarkingInProgress;
    HANDLE m_hPowerStatusReady;
    HANDLE m_hAlarm;

    bool    m_bAlarm;
    CString m_csAlarmMsg;
    int     m_nAlarmNo;

    CString m_csLotID;
    CString m_csLayoutFilename;
    double  m_dPower;
    bool    m_bPowerOK;
    bool    m_nPowerAutoMode;

    char m_cReceiveData[4096];
    bool m_bWaitForTerminator2;

private:
    int GetMsgCase(CString csMsg);
};

#endif // !defined(AFX_RSLASER_H__BC34682C_121B_4DB5_8AAE_86951A0409CE__INCLUDED_)
