/********************************************************************/ /* XW304 API Functions for uPAC-5000 Series */ /* */ /* [Mar 29, 2012] by Liam version 1.00 */ /********************************************************************/ #ifndef __XW304_H #define __XW304_H #ifdef __cplusplus extern "C" { #endif #define AI_TYPE1 0 /* +/-5V */ #define AI_TYPE2 1 /* 0~5V */ int XW304_Init(void); /* Initiate the XW304 library Return On success, returns zero On error, returns a non-zero value Bit0: 1 => Read A/D Gain falure (+/-5V) Bit1: 1 => Read A/D Offset falure (+/-5V) Bit2: 1 => Read A/D Gain falure (0~5V) Bit3: 1 => Read A/D Offset falure (0~5V) Bit4: 1 => Read D/A Gain falure (+/5V) Bit5: 1 => Read D/A Offset falure (+/5V) Bit7: 1 => XW304 cannot be found */ unsigned XW304_GetLibVersion(void); /* Get the version number of XW304 library Return It always returns a non-zero value to indicate the current version 0x100 indicates the version is 1.00 */ void XW304_GetLibDate(char *date); /* Get the build date of the current version of XW304 library Argument date: Buffer where function writes the string */ float XW304_Read_AD_Gain(int ai_type); /* Read the calibration data stored in the EEPROM Argument ai_type: Analog input range selectable, 0 for (+/-5V) and 1 for (0~5V) This argument must correspond with the jumper-selectable setting on the XW304 Return On error, returns 10.0 if there was no setting in the EEPROM */ float XW304_Read_AD_Offset(int ai_type); /* Read the calibration data stored in the EEPROM Argument ai_type: Analog input range selectable, 0 for (+/-5V) and 1 for (0~5V) This argument must correspond with the jumper-selectable setting on the XW304 Return On error, returns 10.0 if there was no setting in the EEPROM */ float XW304_Read_DA_Gain(void); /* Read the calibration data stored in the EEPROM Return On error, returns 10.0 if there was no setting in the EEPROM */ float XW304_Read_DA_Offset(void); /* Read the calibration data stored in the EEPROM Return On error, returns 10.0 if there was no setting in the EEPROM */ void XW304_SetDelay(unsigned delay); /* Specify a short time delay, in milliseconds, to wait before obtaining the raw data from the analog to digital converter chip Argument delay: Delay time, represented as a integer in the range [0, 1000] (unit: 0.01 ms) */ unsigned XW304_GetDelay(void); /* Read back the time delay */ float XW304_AnalogIn(int ai_type, int channel); /* Read the current input voltage, represented as a float in the range [-5, 5] or [0, 5] Argument ai_type: Analog input range selectable, 0 for (+/-5V) and 1 for (0~5V) This argument must correspond with the jumper-selectable setting on the XW304 channel: Channel number, represented as 0, 1, 2, 3, 4 and 5 Return Return the voltage supplied by a voltage source */ void XW304_AnalogInSetChannel(int channel); /* Specify the input channel number before the call of XW304_AnalogInHex() Argument channel: Channel number, represented as 0, 1, 2, 3, 4 and 5 */ int XW304_AnalogInHex(void); /* Read a raw data from the analog to digital converter chip Return A raw data obtained from the analog to digital converter chip, represented as a hex value in the range [0, 0xFFF] */ float XW304_AnalogInHexToFloat(int ai_type, int value); /* Convert a raw data reading into a voltage reading Argument ai_type: Analog input range selectable, 0 for [-5, 5] and 1 for [0, 5] This argument must correspond with the jumper-selectable setting on the XW304 value: The raw data returned by XW304_AnalogInHex() Return Return the voltage, represented as a float */ void XW304_AnalogOut(float value); /* Set the output voltage Argument value: Set the output voltage, represented as a float in the range [-5, 5] */ int XW304_Read_All_DI(void); /* Read the input status of all channels Return All digital inputs are packed as one channel per bit of the return data. Status is indicated as 0=ON (short to GND) and 1=OFF (Open) For example: The status of inputs is shown as the byte value 0C hex, or binary 0000 1010. DI3 is in the fifth bit position from the left, and DI0 is the LSB of this byte. The four remaining high order bits are zero filled. */ int XW304_Read_One_DI(int channel); /* Read the input status of the specified channel Argument channel: Channel number, represented as 0, 1, 2 and 3 Return 0 for ON (short to GND) and 1 for OFF (Open) */ void XW304_Write_All_DO(int value); /* Set the output status for all channels Argument value: All digital outputs are packed as one channel per bit of the writing value */ void XW304_Write_One_DO(int channel, int status); /* Set the output status for the specified channel Argument channel: Channel number, represented as 0, 1, 2 and 3 status: An integer specifying the output value, 0 for OFF and 1 for ON */ int XW304_Read_All_DO(void); /* Read back the current status of all channels Return All digital outputs are packed as one channel per bit of the return data. Status is indicated as 1=ON and 0=OFF For example: The status of outputs is shown as the byte value 0C hex, or binary 0000 1010. DO3 is in the fifth bit position from the left, and DO0 is the LSB of this byte. The four remaining high order bits are zero filled. */ int XW304_Read_One_DO(int channel); /* Read back the current status of the specified channel Argument channel: Channel number, represented as 0, 1, 2 and 3 Return An integer representing the output state, 0 for OFF and 1 for ON */ #ifdef __cplusplus } #endif #endif