#ifndef __PACSDK_H
#define __PACSDK_H



#ifdef __cplusplus
extern "C" {
#endif



#ifdef  PACSDK_EXPORTS
#define  PAC_API extern "C" __declspec(dllexport)
#else
#define  PAC_API extern "C" __declspec(dllimport)
#endif





#define  PAC_PRIVATE_API          PAC_API
#define  PAC_SERAL_NUMBER_LENGTH  8



    //=========================================================================
    //  01. System Information API
    //=========================================================================
#define  PAC_PARALLEL     0x80
#define  PAC_PARALLEL_RW  0x81
#define  PAC_SCAN         0x40
#define  PAC_DI32         0xE3
#define  PAC_32BIT        0x20
#define  PAC_DO32         0xE0
#define  PAC_DI16DO16     0xE2
#define  PAC_DI16         0xC3
#define  PAC_DO16         0xC0
#define  PAC_DI8DO8       0xC2
#define  PAC_8K           8000
#define  PAC_9K           9000


    PAC_API bool pac_BackwardCompatible();                      //W
    PAC_API void pac_ChangeSlot(BYTE slotNo);                   //W  X
    PAC_API bool pac_CheckSDKVersion(DWORD version);            //W  X
    PAC_API void pac_EnableLED(bool bFlag);                     //W
    PAC_API void pac_EnableLEDs(int pin, bool bFlag);           //   X(A)
    PAC_API int  pac_GetComMapping(int ndx);                    //W         name diff doc
    PAC_API void pac_GetCPUVersion(LPSTR cpu_version);          //W  X
    PAC_API void pac_GetEbootVersion(LPSTR eboot_version);      //W
    PAC_API void pac_GetMacAddress(BYTE LAN, LPSTR MacAddr);    //W  X
    PAC_API bool pac_ModuleExists(HANDLE hPort, int slot);      //W  X
    PAC_API int  pac_GetModuleName(BYTE slot, LPSTR strName);   //W  X
    PAC_API int  pac_GetModuleType(BYTE slot);                  //W  X
    PAC_API int  pac_GetModuleVersion(BYTE slot, LPSTR strName);//W  X   
    PAC_API void pac_GetOSVersion(LPSTR os_version);            //W  X
    PAC_API int  pac_GetRotaryID();                             //W  X
    PAC_API void pac_GetSDKVersion(LPSTR sdk_version);          //W  X
    PAC_API void pac_GetSerialNumber(LPSTR SerialNumber);       //W  X
    PAC_API void pac_Reboot();                                  //W  X
    PAC_API int  pac_EthernetLinkState(BYTE LAN, bool *status);  //


    //=========================================================================
    // 02. Backplane API
    //=========================================================================
    PAC_API void pac_EnableRetrigger(BYTE iValues);           //W  X   
    PAC_API void pac_GetBackplaneID(LPSTR backplane_version); //W  X
    PAC_API int  pac_GetBatteryLevel(int nBattery);           //W  X
    PAC_API int  pac_GetDIPSwitch();                          //W  X
    PAC_API int  pac_GetSlotCount();                          //W  X
    PAC_API void pac_RegistryHotPlug(DWORD hWnd, DWORD msgID);//W
    PAC_API void pac_UnregistryHotPlug(DWORD hWnd);           //W

    //undocumented API
    PAC_API void pac_ClearHotPlug();                               //W 
    PAC_API void pac_ClearRisingEdgeIRQ(BYTE slots);               //W 
    PAC_API void pac_EnableHotPlug(bool bEnable);                  //W 
    PAC_API void pac_EnableRisingEdgeIRQ(BYTE slots, bool bEnable);//W
    PAC_API void pac_EOI();                                        //W  X 
    PAC_API bool pac_GetHotPlugIRQState();                         //W 
    PAC_API bool pac_GetHotPlugStatus();                           //W 
    PAC_API BYTE pac_GetRisingEdgeEnableStatus();                  //W 
    PAC_API BYTE pac_GetRisingEdgeIRQStatus();                     //W 
    PAC_API void pac_ResetBackplane();                             //W  X 
    PAC_API void pac_ResetSystemToDefault();                       //W  X 



    //=========================================================================
    // 03. Interrupt API
    //=========================================================================
#define  PAC_INTR_DONE  0
#define  PAC_INTR_DONE1 1
#define  PAC_INTR_FAIL  2
#define  PAC_INTR_EXIT  3

#define  INTR_RISING_TRIG   0
#define  INTR_LEVEL_TRIG    1
#define  INTR_Falling_TRIG  2

    typedef int (CALLBACK * PAC_CALLBACK_FUNC)();

    PAC_API void   pac_EnableSlotInterrupt(BYTE slot, bool bEnable);         //W  X
    PAC_API HANDLE pac_GetSlotInterruptEvent(BYTE slot);                     //W  X
    PAC_API DWORD  pac_GetSlotInterruptID(BYTE Slot);                        //W
    PAC_API void   pac_InterruptDone(BYTE slot);                             //W  X
    PAC_API bool   pac_InterruptInitialize(BYTE slot);                       //W  X
    PAC_API bool   pac_RegisterSlotInterrupt(BYTE slot, PAC_CALLBACK_FUNC f);//W  X
    PAC_API void   pac_SetSlotInterruptEvent(BYTE slot, HANDLE hEvent);      //W  X
    PAC_API bool   pac_SetSlotInterruptPriority(BYTE slot, int nPriority);   //W  X
    PAC_API void   pac_SetTriggerType(BYTE slot, int iType) ;                //W  X
    PAC_API bool   pac_UnregisterSlotInterrupt(BYTE slot);                   //W  X



    //=========================================================================
    // 04. Memory Access API
    //=========================================================================
#define  PAC_MEM_SRAM    0
#define  PAC_MEM_EEPROM  1
#define  PAC_MEM_NVRAM   2

    PAC_API DWORD pac_GetMemorySize(int mem_type);                               //W  X
    PAC_API bool  pac_ReadMemory(DWORD address, LPBYTE lpBuffer, DWORD dwLength, 
        int mem_type);                                                           //W  X
    PAC_API bool  pac_WriteMemory(DWORD address, LPBYTE lpBuffer, DWORD dwLength, 
        int mem_type);                                                           //W  X
    PAC_API void  pac_EnableEEPROM(bool bEnable);                                //W  X
    PAC_API void  pac_EnableMemory(bool bEnable,int mem_type);                                //W  X



    //=========================================================================
    // 05. Watchdog API
    //=========================================================================
#define  PAC_WDT_HW  0
#define  PAC_WDT_OS  1

    PAC_API void  pac_DisableWatchDog(int wdt);             //W  X
    PAC_API bool  pac_EnableWatchDog(int wdt, DWORD value); //W  X
    PAC_API bool  pac_GetWatchDogState(int wdt);            //W  X
    PAC_API DWORD pac_GetWatchDogTime(int wdt);             //W  X
    PAC_API void  pac_RefreshWatchDog(int wdt);             //W  X
    PAC_API bool  pac_SetWatchDogTime(int wdt, DWORD value);//W  X



    //=========================================================================
    // 06. microSD Management API (WinPAC only)
    //=========================================================================
    PAC_API bool pac_SDExists();                     //W
    PAC_API bool pac_SDMount(LPTSTR szPartitionName);//W
    PAC_API bool pac_SDOnside();                     //W
    PAC_API bool pac_SDUnmount();                    //W



    //=========================================================================
    // 07. Registry API
    //=========================================================================
#define  PKT_NONE    0
#define  PKT_KEY     1
#define  PKT_STRING  2
#define  PKT_DWORD   3

    PAC_API DWORD pac_RegCountKey(LPCTSTR KeyName);                                     //W  X
    PAC_API DWORD pac_RegCountValue(LPCTSTR KeyName);                                   //W  X
    PAC_API bool  pac_RegCreateKey(LPCTSTR KeyName);                                    //W  X
    PAC_API bool  pac_RegDeleteKey(LPCTSTR KeyName);                                    //W  X
    PAC_API bool  pac_RegDeleteValue(LPCTSTR KeyName);                                  //W  X
    PAC_API DWORD pac_RegGetDWORD(LPCTSTR KeyName);                                     //W  X
    PAC_API bool  pac_RegGetKeyByIndex(LPCTSTR KeyName, DWORD dwIndex, LPTSTR lpName);  //W  X
    PAC_API DWORD pac_RegGetKeyInfo(LPCTSTR KeyName);                                   //W  X
    PAC_API bool  pac_RegGetString(LPCTSTR KeyName, LPTSTR lpData, DWORD dwLength);     //W  X
    PAC_API bool  pac_RegGetValueByIndex(LPCTSTR KeyName, DWORD dwIndex, LPTSTR lpName);//W  X
    PAC_API bool  pac_RegKeyExist(LPCTSTR KeyName);                                     //W  X
    PAC_API bool  pac_RegSave(LPCTSTR KeyName);                                         //W  X
    PAC_API bool  pac_RegSetString(LPCTSTR KeyName, LPCTSTR assignStr, DWORD dwLength); //W  X
    PAC_API bool  pac_RegSetDWORD(LPCTSTR KeyName, DWORD assignVal);                    //W  X



    //=========================================================================
    // 08. UART API
    //=========================================================================
#define  CTO_TIMEOUT_ALL          0
#define  CTO_READ_RETRY_TIMEOUT   1
#define  CTO_READ_TOTAL_TIMEOUT   2
#define  CTO_WRITE_TOTAL_TIMEOUT  3

#define  CTS  0
#define  DSR  1
#define  RI   2
#define  CD   3

#define  IN_DATA   0
#define  OUT_DATA  1

    PAC_API HANDLE uart_Open(LPCSTR ConnectionString);                        //W  X  
    PAC_API HANDLE uart_OpenEx(LPCSTR ConnectionString);                      //W  X  undoc
    PAC_API bool   uart_Close(HANDLE hPort);                                  //W  X

    PAC_API bool   uart_Write(HANDLE hPort, LPCSTR buf);                      //W  X  undoc
    PAC_API bool   uart_Read(HANDLE hPort, LPSTR buf);                        //W  X  undoc 

    PAC_API bool   uart_WriteExt(HANDLE hPort, LPCSTR buf, DWORD out_Len);
    PAC_API bool   uart_ReadExt(HANDLE hPort, LPSTR buf, DWORD in_Len);   

    PAC_API bool   uart_Send(HANDLE hPort, LPCSTR buf);                       //W  X
    PAC_API bool   uart_Recv(HANDLE hPort, LPSTR buf);                        //W  X
    PAC_API bool   uart_SendCmd(HANDLE hPort, LPCSTR cmd, LPSTR szResult);    //W  X

    PAC_API bool   uart_SendExt(HANDLE hPort, LPCSTR buf, DWORD out_Len);
    PAC_API bool   uart_RecvExt(HANDLE hPort, LPSTR buf, DWORD in_Len);
    PAC_API bool   uart_SendCmdExt(HANDLE hPort, LPCSTR cmd, DWORD out_Len, 
        LPSTR szResult, DWORD in_Len);                                      

    PAC_API void   uart_SetTimeOut(HANDLE hPort, DWORD msec, int ctoType);    //W  X
    PAC_API void   uart_EnableCheckSum(HANDLE hPort, bool bEnable);           //W  X
    PAC_API void   uart_SetTerminator(HANDLE hPort, LPCSTR szTerm);           //W  X

    PAC_API bool   uart_BinSend(HANDLE hPort, LPCSTR buf, DWORD in_Len);      //W  X
    PAC_API bool   uart_BinRecv(HANDLE hPort, LPSTR buf, DWORD in_Len);       //W  X
    PAC_API bool   uart_BinSendCmd(HANDLE hPort, LPCSTR ByteCmd, DWORD in_Len, 
        LPSTR ByteResult, DWORD out_Len);                                     //W  X

    PAC_API DWORD  uart_GetDataSize(HANDLE hPort, int data_type);             //W  X
    PAC_API bool   uart_GetLineStatus(HANDLE hPort, int pin);                 //W  X
    PAC_API DWORD  uart_SetLineStatus(HANDLE port, int pin, int mode);        //W  X  undoc 
    PAC_API DWORD  uart_GetOutputLineStatus(HANDLE hPort);                    //W  X  undoc



    //=========================================================================
    // 09. PAC_IO API
    //=========================================================================
#define  PAC_REMOTE_IO_BASE       (0x1000)
#define  PAC_REMOTE_IO(iAddress)  (PAC_REMOTE_IO_BASE|iAddress)

#define  PAC_REMOTE_iPAC_BASE           (0x100000)
#define  PAC_REMOTE_iPAC(iAddr, iSlot)  (PAC_REMOTE_iPAC_BASE|iAddr<<8|iSlot)

#define  PAC_DAISY_CHAIN_WIRING_MODULE_PORT_BASE       (0x1000000)
#define  PAC_DAISY_CHAIN_WIRING_MODULE_PORT(slot,port) ((slot& PAC_REMOTE_IO_BASE)?(PAC_DAISY_CHAIN_WIRING_MODULE_PORT_BASE|((slot&0xFFF) <<8)|port|(0x1<<6)):((slot& PAC_REMOTE_iPAC_BASE)?(PAC_DAISY_CHAIN_WIRING_MODULE_PORT_BASE|((slot&0xFFFFF) <<8)|port|(0x2<<6)):(PAC_DAISY_CHAIN_WIRING_MODULE_PORT_BASE|(slot<<8)|port)))   

#define  pac_GetBit(v, ndx)       (v & (1<<ndx))                                                    //W  X

    PAC_API bool  pac_WriteDO(HANDLE hPort, int slot, int iDO_TotalCh, DWORD lDO_Value);            //W  X
    PAC_API bool  pac_WriteDOBit(HANDLE hPort, int slot, int iDO_TotalCh, int iChannel, 
        int iBitValue);                                                                             //W  X
    PAC_API bool  pac_ReadDO(HANDLE hPort, int slot, int iDO_TotalCh, DWORD *lDO_Value);            //W  X
    PAC_API bool  pac_ReadDI(HANDLE hPort, int slot, int iDI_TotalCh, DWORD *lDI_Value);            //W  X
    PAC_API bool  pac_ReadDIO(HANDLE hPort, int slot, int iDI_TotalCh, int iDO_TotalCh, 
        DWORD* lDI_Value, DWORD* lDO_Value);                                                        //W  X
    PAC_API bool  pac_ReadDILatch(HANDLE hPort, int slot, int iDI_TotalCh, 
        int iLatchType, DWORD *lDI_Latch_Value);                                                    //W  X
    PAC_API bool  pac_ClearDILatch(HANDLE hPort, int slot);                                         //W  X
    PAC_API bool  pac_ReadDIOLatch(HANDLE hPort, int slot, int iDI_TotalCh,
        int iDO_TotalCh, int iLatchType, DWORD *lDI_Latch_Value, DWORD *lDO_Latch_Value);           //W  X
    PAC_API bool  pac_ClearDIOLatch(HANDLE hPort, int slot);                                        //W  X
    PAC_API bool  pac_ReadDICNT(HANDLE hPort, int slot, int iChannel, int iDI_TotalCh, 
        DWORD *lCounter_Value);                                                                     //W  X
    PAC_API bool  pac_ClearDICNT(HANDLE hPort, int slot, int iChannel, int iDI_TotalCh);
    PAC_API bool  pac_WriteAO(HANDLE hPort, int slot, int iChannel, int iAO_TotalCh, float fValue); //W  X
    PAC_API bool  pac_ReadAO(HANDLE hPort, int slot, int iChannel, int iAO_TotalCh, float *fValue); //W  X
    PAC_API bool  pac_ReadAI(HANDLE hPort, int slot, int iChannel, int iAI_TotalCh, float *fValue); //W  X
    PAC_API bool  pac_ReadAIHex(HANDLE hPort, int slot, int iChannel, int iAI_TotalCh, int *iValue);//W  X
    PAC_API bool  pac_ReadAIAll(HANDLE hPort, int slot, float fValue[]);                            //W  X
    PAC_API bool  pac_ReadAIAllHex(HANDLE hPort, int slot, int iValue[]);                           //W  X
    PAC_API bool  pac_ReadCNT(HANDLE hPort, int slot, int iChannel, DWORD *lCounter_Value);         //W  X
    PAC_API bool  pac_ClearCNT(HANDLE hPort, int slot, int iChannel);                               //W  X
    PAC_API bool  pac_ReadCNTOverflow(HANDLE hPort, int slot, int iChannel, int *iOverflow);        //W  X

    PAC_API bool  pac_ReadCNTAll(HANDLE hPort, int slot, int iTotalChannel, DWORD lCounter_Value[]);         
    PAC_API bool  pac_ClearCNTAll(HANDLE hPort, int slot, int iTotalChannel);
    PAC_API bool  pac_ReadFREQ(HANDLE hPort, int slot, int iChannel, float *fFreq_Value); 

    // (undoc)
    PAC_API short pac_GetModuleLastOutputSource(HANDLE hPort,int slot); 
    PAC_API bool  pac_GetModuleWDTStatus(HANDLE hPort,int slot); 
	PAC_API bool  pac_GetModuleWDTStatusEX(HANDLE hPort,int slot, short *outStatus); 
    PAC_API bool  pac_GetModuleWDTConfig(HANDLE hPort,int slot, short* enStatus, unsigned long *wdtTimeout,int *ifWDT_Overwrite);
    PAC_API bool  pac_SetModuleWDTConfig(HANDLE hPort,int slot, short enStatus, unsigned long wdtTimeout,int ifWDT_Overwrite);
    PAC_API bool  pac_ResetModuleWDT(HANDLE hPort,int slot); 
    PAC_API bool  pac_RefreshModuleWDT(HANDLE hPort,int slot); 

    PAC_API bool  pac_InitModuleWDTInterrupt(int slot,PAC_CALLBACK_FUNC f); //only for 8KRW module
    PAC_API bool pac_SetModuleWDTInterruptStatus(int slot,short enStatus);//only for 8KRW module
    PAC_API short pac_GetModuleWDTInterruptStatus(int slot);               //only for 8KRW module

    PAC_API bool  pac_ReadModuleSafeValueDO(HANDLE hPort,int slot, int iDO_TotalCh, unsigned long *lValue);
    PAC_API bool  pac_WriteModuleSafeValueDO(HANDLE hPort,int slot, int iDO_TotalCh, unsigned long lValue);

    PAC_API bool  pac_ReadModuleSafeValueAO(HANDLE hPort,int slot,int iChannel,int iAO_TotalCh, float *fValue);
    PAC_API bool  pac_WriteModuleSafeValueAO(HANDLE hPort,int slot,int iChannel,int iAO_TotalCh,float fValue); 

    PAC_API bool  pac_ReadModulePowerOnValueDO(HANDLE hPort,int slot, int iDO_TotalCh, unsigned long *lValue); //PowerON status is 0ff and ruturn the 0 of powerOn value even the powerON value isn't 0 saved on fram
    PAC_API bool  pac_WriteModulePowerOnValueDO(HANDLE hPort,int slot, int iDO_TotalCh, unsigned long lValue); //PowerOn value large 0 means the PowerOn value is enabled

    PAC_API bool  pac_ReadModulePowerOnValueAO(HANDLE hPort,int slot,int iChannel,int iAO_TotalCh,float *fValue);
    PAC_API bool  pac_WriteModulePowerOnValueAO(HANDLE hPort,int slot,int iChannel,int iAO_TotalCh,float fValue);

    PAC_API bool pac_WriteDO_MF(HANDLE hPort, int iAddrSlot, int iDO_TotalCh, DWORD lDO_Value);
    PAC_API bool pac_ReadDIO_MF(HANDLE hPort, int iAddrSlot, int iDI_TotalCh, int iDO_TotalCh, DWORD* lDI_Value, DWORD* lDO_Value);
    PAC_API bool pac_ReadDI_MF(HANDLE hPort, int iSlot, int iDI_TotalCh, DWORD *lDI_Value);
    PAC_API bool pac_ReadDO_MF(HANDLE hPort, int iSlot, int iDO_TotalCh, DWORD *lDO_Value);
    
    PAC_API bool pac_ReadDICNT_MF(HANDLE hPort, int iAddrSlot, int iChannel, int iDI_TotalCh, DWORD *lCounter_Value);
    PAC_API bool pac_ClearDICNT_MF(HANDLE hPort, int iAddrSlot, int iChannel, int iDI_TotalCh);

    PAC_API bool pac_ReadModulePowerOnValueDO_MF(HANDLE hPort, int slot, int iDO_TotalCh, unsigned long *lValue);
    PAC_API bool pac_WriteModulePowerOnValueDO_MF(HANDLE hPort, int slot, int iDO_TotalCh, unsigned long lValue);

    PAC_API bool pac_ReadModuleSafeValueDO_MF(HANDLE hPort, int slot, int iDO_TotalCh, unsigned long *lValue);
    PAC_API bool pac_WriteModuleSafeValueDO_MF(HANDLE hPort, int slot, int iDO_TotalCh, unsigned long lData);

    PAC_API bool pac_ReadAO_MF(HANDLE hPort, int slot, int iChannel, int iAO_TotalCh, float *fValue); //W  X
	PAC_API bool pac_WriteAO_MF(HANDLE hPort, int iAddrSlot, int iChannel, int iAO_TotalCh, float fValue);

    PAC_API bool pac_ReadModulePowerOnValueAO_MF(HANDLE hPort,int slot,int iChannel,int iAO_TotalCh,float *fValue);
	PAC_API bool pac_WriteModulePowerOnValueAO_MF(HANDLE hPort, int iAddrSlot, int iChannel, int iAO_TotalCh, float fValue);

    PAC_API bool pac_ReadModuleSafeValueAO_MF(HANDLE hPort,int slot,int iChannel,int iAO_TotalCh, float *fValue);
	PAC_API bool pac_WriteModuleSafeValueAO_MF(HANDLE hPort, int iAddrSlot, int iChannel, int iAO_TotalCh, float  fValue);

	PAC_API bool pac_ReadAIAllExt(HANDLE hPort, int slot, float fValue[], DWORD Buff_Len, DWORD *Channel);
	PAC_API bool pac_ReadAIAllHexExt(HANDLE hPort, int slot, int iValue[], DWORD Buff_Len, DWORD *Channel);


	PAC_API bool pac_SetModulePowerOnEnStatus(int slot, short enStatus); //only for 8KRW module
    PAC_API bool pac_GetModulePowerOnEnStatus(int slot, short* enStatus); //only for 8KRW module

	PAC_API bool pac_ReadAISensorSerialNumber(HANDLE hPort, int iAddrSlot,int port,int iindex, char *SNstring, DWORD Buff_Len);//for DAISY CHAIN WIRING MODULE , such as i-87004
    
	PAC_API bool pac_WriteDI_LPF(HANDLE hPort, int slot, DWORD lpf_Value);//only for 9K module
	PAC_API bool pac_ReadDI_LPF(HANDLE hPort, int slot, DWORD *lpf_Value, int type);//only for 9K module. type = 0 -> Hardware, 1 -> Software

	//=========================================================================
    // 10. Backplane timer API
    //=========================================================================
#define  TIMEROUT  0
#define  TIMER1    1
#define  TIMER2    2

    typedef int (CALLBACK * PAC_TIMEROUT_CALLBACK_FUNC)();

    PAC_API DWORD pac_GetBPTimerTimeTick_ms(void);                         //W  X
    PAC_API WORD  pac_GetBPTimerTimeTick_us(void);                         //W  X
    PAC_API void  pac_KillBPTimer(int type);                               //W  X
    PAC_API bool  pac_SetBPTimer(int type, unsigned int uElapse, 
        PAC_TIMEROUT_CALLBACK_FUNC f);                                     //W  X
    PAC_API bool  pac_SetBPTimerInterruptPriority(int type, int nPriority);//W  X  undoc 
    PAC_API bool  pac_SetBPTimerOut(unsigned int uHighElapse, 
        unsigned int uLOwElapse, PAC_TIMEROUT_CALLBACK_FUNC f);            //W  X



    //=========================================================================
    //  11. Error Handling API
    //=========================================================================
    PAC_API void  pac_ClearLastError(DWORD errno);                        //W  X  
    PAC_API DWORD pac_GetLastError();                                     //W  X
    PAC_API void  pac_SetLastError(DWORD errno);                          //W  X  
    PAC_API void  pac_GetErrorMessage(DWORD dwMessageID, LPTSTR lpBuffer);//W  X



	//=========================================================================
	// 12. MISC API
	//========================================================================= 
	PAC_API void pac_AnsiToWideString(LPCSTR astr, LPTSTR wstr);		//W  X      
	PAC_API void pac_DoEvent();  //same function(org wpac				//W  X
	PAC_API void pac_DoEvents(); //same function(org xpac				//W  X
	PAC_API void pac_WideStringToAnsi(const TCHAR *wstr, LPSTR astr);	//W  X   
	PAC_API void pac_WideToAnsiString(LPCTSTR wstr, LPSTR astr);		//W  X
	PAC_API bool pac_GetCurrentDirectory(char* cBuffer, DWORD nSize);	//W  X
	PAC_API bool pac_GetCurrentDirectoryW(LPTSTR lpBuffer, DWORD nSize);//W  X



    //=========================================================================
    // 13. Buzzer API (undoc)
    //=========================================================================
    PAC_API void pac_BuzzerBeep(WORD count, DWORD milliseconds);//W
    PAC_API void pac_GetBuzzerFreqDuty(int *freq, int *duty);   //W
    PAC_API void pac_SetBuzzerFreqDuty(int freq, int duty);     //W
    PAC_API void pac_StopBuzzer();                              //W






    //=========================================================================
    // 14. BackLight API (undoc)
    //=========================================================================
	#define PAC_MOSTDARK 20
	#define PAC_FULLON 100
	PAC_API void pac_SetBackLight(int level);
	PAC_API void pac_SetBackLight_Slope(int level);
	PAC_API DWORD pac_GetBackLight();



    //=========================================================================
    // Undocumented API
    //=========================================================================
#define  PAC_INP        _pac_inp        //W  X
#define  PAC_OUTP       _pac_outp       //W  X
#define  PAC_MAP        _pac_map        //W
#define  PAC_SLOT_INP   _pac_slot_inp   //W  X
#define  PAC_SLOT_OUTP  _pac_slot_outp  //W  X 

    PAC_PRIVATE_API BYTE  _pac_inp(int addr);                            //W  X
    PAC_PRIVATE_API void  _pac_outp(int addr, BYTE val);                 //W  X
    PAC_PRIVATE_API PBYTE _pac_map(int addr);                            //W
    PAC_PRIVATE_API BYTE  _pac_slot_inp(BYTE slot, int addr);            //W  X
    PAC_PRIVATE_API void  _pac_slot_outp(BYTE slot, int addr, BYTE val); //W  X
    PAC_PRIVATE_API PBYTE _pac_slot_map(BYTE slot, int addr);            //W
    PAC_PRIVATE_API DWORD _pac_get_slot_offset(BYTE slot);               //W  X
    PAC_PRIVATE_API PBYTE _pac_get_base_address();                       //W  X
    PAC_PRIVATE_API void  _pac_set_mac_address(BYTE LAN, LPTSTR MacAddr);//W

    /************************** 16-bit ********************************/
    PAC_PRIVATE_API WORD  _pac_inpw(int addr);                           //W  X           
    PAC_PRIVATE_API void  _pac_outpw(int addr, WORD val);                //W  X
    PAC_PRIVATE_API WORD  _pac_slot_inpw(BYTE slot, int addr);           //W
    PAC_PRIVATE_API void  _pac_slot_outpw(BYTE slot, int addr, WORD val);//W
    /******************************************************************/

    PAC_PRIVATE_API void  _pac_refresh_screen();                    //W
    PAC_PRIVATE_API void  _pac_us_delay(DWORD microsecond);         //W  X
    PAC_PRIVATE_API void  _pac_ticks_delay(DWORD ticks);            //W  X?
    PAC_PRIVATE_API bool  _pac_get_partition_info(LPTSTR szPartName, 
        LPTSTR szFileSys, LPTSTR szVolName);                        //W
    PAC_PRIVATE_API DWORD _pac_oscr0();                             //W
    PAC_PRIVATE_API float _pac_delay(WORD wUSec);                   //   X
    PAC_PRIVATE_API DWORD _pac_slot_addr(BYTE slot, int addr);      //W  X 
    PAC_PRIVATE_API WORD  _pac_get_CPUtype(void);                   //   X

	PAC_PRIVATE_API bool uart_ChangeMode(int mode);

    //=========================================================================
    // Error Codes
    //=========================================================================
#define  PAC_ERR_SUCCESS                     0x00000
#define  PAC_ERR_UNKNOWN                     0x00001

    //Basic=====================================================================
#define  PAC_ERR_BASE                        0x10000
#define  PAC_ERR_SLOT_REGISTERED             (PAC_ERR_BASE + 1)
#define  PAC_ERR_SLOT_NOT_REGISTERED         (PAC_ERR_BASE + 2)
#define  PAC_ERR_UNKNOWN_MODULE              (PAC_ERR_BASE + 3)
#define  PAC_ERR_INVALID_MAC                 (PAC_ERR_BASE + 4)
#define  PAC_ERR_INVALID_COMPORT_NUMBER      (PAC_ERR_BASE + 5)
#define  PAC_ERR_FUNCTION_NOT_SUPPORT        (PAC_ERR_BASE + 6)
#define  PAC_ERR_MODULE_UNEXISTS             (PAC_ERR_BASE + 7)
#define  PAC_ERR_INVALID_SLOT_NUMBER         (PAC_ERR_BASE + 8)
#define  PAC_ERR_FUNCTION_REPEAT_CALLED      (PAC_ERR_BASE + 9)
#define  PAC_ERR_INVALID_HANDLE_VALUE        (PAC_ERR_BASE + 10)
#define  PAC_ERR_DEVICE_IO_CONTROL           (PAC_ERR_BASE + 11)
#define  PAC_ERR_INVALID_PARAMETER           (PAC_ERR_BASE + 12)

    //Memory Access=============================================================
#define  PAC_ERR_MEMORY_BASE                 0x11000
#define  PAC_ERR_EEP_INVALID_ADDRESS         (PAC_ERR_MEMORY_BASE + 1)
#define  PAC_ERR_SRAM_INVALID_ADDRESS        (PAC_ERR_MEMORY_BASE + 2)
#define  PAC_ERR_MEMORY_INVALID_TYPE         (PAC_ERR_MEMORY_BASE + 3)
#define  PAC_ERR_NVRAM_INVALID_ADDRESS       (PAC_ERR_MEMORY_BASE + 4)
#define  PAC_ERR_EEP_WRITE_PROTECT           (PAC_ERR_MEMORY_BASE + 5)
#define  PAC_ERR_EEP_WRITE_FAIL              (PAC_ERR_MEMORY_BASE + 6)
#define  PAC_ERR_EEP_READ_FAIL               (PAC_ERR_MEMORY_BASE + 7)
#define  PAC_ERR_MEMORY_INVALID_SIZE         (PAC_ERR_MEMORY_BASE + 8)

    //Watch Dog=================================================================
#define  PAC_ERR_WDT_BASE                    0x12000
#define  PAC_ERR_WDT_INVALID_VALUE           (PAC_ERR_WDT_BASE + 1)
#define  PAC_ERR_WDT_UNEXIST                 (PAC_ERR_WDT_BASE + 2)
#define  PAC_ERR_WDT_BASE_NOT_SET            (PAC_ERR_WDT_BASE + 3)
#define  PAC_ERR_WDT_OS_FOR_OS_STARTUP  	 (PAC_ERR_WDT_BASE + 4)
    //Interrupt=================================================================
#define  PAC_ERR_INTR_BASE                   0x13000
#define  PAC_ERR_INTR_CREATE_EVENT_FAILURE    (PAC_ERR_INTR_BASE + 1)

    //UART======================================================================
#define  PAC_ERR_UART_BASE                   0x14000
#define  PAC_ERR_UART_CHECKSUM               (PAC_ERR_UART_BASE+1)
#define  PAC_ERR_UART_READ_TIMEOUT           (PAC_ERR_UART_BASE+2)
#define  PAC_ERR_UART_RESPONSE               (PAC_ERR_UART_BASE+3)
#define  PAC_ERR_UART_UNDER_INPUT_RANGE      (PAC_ERR_UART_BASE+4)
#define  PAC_ERR_UART_EXCEED_INPUT_RANGE     (PAC_ERR_UART_BASE+5)
#define  PAC_ERR_UART_OPEN_FAILED            (PAC_ERR_UART_BASE+6)
#define  PAC_ERR_UART_GET_COMM_STATUS_ERROR  (PAC_ERR_UART_BASE+7)
#define  PAC_ERR_UART_INVALID_VALUE          (PAC_ERR_UART_BASE+8)
#define  PAC_ERR_UART_INTERNAL_BUFFER_OVERFLOW (PAC_ERR_UART_BASE+9)

    //IO========================================================================
#define  PAC_ERR_IO_BASE                     0x15000
#define  PAC_ERR_IO_NOT_SUPPORT              (PAC_ERR_IO_BASE+1)
#define  PAC_ERR_IO_ID                       (PAC_ERR_IO_BASE+2)
#define  PAC_ERR_IO_SLOT                     (PAC_ERR_IO_BASE+3)
#define  PAC_ERR_IO_CHANNEL                  (PAC_ERR_IO_BASE+4)
#define  PAC_ERR_IO_GAIN                     (PAC_ERR_IO_BASE+5)
#define  PAC_ERR_IO_INT_MODE                 (PAC_ERR_IO_BASE+6)
#define  PAC_ERR_IO_VALUE_OUT_OF_RANGE       (PAC_ERR_IO_BASE+7)
#define  PAC_ERR_IO_CHANNEL_OUT_OF_RANGE     (PAC_ERR_IO_BASE+8)
#define  PAC_ERR_IO_DO_CANNOT_OVERWRITE      (PAC_ERR_IO_BASE+10)
#define  PAC_ERR_IO_AO_CANNOT_OVERWRITE      (PAC_ERR_IO_BASE+11)

    //Backplane Timer===========================================================
#define  PAC_ERR_BPTIMER_BASE                0x16000
#define  PAC_ERR_BPTIMER_REGISTERED          (PAC_ERR_BPTIMER_BASE + 1)
#define  PAC_ERR_BPTIMER_NOT_REGISTERED      (PAC_ERR_BPTIMER_BASE + 2)
#define  PAC_ERR_OPEN_TIMER                  (PAC_ERR_BPTIMER_BASE + 3)

    //Buzzer ===========================================================
#define  PAC_ERR_BUZZER_BASE                 0x165000
#define  PAC_ERR_BUZZER_CLOSE               (PAC_ERR_BUZZER_BASE + 1)
#define  PAC_ERR_BUZZER_SET                 (PAC_ERR_BUZZER_BASE + 2)
#define  PAC_ERR_BUZZER_THREAD              (PAC_ERR_BUZZER_BASE + 3)

#ifdef __cplusplus
}
#endif


//#pragma comment(lib, "PACSDK.lib")
//#pragma warning(disable:4099)     //disable sprintf to sprintf_s warning


#endif //__PACSDK_H    