#ifdef	__cplusplus  // for C++ compile use

extern "C" {
#endif	

#define  i9172_GetLibVersion         i8172W_GetLibVersion
#define  i9172_Init                  i8172W_Init
#define  i9172_WriteDOGroup          i8172W_WriteDOGroup
#define  i9172_WriteDOBit            i8172W_WriteDOBit
#define  i9172_ReadDIGroup           i8172W_ReadDIGroup
#define  i9172_ReadDIBit             i8172W_ReadDIBit
#define  i9172_ReadDIGroupStatus     i8172W_ReadDIGroupStatus
#define  i9172_ReadInputGroupStatus  i8172W_ReadInputGroupStatus
#define  i9172_DIO_WriteDOGroup      i8172W_DIO_WriteDOGroup
#define  i9172_DIO_WriteDOBit        i8172W_DIO_WriteDOBit
#define  i9172_DIO_ReadDIGroup       i8172W_DIO_ReadDIGroup
#define  i9172_DIO_ReadDIBit         i8172W_DIO_ReadDIBit
#define  i9172_ReadAIHex             i8172W_ReadAIHex
#define  i9172_AIHexToFloat          i8172W_AIHexToFloat
#define  i9172_ReadAI_Ch             i8172W_ReadAI_Ch
#define  i9172_ReadAI_All            i8172W_ReadAI_All
#define  i9172_WriteAOHex            i8172W_WriteAOHex
#define  i9172_WriteAOFloat          i8172W_WriteAOFloat


// function for I-8172 & I-9172 I/O 
int i8172W_GetLibVersion(); 
/*********************************************************
User use this function to read the version of lib.
*********************************************************/
 
//void i8172W_GetLibDate(char *LibDate); 
/********************************************************
Reading the date of lib lately. 
*********************************************************/


int i8172W_Init(int iSlot);
/***************************************************************
Read hardware ID                                      
    iSlot: 1 ~ 8
    return:  0    OK
            -1    error                                       
****************************************************************/  


// function for I-8172/9172 to FR-2057
void i8172W_WriteDOGroup(int iSlot,int iPort, int iGroup,unsigned int iData);
/***************************************************************
User use this function to write Hex value to DO (for FR-2057) module,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7
           Every group has 16 channels.
    iData  0 ~ 0xffff
****************************************************************/


void i8172W_WriteDOBit(int iSlot,int iPort,int iGroup,int iChannel,int iStatus);
/****************************************************************
User use this function to write single channel to DO (for FR-2057) module,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7
           Every group has 16 channels.
    iBit: 0~15
    iStatus: 0 off
             1 on
****************************************************************/


// function for I-8172/9172 to FR-2053
unsigned int i8172W_ReadDIGroup(int iSlot,int iPort,int iGroup);
/***************************************************************
User use this function to read value from DI (for FR-2053 ) module,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7
           Every group has 16 channels.
    
    return: DI Value (0 ~ 0xffff)
    
****************************************************************/


unsigned int i8172W_ReadDIBit(int iSlot,int iPort,int iGroup,int iChannel);
/***************************************************************
User use this function to read single channel from DI (for FR-2053 ) module,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7
           Every group has 16 channels.
    iChannel: 0 ~ 15
    return: 0 or 1  
************************************************************/ 


int i8172W_ReadDIGroupStatus(int iSlot,int iPort, int iGroup);


//FR-2053, FR-2054, FR-2017 function
int i8172W_ReadInputGroupStatus(int iSlot,int iPort, int iGroup);
/**************************************************************
Read status of DI Group Communication Status
	  iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0~7
	return 0 offline, 1 online
***************************************************************/



// function used for FR-2054
void i8172W_DIO_WriteDOGroup(int iSlot,int iPort, int iGroup,unsigned int iData);
/***************************************************************
User use this function to input Hex value to DO module,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7
    iData: 0 ~ 0xff
****************************************************************/



//FR-2054 function
void i8172W_DIO_WriteDOBit(int iSlot,int iPort,int iGroup,int iChannel, int iStatus);
/****************************************************************
User use this function to input write channel to DO (for FR-2054 ) module,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7           
    iBitIndex: 0~7
    iStatus: 0 off
             1 on
****************************************************************/


//FR-2054 function
unsigned int i8172W_DIO_ReadDIGroup(int iSlot,int iPort,int iGroup);
/***************************************************************
User use this function to read value from DI (for FR-2054 ) module,
    iSlot:  1 ~ 8
    iPort: 0 or 1
    iGroup: 8 ~ 15    
    return: DI Value 0 ~ 0xff
    
****************************************************************/


//FR-2054 function
unsigned int i8172W_DIO_ReadDIBit(int iSlot,int iPort,int iGroup,int iChannel);
/***************************************************************
User use this function to read single channel from DI(for FR-2054 ) module,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 8 ~ 15           
    iChannel: 0 ~ 7
    return: 0 or 1  
************************************************************/ 



//FR-2017 function
short i8172W_ReadAIHex(int iSlot,int iPort,int iGroup,short bitMode,short *iChannel, short* aiHex);
/***************************************************************
User use this function to read channel index and analog input data get from FR-2017,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 8 ~ 15
    bitMode: 12 means 12-bit mode, 16 means 16-bit mode.
    *iChannel: requested channel index get from FR-2017
    *aiHex: requested hex format analog input data from FR-2017
    
    return: if return < 0 means Read AI Hex failed else means Read AI Hex successfully. 
    
    Note: For FRnet, FR-2017 update 16-bit data coutinuous every 2.8 ms,
    if 16-bit mode, *iChannel always be 0, and aiHex will be the only analog input data.
    
    if 12-bit mode, the data format defined as 
    MSB																														LSB
	bit15	bit14	bit13	bit12	bit11	bit10	Bit9	Bit8	Bit7	Bit6	Bit5	Bit4	Bit3	Bit2	Bit1	Bit0
	|<------------------------------12-bits AD data------------------------------------------->|    |<----- Channel Index  ---->|

    if 12-bit mode, we have to use i9172_ReadAIHex function to get which channel and data get from FR-2017, 
    if use i9172_ReadAIHex to get hex data from FR-2017, we have to use i9172_AIHexToFloat with typeCode and bitMode to convert the hex data to float.
    
****************************************************************/


   //i8172_AIHexToFloat(iArr[i],  typeCode[i],  bitMode);	
void i8172W_AIHexToFloat(short hexData, short typeCode, short bitMode, float* fData);
/***************************************************************
User use this function to convert hex format analog input data to float format,
    hexData: hex format analog input data get from FR-2017 with function i9172_ReadAIHex
    typeCode: the input range of FR-2017
    bitMode: 12 means 12-bit mode, 16 means 16-bit mode.    
    fData: converted float format data.
 	
 	FR_2017 type code
 	0x1a	0 ~ 20 mA
	0x7		4 ~ 20 mA
	0x8		+/-10 V
	0x9		+/-5 V
	0xa		+/-1 V
	0xb		+/-500 mV
	0xc		+/-150 mV 
	0xd		+/-20 mA    
****************************************************************/


short i8172W_ReadAI_Ch(int iSlot,int iPort, int iGroup, short bitMode,short typeCode, short iChannel, float* aiFloat);
/***************************************************************
User use this function to read channel index and analog input data get from FR-2017,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 8 ~ 15
    bitMode: 12 means 12-bit mode, 16 means 16-bit mode.
    typeCode: the input range of FR-2017
    iChannel: requested channel index of FR-2017
    *aiFloat: requested float format analog input data from FR-2017
    
    return: the sampling time needs for i9172_ReadAI_Ch to get the iChannel index data from FR-2017. 
    
    Note: for most users, it is not convenient to use i9172_ReadAIHex to get the analog input data from FR-2017
    By using i9172_ReadAI_Ch, program will blocked for about 0 to 45 ms to get certain channel index data.
	
	FR_2017 type code
 	0x1a	0 ~ 20 mA
	0x7		4 ~ 20 mA
	0x8		+/-10 V
	0x9		+/-5 V
	0xa		+/-1 V
	0xb		+/-500 mV
	0xc		+/-150 mV 
	0xd		+/-20 mA        
****************************************************************/


short i8172W_ReadAI_All(int iSlot,int iPort, int iGroup, short bitMode,short isSingleEnded,short typeCode[],  float aiFloat[]);
/***************************************************************
User use this function to read all analog input data get from FR-2017,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 8 ~ 15
    bitMode: 12 means 12-bit mode, 16 means 16-bit mode.
    isSingleEnded: 0 differential mode , 
    			   1 single-ended mode , 
    typeCode[]: the input range array of FR-2017    
    aiFloat[]: requested float format analog input data array.
    
    return: the sampling time needs for i9172_ReadAI_ALL to get the all analog input data from FR-2017.     
    Note: for most users, it is not convenient to use i9172_ReadAIHex to get the analog input data from FR-2017
    By using i9172_ReadAI_ALL, program will blocked for about 0 to 45 ms to get all channels' data.   
	
	FR_2017 type code
	0x7		4 ~ 20 mA
	0x8		+/-10 V
	0x9		+/-5 V
	0xa		+/-1 V
	0xb		+/-500 mV
	0xc		+/-150 mV 
	0xd		+/-20 mA     
	0x1a	0 ~ 20 mA
****************************************************************/


short i8172W_WriteAOHex(int iSlot,int iPort,int iGroup,short bitMode,short iChannel, short aoHexData, short ifDelay);
/***************************************************************
User use this function to write analog output data by FR-2024,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7
    bitMode: 12 means 12-bit mode, at present only support 12-bit mode, reserved this parameter for future I/O with different bit mode.    
    iChannel: channel index of FR-2024
    aoHexData: analog output data.
    delayTime: the delay time after FR-2024 write analog output data.
    return: 0. 
    
    Note: for some application,program may use a for loop to write analog output by using i9172_WriteAOHex,
    but for FRnet protocol, each command will have 3 ms delay for 250K setting and 1 ms delay for 1M setting.
    if there is no need to write analog output continuously, the delayTime may set as 0   
****************************************************************/


short i8172W_WriteAOFloat(int iSlot,int iPort,int iGroup,short bitMode,short iChannel, short typeCode, float aoFloat, short ifDelay);
/***************************************************************
User use this function to write analog output data by FR-2024,
    iSlot: 1 ~ 8
    iPort: 0 or 1
    iGroup: 0 ~ 7
    bitMode: 12 means 12-bit mode, at present only support 12-bit mode, reserved this parameter for future I/O with different bit mode.
    typeCode: the input range of FR-2024
    iChannel: channel index of FR-2024
    aoHexData: analog output data.
    delayTime: the delay time after FR-2024 write analog output data.
    return: 0. 
    
    Note: for some application,program may use a for loop to write analog output by using i9172_WriteAOFloat,
    but for FRnet protocol, each command will have 3 ms delay for 250K setting and 1 ms delay for 1M setting.
    if there is no need to write analog output continuously, the delayTime may set as 0   
   
	typeCode for FR-2024    
	0 ~ 20mA	0x30
	4 ~ 20mA	0x31
	0V ~ +10V	0x32
	-10V ~ +10V	0x33
	0V ~ +5V	0x34
	-5V ~ +5V	0x35
****************************************************************/


#ifdef	__cplusplus
}
#endif	/*	__cplusplus	*/

