
#ifdef __cplusplus
extern "C" {
#endif

// Error Code Definition
#define NoError 		0
#define ID_ERROR		-1
#define SLOT_ERROR		-2
#define CHANNEL_ERROR		-3
#define GAIN_ERROR		-4
#define INT_MODE_ERROR  	-5
#define NOT_SUPPORT_ERROR	-6
#define NOT_Calibration		-7  

// error code NOT_Calibration calibration means lib failed to read the calibration parameters from eeprom
// this kind of error code aomethimes happened on CE platform at first slot of backplane.
// normally, calibration ranges for 9017HW series are between 30000 ~ 38000, if failed to read the calibration from eeprom
// the calibration parameters for gain will be 65535 (0xffff) 

#define Bad_Calibration		-8

#define  I9017_GetLibVersion         I8017_GetLibVersion
#define  I9017_GetFirmwareVersion    I8017_GetFirmwareVersion
#define  I9017_Init                  I8017_Init
#define  I9017_Get_D_Sub_Status      I8017_Get_D_Sub_Status
#define  I9017_GetSingleEndJumper    I8017_GetSingleEndJumper
#define  I9017_Select_SingleEnd      I8017_Select_SingleEnd
#define  I9017_ReadGainOffset_Info   I8017_ReadGainOffset_Info
#define  I9017_Read_mA_GainOffset    I8017_Read_mA_GainOffset
#define  I9017_SetLED                I8017_SetLED
#define  I9017_ReadAI                I8017_ReadAI
#define  I9017_ReadAI_AVG            I8017_ReadAI_AVG
#define  I9017_ReadAIHex             I8017_ReadAIHex
#define  I9017_ReadAIHex_AVG         I8017_ReadAIHex_AVG

/* function to get the library version of i-8017HW
/*	      return: version number. 
/*        for example: 0x106; = Rev:1.0.6             */

short I8017_GetLibVersion(void);				
//void I8017_GetLibDate(char libDate[]);	


/* function to get the lattice version of i-8017h at specific slot
/*        iSlot: 1 ~ 8
/*	      return: Error code .                                    */		  			
short I8017_GetFirmwareVersion(int slot, short* ver);			

/* function to initialize i-8017h at specific slot
/*        iSlot: 1 ~ 8
/*	      return: Error Code.                                     */	 
short I8017_Init(int slot);			


/* function to get connector status between D sub and 8017DW  (open or close) for i-8017DW at specific slot
/*	      D Sub status: 1  means "Open"; 0 means "Close". 
/*        iSlot: 1 ~ 8
/*		    return: Error code
/* function for I-8017DW module only, in the others 8017 series module, 
/* the value of D Sub Status will always 1 (Open)                  */				
short I8017_Get_D_Sub_Status(int slot, short* D_Sub_Status);			


/* function to get the single ended/differential jumper status for i-8017h at specific slot
/*	      selectJumper: 1 Single Ended; 0 Differential. 
/*        iSlot: 1 ~ 8
/*		    return: Error code                                       */
short I8017_GetSingleEndJumper(int slot, short* selectJumper);		

// this function is for I-9017-15 only
// for I-9017-15, it can use this function to selection single-ended/differential mode
// for 8017HW/8017HCW/8017DW/9017 they use jumper to be as single-ended or differential mode
// for 9017C-15 does not need to select single-ended/differential mode, default as differential mode.
short I8017_Select_SingleEnd(int slot, short selection);


/* function to get the calibrated gain and offset value for i-8017h at specific slot for certain input range
/*        iSlot: 1 ~ 8
/*        iGain: 0: +/- 10.0V 			
/*			         1: +/- 5.0V 
/*			         2: +/- 2.5V 
/*			         3: +/- 1.25V 
/*			         4: +/- 20mA 
/*        iGainValue: the calibated gain value 
/*        iOffsetValue: the calibated offset value 
/*		    return: Error code                                        */
short I8017_ReadGainOffset_Info(int slot,int Gain,unsigned short* GainValue, short* OffsetValue);	

// for I-9017C-15 only, each channel has its own calibration parameters
short I8017_Read_mA_GainOffset(int slot,short ch ,unsigned short* GainValue, short* offsetValue);


/* function to have programmable LED control for i-8017h at specific slot
/*        iSlot: 1 ~ 8
/*		    iLedValue: 0 ~ 0xffff
/*		    return: Error code                                        */
void I8017_SetLED(int slot,unsigned short iLedValue);		


/* function to read float format analog input data from i-8017h at specific slot
/*        iSlot: 1 ~ 8
/*        iChannel: 0 ~ 7 if Differential mode; 0 ~ 15 if Single Ended mode
/*        iGain: 0: +/- 10.0V 	
/*			         1: +/- 5.0V 
/*		           2: +/- 2.5V 
/*			         3: +/- 1.25V 
/*			         4: +/- 20mA 
/*		    fValue: float format analog input data. 
/*		    return: Error code                                        */				
short I8017_ReadAI(int slot,int iChannel,int iGain,float* fValue);						


/* function to read float format analog input data from i-8017h at specific slot
/*        iSlot: 1 ~ 8
/*        iChannel: 0 ~ 7 if Differential mode; 0 ~ 15 if Single Ended mode
/*        iGain: 0: +/- 10.0V 
/*			         1: +/- 5.0V 
/*			         2: +/- 2.5V 
/*			         3: +/- 1.25V 
/*			         4: +/- 20mA 
/*		  fValue: float format analog input data. 
/*		  return: Error code                                          */
short I8017_ReadAI_AVG(int slot,int iChannel,int iGain,unsigned short averageCnt,float* fValue);				


/* function to read 16 bit hex format analog input data from i-8017h at specific slot
/*        iSlot: 1 ~ 8
/*        iChannel: 0 ~ 7 if Differential mode; 0 ~ 15 if Single Ended mode
/*        iGain: 0: +/- 10.0V 	
/*			         1: +/- 5.0V 
/*			         2: +/- 2.5V 
/*			         3: +/- 1.25V 
/*			         4: +/- 20mA 
/*		  averageCnt: the average count for each sampling routine.
/*		  iValue: 16 bit hex format analog input data. 
/*		  return: Error code                                          */
short I8017_ReadAIHex(int slot,int iChannel,int iGain,short* iValue);				


/* function to read average value for 16 bit hex format analog input data from i-8017h at specific slot
/*        iSlot: 1 ~ 8
/*        iChannel: 0 ~ 7 if Differential mode; 0 ~ 15 if Single Ended mode
/*        iGain: 0: +/- 10.0V 
/*			         1: +/- 5.0V 
/*		           2: +/- 2.5V 
/*			         3: +/- 1.25V 
/*			         4: +/- 20mA 
/*		  averageCnt: the average count for each sampling routine.
/*		  iValue: 16 bit hex format analog input data. 
/*		  return: Error code                                          */
short I8017_ReadAIHex_AVG(int slot,int iChannel,int iGain,unsigned short averageCnt,short* iValue);		

                      	
#ifdef __cplusplus
}
#endif

