/******************************************************/
/*  I/O scan kernel head file                         */
/*  For I-8000                                        */
/*                                                    */
/*  [2006,07,04] first released by Kevin              */
/*                                                    */
/*  Note: head file version is different to           */
/*        lib file version.                           */
/*                                                    */
/******************************************************/
/*
[2011, 09, 01] by MAc
    Change the sub elements's dimension of t_RangeCode to 20 
[2006,07,20] by Kevin
    Change function name
        SMMI_Offset_Get_AIOffset_FromEEPROM ==> SMMI_Offset_Get_AIOffset
        SMMI_Offset_Write_AIOffset_ToEEPROM ==> SMMI_Offset_Set_AIOffset
*/

extern unsigned int iMemoryAddr_IO_DI[8];
extern unsigned int iMemoryAddr_IO_DO[8];
extern unsigned int iMemoryAddr_IO_AI[8];
extern unsigned int iMemoryAddr_IO_AO[8];

extern unsigned int iMemoryNum_IO_DI[8];
extern unsigned int iMemoryNum_IO_DO[8];
extern unsigned int iMemoryNum_IO_AI[8];
extern unsigned int iMemoryNum_IO_AO[8];

extern int iTotal_DINum,iTotal_DONum,iTotal_AINum,iTotal_AONum;    // Total DI,DO,AI,AO numbers.
    // To put user-defined registers to the momory,
    // the begining offset index is iTotal_DINum,iTotal_DONum,iTotal_AINum,iTotal_AONum.
    // For example:
    //      iMemory_IO_DI[iTotal_DINum]=1;       // the 1st user-defined DI register
    //      iMemory_IO_DI[iTotal_DINum+1]=0;     // the 2nd user-defined DI register
    //      iMemory_IO_DO[iTotal_DONum]=1;       // the 1st user-defined DO register
    //      iMemory_IO_AI[iTotal_AINum+5]=1234;  // the 6th user-defined AI register
    //      iMemory_IO_AO[iTotal_AONum+2]=4567;  // the 3th user-defined AO register
    
    
int Init_IO_Scan(unsigned char far *iPointer_DI, 
                 unsigned char far *iPointer_DO,
                           int far *iPointer_AI,
                           int far *iPointer_AO);
int UpdateIOModule(void);

int SMMI_Net_CheckIn(void);
int SMMI_Offset_CheckIn(void);
int Configuration(unsigned char *Command,unsigned char *Result);
//==================================================//
//      Prototype of I/O module access functions    //
//==================================================//
void ScanIOModule(int iSlot);
    // iSlot: scan which slot now?
    
int SMMI_Offset_Get_AIOffset(int iSlot,int iChannel);
int SMMI_Offset_Set_AIOffset(int iSlot,int iChannel,int iValue);
    

// To store analog module setting
// I-87K module uses same setting for every channels
// I-8K module uses different setting for each channel 
// Range code of digital modules are 0x40.
//typedef struct t_RangeCode{
//    unsigned char cRangeCode[16];
//    float fSpan[16];     // 0 ~ Maximum value 
//    float fGainP[16];    // For AI modules, iValue(Memory:0~32767)=fValue(real:0~fSpan)/fGainP
//                        // For AO modules, fValue(Real:0~fSpan)=iValue(Memory:0~32767)*fGainP
//    float fGainN[16];    // For AI modules, iValue(Memory:0~-32768)=fValue(real:0~-fSpan)/fGainN
//                        // For AO modules, fValue(Real:0~-fSpan)=iValue(Memory:0~-32768)*fGainN
//}RANGECODE;
typedef struct t_RangeCode{
    unsigned char cRangeCode[20];
    float fSpan[20];     // 0 ~ Maximum value 
    float fGainP[20];    // For AI modules, iValue(Memory:0~32767)=fValue(real:0~fSpan)/fGainP
                        // For AO modules, fValue(Real:0~fSpan)=iValue(Memory:0~32767)*fGainP
    float fGainN[20];    // For AI modules, iValue(Memory:0~-32768)=fValue(real:0~-fSpan)/fGainN
                        // For AO modules, fValue(Real:0~-fSpan)=iValue(Memory:0~-32768)*fGainN
}RANGECODE;
extern RANGECODE rcRangeCodeSetting[8]; //8 slots max.    

//extern int iMemory_IO_AI_Offset[8][16];
extern int iMemory_IO_AI_Offset[8][20];