#pragma once

class CAdlinkCommon
{
public:
    CAdlinkCommon(int nPhysicalCardID, int nPortNo, int nPointNo);
    ~CAdlinkCommon(void);

    int InitInputCard(unsigned short usCardModel, int nHardwareIniTypeCardNo, int *pPhysicalCardID);

    int InitOutputCard(unsigned short usCardModel, int nHardwareIniTypeCardNo, int *pPhysicalCardID);

    int ClearOutputPort(int nPhysicalCardID, int nPortNo) const;

    int SetPortType(int nPhysicalCardID, int PortNo, int nType);

    int CloseInputCard(int nPhysicalCardID);

    int CloseOutputCard(int nPhysicalCardID);

    bool ReadVoltage(int nRange, double *pVoltage);

    bool ReadInput(unsigned short *pState);

    bool WriteOutputBit(bool bState);

    bool WriteVoltage(double dVoltage);

    bool ConfigOutputVoltageRange(double dRange);                                               // for 9112

    bool ClearEncoder();                                                                        // for 9222

    bool UseEncoder(bool bUse);                                                                 // for 9222

    unsigned long ReadEncoder();                                                                // for 9222

    bool SetupEncoder(unsigned short usMode, unsigned long ulReg1Val, unsigned long ulReg2Val); // for 9222

private:
    unsigned short m_usPhysicalCardID;                                                          // only used for CInput and COutput class
    unsigned short m_usPortNo;                                                                  // only used for CInput and COutput class
    unsigned short m_usPointNo;                                                                 // only used for CInput and COutput class

    bool InitCard(unsigned short usCardModel, int nHardwareIniTypeCardNo, int *pPhysicalCardID) const;

    bool CloseCard(int nPhysicalCardID);
};
