long getDacBinVoltCalibrated(ue9CalibrationInfo *caliInfo, int dacNumber, double analogVolt, uint16 *bytesVolt) { double tBytesVolt; if( isCalibrationInfoValid(caliInfo) == 0 ) return -1; if( dacNumber < 0 || dacNumber > 2 ) { printf("getDacBinVoltCalibrated error: invalid channelNumber.\n"); return -1; } tBytesVolt = analogVolt*caliInfo->ccConstants[10 + dacNumber*2] + caliInfo->ccConstants[11 + dacNumber*2]; //Checking to make sure bytesVoltage will be a value between 0 and 4095, or //that a uint16 overflow does not occur. A too high analogVoltage (above 5 //volts) or too low analogVoltage (below 0 volts) will cause a value not //between 0 and 4095. if( tBytesVolt < 0 ) tBytesVolt = 0; if( tBytesVolt > 4095 ) tBytesVolt = 4095; *bytesVolt = (uint16)tBytesVolt; return 0; }
long getDacBinVoltCalibrated16Bit(u3CalibrationInfo *caliInfo, int dacNumber, double analogVolt, uint16 *bytesVolt16) { double tBytesVolt; if(isCalibrationInfoValid(caliInfo) == 0) return -1; if(dacNumber < 0 || dacNumber > 2) { printf("getDacBinVoltCalibrated16Bit error: invalid channelNumber.\n"); return -1; } if(caliInfo->hardwareVersion < 1.30) tBytesVolt = analogVolt*caliInfo->ccConstants[4 + dacNumber*2] + caliInfo->ccConstants[5 + dacNumber*2]; else tBytesVolt = analogVolt*caliInfo->ccConstants[4 + dacNumber*2]*256 + caliInfo->ccConstants[5 + dacNumber*2]*256; //Checking to make sure bytesVolt will be a value between 0 and 255/65535. Too //high of an analogVoltage (about 4.95 and above volts) or too low (below 0 //volts) will cause a value not between 0 and 255/65535. if(tBytesVolt < 0) tBytesVolt = 0; if(tBytesVolt > 65535 && caliInfo->hardwareVersion >= 1.30) tBytesVolt = 65535; else if(tBytesVolt > 255 && caliInfo->hardwareVersion < 1.30) tBytesVolt = 255; *bytesVolt16 = (uint16)tBytesVolt; return 0; }
long getDacBinVoltCalibrated16Bit(u6CalibrationInfo *caliInfo, int dacNumber, double analogVolt, uint16 *bytesVolt16) { uint32 dBytesVolt; if(isCalibrationInfoValid(caliInfo) == -1) return -1; if(dacNumber < 0 || dacNumber > 2) { printf("getDacBinVoltCalibrated error: invalid channelNumber.\n"); return -1; } dBytesVolt = analogVolt*caliInfo->ccConstants[16 + dacNumber*2] + caliInfo->ccConstants[17 + dacNumber*2]; //Checking to make sure bytesVolt will be a value between 0 and 65535. if(dBytesVolt < 0) dBytesVolt = 0; if(dBytesVolt > 65535) dBytesVolt = 65535; *bytesVolt16 = (uint16)dBytesVolt; return 0; }
long getAinVoltCalibrated(ue9CalibrationInfo *caliInfo, uint8 gainBip, uint8 resolution, uint16 bytesVolt, double *analogVolt) { if( isCalibrationInfoValid(caliInfo) == 0 ) return -1; if( resolution < 18 ) { if( (gainBip >= 0 && gainBip <= 3) || gainBip == 8 ) { if( gainBip == 8 ) gainBip = 4; //setting this for index purposes *analogVolt = (caliInfo->ccConstants[gainBip*2]*bytesVolt) + caliInfo->ccConstants[gainBip*2 + 1]; return 0; } else goto invalidGainBip; } else //UE9 Pro high res { if( gainBip == 0 || gainBip == 8 ) { if( gainBip == 8 ) gainBip = 1; //setting this for index purposes *analogVolt = (caliInfo->ccConstants[gainBip*2 + 21]*bytesVolt) + caliInfo->ccConstants[gainBip*2 + 22]; return 0; } else goto invalidGainBip; } invalidGainBip: printf("getAinVoltCalibrated error: invalid GainBip.\n"); return -1; }
long binaryToCalibratedAnalogVoltage(ue9CalibrationInfo *caliInfo, uint8 gainBip, uint8 resolution, uint16 bytesVoltage, double *analogVoltage) { double slope; double offset; if(isCalibrationInfoValid(caliInfo) == -1) return -1; if(resolution < 18) { switch( (unsigned int)gainBip ) { case 0: slope = caliInfo->unipolarSlope[0]; offset = caliInfo->unipolarOffset[0]; break; case 1: slope = caliInfo->unipolarSlope[1]; offset = caliInfo->unipolarOffset[1]; break; case 2: slope = caliInfo->unipolarSlope[2]; offset = caliInfo->unipolarOffset[2]; break; case 3: slope = caliInfo->unipolarSlope[3]; offset = caliInfo->unipolarOffset[3]; break; case 8: slope = caliInfo->bipolarSlope; offset = caliInfo->bipolarOffset; break; default: goto invalidGainBip; } } else //UE9 Pro high res { switch( (unsigned int)gainBip ) { case 0: slope = caliInfo->hiResUnipolarSlope; offset = caliInfo->hiResUnipolarOffset; break; case 8: slope = caliInfo->hiResBipolarSlope; offset = caliInfo->hiResBipolarOffset; break; default: goto invalidGainBip; } } *analogVoltage = (slope * bytesVoltage) + offset; return 0; invalidGainBip: printf("binaryToCalibratedAnalogVoltage error: invalid GainBip.\n"); return -1; }
long analogToCalibratedBinary8BitVoltage(u3CalibrationInfo *caliInfo, int DACNumber, double analogVoltage, uint8 *bytesVoltage8) { double tempBytesVoltage; if (isCalibrationInfoValid(caliInfo) == -1) return -1; switch(DACNumber) { case 0: tempBytesVoltage = analogVoltage*caliInfo->dacSlope[0] + caliInfo->dacOffset[0]; break; case 1: tempBytesVoltage = analogVoltage*caliInfo->dacSlope[1] + caliInfo->dacOffset[1]; break; default: printf("analogToCalibratedBinaryVoltage error: invalid channelNumber.\n"); return -1; } //Checking to make sure bytesVoltage will be a value between 0 and 255. Too //high of an analogVoltage (about 4.95 and above volts) or too low (below 0 //volts) will cause a value not between 0 and 255. if (tempBytesVoltage < 0) tempBytesVoltage = 0; else if (tempBytesVoltage > 255 && caliInfo->hardwareVersion < 1.30) tempBytesVoltage = 255; *bytesVoltage8 = (uint8)tempBytesVoltage; return 0; }
long getAinVoltCalibrated(u6CalibrationInfo *caliInfo, int resolutionIndex, int gainIndex, int bits24, uint32 bytesVolt, double *analogVolt) { double value = 0; int indexAdjust = 0; if(isCalibrationInfoValid(caliInfo) == -1) return -1; value = (double)bytesVolt; if(bits24) value = value/256.0; if(gainIndex > 4) { printf("getAinVoltCalibrated error: invalid gain index.\n"); return -1; } if(resolutionIndex > 8) indexAdjust = 24; if(value < caliInfo->ccConstants[indexAdjust + gainIndex*2 + 9]) *analogVolt = (caliInfo->ccConstants[indexAdjust + gainIndex*2 + 9] - value) * caliInfo->ccConstants[indexAdjust + gainIndex*2 + 8]; else *analogVolt = (value - caliInfo->ccConstants[indexAdjust + gainIndex*2 + 9]) * caliInfo->ccConstants[indexAdjust + gainIndex*2]; return 0; }
long eDAC(HANDLE Handle, u3CalibrationInfo *CalibrationInfo, long ConfigIO, long Channel, double Voltage, long Binary, long Reserved1, long Reserved2) { uint8 sendDataBuff[3]; uint8 byteV, DAC1Enabled, Errorcode, ErrorFrame; uint16 bytesV; long error, sendSize; if(isCalibrationInfoValid(CalibrationInfo) == 0) { printf("eDAC error: calibration information is required"); return -1; } if(Channel < 0 || Channel > 1) { printf("eDAC error: Invalid DAC channel\n"); return -1; } if(ConfigIO != 0 && Channel == 1 && CalibrationInfo->hardwareVersion < 1.30) { //Using ConfigIO to enable DAC1 error = ehConfigIO(Handle, 2, 0, 1, 0, 0, NULL, &DAC1Enabled, NULL, NULL); if(error != 0) return error; } /* Setting up Feedback command to set DAC */ if(CalibrationInfo->hardwareVersion < 1.30) { sendSize = 2; sendDataBuff[0] = 34 + Channel; //IOType is DAC0/1 (8 bit) if(getDacBinVoltCalibrated8Bit(CalibrationInfo, (int)Channel, Voltage, &byteV) < 0) return -1; sendDataBuff[1] = byteV; //Value } else { sendSize = 3; sendDataBuff[0] = 38 + Channel; //IOType is DAC0/1 (16 bit) if(getDacBinVoltCalibrated16Bit(CalibrationInfo, (int)Channel, Voltage, &bytesV) < 0) return -1; sendDataBuff[1] = (uint8)(bytesV&255); //Value LSB sendDataBuff[2] = (uint8)((bytesV&65280)/256); //Value MSB } if(ehFeedback(Handle, sendDataBuff, sendSize, &Errorcode, &ErrorFrame, NULL, 0) < 0) return -1; if(Errorcode) return (long)Errorcode; return 0; }
long getTempKCalibrated(u3CalibrationInfo *caliInfo, uint32 bytesTemp, double *kelvinTemp) { if(isCalibrationInfoValid(caliInfo) == 0) return -1; *kelvinTemp = caliInfo->ccConstants[8]*((double)bytesTemp); return 0; }
long binaryToCalibratedAnalogTemperature(u3CalibrationInfo *caliInfo, uint16 bytesTemperature, double *analogTemperature) { if (isCalibrationInfoValid(caliInfo) == -1) return -1; *analogTemperature = caliInfo->tempSlope*((double)bytesTemperature); return 0; }
long eAIN(HANDLE Handle, ue9CalibrationInfo *CalibrationInfo, long ChannelP, long ChannelN, double *Voltage, long Range, long Resolution, long Settling, long Binary, long Reserved1, long Reserved2) { uint8 IOType, Channel, AINM, AINH, ainGain; uint16 bytesVT; if( isCalibrationInfoValid(CalibrationInfo) == 0 ) { printf("eAIN error: calibration information is required"); return -1; } if( Range == LJ_rgBIP5V ) ainGain = 8; else if( Range == LJ_rgUNI5V ) ainGain = 0; else if( Range == LJ_rgUNI2P5V ) ainGain = 1; else if( Range == LJ_rgUNI1P25V ) ainGain = 2; else if( Range == LJ_rgUNIP625V ) ainGain = 3; else { printf("eAIN error: Invalid Range\n"); return -1; } if( ehSingleIO(Handle, 4, (uint8)ChannelP, ainGain, (uint8)Resolution, (uint8)Settling, &IOType, &Channel, NULL, &AINM, &AINH) < 0 ) return -1; bytesVT = AINM + AINH*256; if( Binary != 0 ) { *Voltage = (double)bytesVT; } else { if( ChannelP == 133 || ChannelP == 141 ) { if( getTempKCalibrated(CalibrationInfo, 0, bytesVT, Voltage) < 0 ) return -1; } else { if( getAinVoltCalibrated(CalibrationInfo, ainGain, (uint8)Resolution, bytesVT, Voltage) < 0 ) return -1; } } return 0; }
long getAinVoltCalibrated_hw130(u3CalibrationInfo *caliInfo, uint8 positiveChannel, uint8 negChannel, uint16 bytesVolt, double *analogVolt) { if(isCalibrationInfoValid(caliInfo) == 0) return -1; if(caliInfo->hardwareVersion < 1.30) { printf("getAinVoltCalibrated_hw130 error: cannot handle U3 hardware versions < 1.30 . Please use getAinVoltCalibrated function.\n"); return -1; } if(negChannel <= 15 || negChannel == 30) { if(caliInfo->highVoltage == 0 || (caliInfo->highVoltage == 1 && positiveChannel >= 4 && negChannel >= 4)) *analogVolt = caliInfo->ccConstants[2]*((double)bytesVolt) + caliInfo->ccConstants[3]; else if(caliInfo->hardwareVersion >= 1.30 && caliInfo->highVoltage == 1) { printf("getAinVoltCalibrated_hw130 error: invalid negative channel for U3-HV.\n"); return -1; } } else if(negChannel == 31) { if(caliInfo->highVoltage == 1 && positiveChannel < 4) *analogVolt = caliInfo->ccConstants[12+positiveChannel]*((double)bytesVolt) + caliInfo->ccConstants[16+positiveChannel]; else *analogVolt = caliInfo->ccConstants[0]*((double)bytesVolt) + caliInfo->ccConstants[1]; } else if(negChannel == 32) //special range (binary value should be from a differential AIN reading with negative channel 30) { if(caliInfo->highVoltage == 1 && positiveChannel < 4) { *analogVolt = (caliInfo->ccConstants[2]*((double)bytesVolt) + caliInfo->ccConstants[3] + caliInfo->ccConstants[9]) * caliInfo->ccConstants[12 + positiveChannel] / caliInfo->ccConstants[0] + caliInfo->ccConstants[16 + positiveChannel]; } else { *analogVolt = caliInfo->ccConstants[2]*((double)bytesVolt) + caliInfo->ccConstants[3] + caliInfo->ccConstants[9]; } } else { printf("getAinVoltCalibrated_hw130 error: invalid negative channel.\n"); return -1; } return 0; }
long getTempKCalibrated(ue9CalibrationInfo *caliInfo, int powerLevel, uint16 bytesTemp, double *kelvinTemp) { if( isCalibrationInfoValid(caliInfo) == 0 ) return -1; if( powerLevel == 0 || powerLevel == 1 ) { *kelvinTemp = caliInfo->ccConstants[14 + powerLevel]*bytesTemp; return 0; } else { printf("getTempKCalibrated error: invalid powerLevel.\n"); return -1; } }
long eDAC(HANDLE Handle, ue9CalibrationInfo *CalibrationInfo, long Channel, double Voltage, long Binary, long Reserved1, long Reserved2) { uint8 IOType, channel; uint16 bytesVoltage; if( isCalibrationInfoValid(CalibrationInfo) == 0 ) { printf("eDAC error: calibration information is required"); return -1; } if( getDacBinVoltCalibrated(CalibrationInfo, (uint8)Channel, Voltage, &bytesVoltage) < 0 ) return -1; return ehSingleIO(Handle, 5, (uint8)Channel, (uint8)( bytesVoltage & (0x00FF) ), (uint8)(( bytesVoltage /256 ) + 192), 0, &IOType, &channel, NULL, NULL, NULL); }
long eDAC(HANDLE Handle, ue9CalibrationInfo *caliInfo, long Channel, double Voltage, long Binary, long Reserved1, long Reserved2) { uint8 IOType, channel; uint16 bytesVoltage; if(isCalibrationInfoValid(caliInfo) == -1) { analogToUncalibratedBinaryVoltage(Voltage, &bytesVoltage); } else { if(analogToCalibratedBinaryVoltage(caliInfo, (uint8)Channel, Voltage, &bytesVoltage) < 0) return -1; } return ehSingleIO(Handle, 5, (uint8)Channel, (uint8)( bytesVoltage & (0x00FF) ), (uint8)(( bytesVoltage /256 ) + 192), 0, &IOType, &channel, NULL, NULL, NULL); }
long analogToCalibratedBinaryVoltage(ue9CalibrationInfo *caliInfo, int DACNumber, double analogVoltage, uint16 *bytesVoltage) { double slope; double offset; double tempBytesVoltage; if(isCalibrationInfoValid(caliInfo) == -1) return -1; switch(DACNumber) { case 0: slope = caliInfo->DACSlope[0]; offset = caliInfo->DACOffset[0]; break; case 1: slope = caliInfo->DACSlope[1]; offset = caliInfo->DACOffset[1]; break; default: printf("analogToCalibratedBinaryVoltage error: invalid DACNumber.\n"); return -1; } tempBytesVoltage = slope*analogVoltage + offset; //Checking to make sure bytesVoltage will be a value between 0 and 4095, or //that a uint16 overflow does not occur. A too high analogVoltage (above 5 //volts) or too low analogVoltage (below 0 volts) will cause a value not //between 0 and 4095. if(tempBytesVoltage < 0) tempBytesVoltage = 0; if(tempBytesVoltage > 4095) tempBytesVoltage = 4095; *bytesVoltage = (uint16)tempBytesVoltage; return 0; }
long getAinVoltCalibrated(u3CalibrationInfo *caliInfo, int dacEnabled, uint8 negChannel, uint16 bytesVolt, double *analogVolt) { if(isCalibrationInfoValid(caliInfo) == 0) return -1; if(caliInfo->hardwareVersion >= 1.30) { if(caliInfo->highVoltage == 1) { printf("getAinVoltCalibrated error: cannot handle U3-HV device. Please use getAinVoltCalibrated_hw130 function.\n"); return -1; } else return getAinVoltCalibrated_hw130(caliInfo, 0, negChannel, bytesVolt, analogVolt); } if(negChannel <= 15 || negChannel == 30) { if(dacEnabled == 0) *analogVolt = caliInfo->ccConstants[2]*((double)bytesVolt) + caliInfo->ccConstants[3]; else *analogVolt = (bytesVolt/65536.0)*caliInfo->ccConstants[11]*2.0 - caliInfo->ccConstants[11]; } else if(negChannel == 31) { if(dacEnabled == 0) *analogVolt = caliInfo->ccConstants[0]*((double)bytesVolt) + caliInfo->ccConstants[1]; else *analogVolt = (bytesVolt/65536.0)*caliInfo->ccConstants[11]; } else { printf("getAinVoltCalibrated error: invalid negative channel.\n"); return -1; } return 0; }
long binaryToCalibratedAnalogVoltage(u3CalibrationInfo *caliInfo, int dacEnabled, uint8 negChannel, uint16 bytesVoltage, double *analogVoltage) { if (isCalibrationInfoValid(caliInfo) == -1) return -1; if (caliInfo->hardwareVersion >= 1.30) { if (caliInfo->highVoltage == 1) { printf("binaryToCalibratedAnalogVoltage error: cannot handle U3-HV device. Please use binaryToCalibratedAnalogVoltage_hw130 function.\n"); return -1; } else return binaryToCalibratedAnalogVoltage_hw130(caliInfo, 0, negChannel, bytesVoltage, analogVoltage); } if ((negChannel >= 0 && negChannel <= 15) || negChannel == 30) { if (dacEnabled == 0) *analogVoltage = caliInfo->ainDiffSlope*((double)bytesVoltage) + caliInfo->ainDiffOffset; else *analogVoltage = (bytesVoltage/65536.0)*caliInfo->vreg*2.0 - caliInfo->vreg; } else if (negChannel == 31) { if (dacEnabled == 0) *analogVoltage = caliInfo->ainSESlope*((double)bytesVoltage) + caliInfo->ainSEOffset; else *analogVoltage = (bytesVoltage/65536.0)*caliInfo->vreg; } else { printf("binaryToCalibratedAnalogVoltage error: invalid negative channel.\n"); return -1; } return 0; }
long binaryToCalibratedAnalogTemperature(ue9CalibrationInfo *caliInfo, int powerLevel, uint16 bytesTemperature, double *analogTemperature) { double slope = 0; if(isCalibrationInfoValid(caliInfo) == -1) return -1; switch( (unsigned int)powerLevel ) { case 0: //high power slope = caliInfo->tempSlope; break; case 1: //low power slope = caliInfo->tempSlopeLow; break; default: printf("binaryToCalibratedAnalogTemperature error: invalid powerLevel.\n"); return -1; } *analogTemperature = (double)(bytesTemperature)*slope; return 0; }
long binaryToCalibratedAnalogVoltage_hw130(u3CalibrationInfo *caliInfo, uint8 positiveChannel, uint8 negChannel, uint16 bytesVoltage, double *analogVoltage) { if (isCalibrationInfoValid(caliInfo) == -1) return -1; if (caliInfo->hardwareVersion < 1.30) { printf("binaryToCalibratedAnalogVoltage_hw130 error: cannot handle U3 hardware versions < 1.30 . Please use binaryToCalibratedAnalogVoltage function.\n"); return -1; } if ((negChannel >= 0 && negChannel <= 15) || negChannel == 30) { if (caliInfo->highVoltage == 0 || (caliInfo->highVoltage == 1 && positiveChannel >= 4 && negChannel >= 4)) *analogVoltage = caliInfo->ainDiffSlope*((double)bytesVoltage) + caliInfo->ainDiffOffset; else if (caliInfo->hardwareVersion >= 1.30 && caliInfo->highVoltage == 1) { printf("binaryToCalibratedAnalogVoltage_hw130 error: invalid negative channel for U3-HV.\n"); return -1; } } else if (negChannel == 31) { if (caliInfo->highVoltage == 1 && positiveChannel >= 0 && positiveChannel < 4) *analogVoltage = caliInfo->hvAINSlope[positiveChannel]*((double)bytesVoltage) + caliInfo->hvAINOffset[positiveChannel]; else *analogVoltage = caliInfo->ainSESlope*((double)bytesVoltage) + caliInfo->ainSEOffset; } else { printf("binaryToCalibratedAnalogVoltage_hw130 error: invalid negative channel.\n"); return -1; } return 0; }
long eDAC(HANDLE Handle, u6CalibrationInfo *CalibrationInfo, long Channel, double Voltage, long Binary, long Reserved1, long Reserved2) { uint8 sendDataBuff[3]; uint8 Errorcode, ErrorFrame; uint16 bytesV; long sendSize; if(isCalibrationInfoValid(CalibrationInfo) != 1) { printf("eDAC error: Invalid calibration information.\n"); return -1; } if(Channel < 0 || Channel > 1) { printf("eDAC error: Invalid Channel.\n"); return -1; } sendSize = 3; sendDataBuff[0] = 38 + Channel; //IOType is DAC0/1 (16 bit) if(getDacBinVoltCalibrated16Bit(CalibrationInfo, (int)Channel, Voltage, &bytesV) < 0) return -1; sendDataBuff[1] = (uint8)(bytesV&255); //Value LSB sendDataBuff[2] = (uint8)((bytesV&65280)/256); //Value MSB if(ehFeedback(Handle, sendDataBuff, sendSize, &Errorcode, &ErrorFrame, NULL, 0) < 0) return -1; if(Errorcode) return (long)Errorcode; return 0; }
long eAIN(HANDLE Handle, u6CalibrationInfo *CalibrationInfo, long ChannelP, long ChannelN, double *Voltage, long Range, long Resolution, long Settling, long Binary, long Reserved1, long Reserved2) { uint8 sendDataBuff[4], recDataBuff[5]; uint8 diff, gain, Errorcode, ErrorFrame; uint32 bytesV; if(isCalibrationInfoValid(CalibrationInfo) != 1) { printf("eAIN error: Invalid calibration information.\n"); return -1; } //Checking if acceptable positive channel if(ChannelP < 0 || ChannelP > 143) { printf("eAIN error: Invalid ChannelP value.\n"); return -1; } //Checking if single ended or differential readin if(ChannelN == 0 || ChannelN == 15) { //single ended reading diff = 0; } else if((ChannelN&1) == 1 && ChannelN == ChannelP + 1) { //differential reading diff = 1; } else { printf("eAIN error: Invalid ChannelN value.\n"); return -1; } if(Range == LJ_rgAUTO) gain = 15; else if(Range == LJ_rgBIP10V) gain = 0; else if(Range == LJ_rgBIP1V) gain = 1; else if(Range == LJ_rgBIPP1V) gain = 2; else if(Range == LJ_rgBIPP01V) gain = 3; else { printf("eAIN error: Invalid Range value\n"); return -1; } if(Resolution < 0 || Resolution > 13) { printf("eAIN error: Invalid Resolution value\n"); return -1; } if(Settling < 0 && Settling > 4) { printf("eAIN error: Invalid Settling value\n"); return -1; } /* Setting up Feedback command to read analog input */ sendDataBuff[0] = 3; //IOType is AIN24AR sendDataBuff[1] = (uint8)ChannelP; //Positive channel sendDataBuff[2] = (uint8)Resolution + gain*16; //Res Index (0-3), Gain Index (4-7) sendDataBuff[3] = (uint8)Settling + diff*128; //Settling factor (0-2), Differential (7) if(ehFeedback(Handle, sendDataBuff, 4, &Errorcode, &ErrorFrame, recDataBuff, 5) < 0) return -1; if(Errorcode) return (long)Errorcode; bytesV = recDataBuff[0] + ((uint32)recDataBuff[1])*256 + ((uint32)recDataBuff[2])*65536; gain = recDataBuff[3]/16; if(Binary != 0) { *Voltage = (double)bytesV; } else { if(ChannelP == 14) { if(getTempKCalibrated(CalibrationInfo, Resolution, gain, 1, bytesV, Voltage) < 0) return -1; } else { gain = recDataBuff[3]/16; if(getAinVoltCalibrated(CalibrationInfo, Resolution, gain, 1, bytesV, Voltage) < 0) return -1; } } return 0; }
long eAIN(int fd, ue9CalibrationInfo *caliInfo, long ChannelP, long ChannelN, double *Voltage, long Range, long Resolution, long Settling, long Binary, long Reserved1, long Reserved2) { uint8 IOType, Channel, AINM, AINH, ainGain; uint16 bytesVT; if(Range == LJ_rgBIP5V) ainGain = 8; else if(Range == LJ_rgUNI5V) ainGain = 0; else if(Range == LJ_rgUNI2P5V) ainGain = 1; else if(Range == LJ_rgUNI1P25V) ainGain = 2; else if(Range == LJ_rgUNIP625V) ainGain = 3; else { printf("eAIN error: Invalid Range\n"); return -1; } if(ehSingleIO(fd, 4, (uint8)ChannelP, ainGain, (uint8)Resolution, (uint8)Settling, &IOType, &Channel, NULL, &AINM, &AINH) < 0) return -1; bytesVT = AINM + AINH*256; if(Binary != 0) { *Voltage = (double)bytesVT; } else { if(isCalibrationInfoValid(caliInfo) == -1) { if(Channel == 133 || ChannelP == 141) { binaryToUncalibratedAnalogTemperature(bytesVT, Voltage); } else { if(binaryToUncalibratedAnalogVoltage(ainGain, Resolution, bytesVT, Voltage) < 0) return -1; } } else { if(ChannelP == 133 || ChannelP == 141) { if(binaryToCalibratedAnalogTemperature(caliInfo, 0, bytesVT, Voltage) < 0) return -1; } else { if(binaryToCalibratedAnalogVoltage(caliInfo, ainGain, (uint8)Resolution, bytesVT, Voltage) < 0) return -1; } } } return 0; }
long eAIN(HANDLE Handle, u3CalibrationInfo *CalibrationInfo, long ConfigIO, long *DAC1Enable, long ChannelP, long ChannelN, double *Voltage, long Range, long Resolution, long Settling, long Binary, long Reserved1, long Reserved2) { uint8 sendDataBuff[3], recDataBuff[2]; uint8 FIOAnalog, EIOAnalog, curFIOAnalog, curEIOAnalog, curTCConfig; uint8 settling, quicksample, Errorcode, ErrorFrame; uint8 outDAC1Enable; uint16 bytesVT; long error; double hwver; int hv; int isSpecialRange = 0; if(isCalibrationInfoValid(CalibrationInfo) == 0) { printf("eAIN error: calibration information is required"); return -1; } hwver = CalibrationInfo->hardwareVersion; hv = CalibrationInfo->highVoltage; if(ChannelP < 0 || (ChannelP > 15 && ChannelP != 30 && ChannelP != 31)) { printf("eAIN error: Invalid positive channel\n"); return -1; } if(ChannelN < 0 || (ChannelN > 15 && ChannelN != 30 && ChannelN != 31 && ChannelN != 32) || (hwver >= 1.30 && hv == 1 && ((ChannelP < 4 && ChannelN != 31 && ChannelN != 32) || ChannelN < 4))) { printf("eAIN error: Invalid negative channel\n"); return -1; } if (ChannelN == 32) { isSpecialRange = 1; ChannelN = 30; // Set to 30 for the feedback packet. We'll set it back to 32 for conversion. } if(ConfigIO != 0 && !(hwver >= 1.30 && hv == 1 && ChannelP < 4)) { FIOAnalog = 0; EIOAnalog = 0; //Setting ChannelP and ChannelN channels to analog using //FIOAnalog and EIOAnalog if(ChannelP <= 7) FIOAnalog = pow(2, ChannelP); else if(ChannelP <= 15) EIOAnalog = pow(2, (ChannelP - 8)); if(ChannelN <= 7) FIOAnalog = FIOAnalog | (int)pow(2, ChannelN); else if(ChannelN <= 15) EIOAnalog = EIOAnalog | (int)pow(2, (ChannelN - 8)); //Using ConfigIO to get current FIOAnalog and EIOAnalog settings if((error = ehConfigIO(Handle, 0, 0, 0, 0, 0, &curTCConfig, &outDAC1Enable, &curFIOAnalog, &curEIOAnalog)) != 0) return error; *DAC1Enable = outDAC1Enable; if( !(FIOAnalog == curFIOAnalog && EIOAnalog == curEIOAnalog) ) { //Creating new FIOAnalog and EIOAnalog settings FIOAnalog = FIOAnalog | curFIOAnalog; EIOAnalog = EIOAnalog | curEIOAnalog; //Using ConfigIO to set new FIOAnalog and EIOAnalog settings if((error = ehConfigIO(Handle, 12, curTCConfig, 0, FIOAnalog, EIOAnalog, NULL, NULL, &curFIOAnalog, &curEIOAnalog)) != 0) return error; } } /* Setting up Feedback command to read analog input */ sendDataBuff[0] = 1; //IOType is AIN settling = (Settling != 0) ? 1 : 0; quicksample = (Resolution != 0) ? 1 : 0; sendDataBuff[1] = (uint8)ChannelP + settling*64 + quicksample*128; //Positive channel (bits 0-4), LongSettling (bit 6) //QuickSample (bit 7) sendDataBuff[2] = (uint8)ChannelN; //Negative channel if(ehFeedback(Handle, sendDataBuff, 3, &Errorcode, &ErrorFrame, recDataBuff, 2) < 0) return -1; if(Errorcode) return (long)Errorcode; bytesVT = recDataBuff[0] + recDataBuff[1]*256; if (isSpecialRange) { ChannelN = 32; // Change the negative channel back to 32 from 30 for conversion. } if(Binary != 0) { *Voltage = (double)bytesVT; } else { if(ChannelP == 30) { if(getTempKCalibrated(CalibrationInfo, bytesVT, Voltage) < 0) return -1; } else { if(hwver < 1.30) error = getAinVoltCalibrated(CalibrationInfo, (int)(*DAC1Enable), ChannelN, bytesVT, Voltage); else error = getAinVoltCalibrated_hw130(CalibrationInfo, ChannelP, ChannelN, bytesVT, Voltage); if(error < 0) return -1; } } return 0; }