Beispiel #1
0
int readIntTemp(int socketFD, ue9CalibrationInfo *caliInfo, 
		double *dblIntTemp)
{
  uint8 sendBuff[8], recBuff[8];
  int sendChars, recChars;
  //  double voltage;
  double temperature; //in Kelvins
  uint16 bytesTemperature;
  uint8 ainResolution;

  ainResolution = 12;

  /* read temperature from internal temperature sensor */
  sendBuff[1] = (uint8)(0xA3);  //command byte
  sendBuff[2] = (uint8)(0x04);  //IOType = 4 (analog in)
  sendBuff[3] = (uint8)(0x85);  //Channel = 133 (tempSensor)
  sendBuff[4] = (uint8)(0x00);  //Gain = 1 (Bip does not apply)  
  sendBuff[5] = (uint8)(0x0C);  //Resolution = 12
  sendBuff[6] = (uint8)(0x00);  //SettlingTime = 0
  sendBuff[7] = (uint8)(0x00);  //Reserved
  sendBuff[0] = normalChecksum8(sendBuff, 8);

  //Sending command to UE9
  sendChars = send(socketFD, sendBuff, 8, 0);
  if(sendChars < 8)
  {
    if(sendChars == -1)
      goto sendError0;
    else  
      goto sendError1;
  }

  //Receiving response from UE9
  recChars = recv(socketFD, recBuff, 8, 0);
  if(recChars < 8)
  {
    if(recChars == -1)
      goto recvError0;
    else  
      goto recvError1;
  }

  if((uint8)(normalChecksum8(recBuff, 8)) != recBuff[0])
    goto chksumError;

  if(recBuff[1] != (uint8)(0xA3))
    goto commandByteError;

  if(recBuff[2] != (uint8)(0x04))
    goto IOTypeError;

  if(recBuff[3] != (uint8)(0x85))
    goto channelError;

  bytesTemperature = recBuff[5] + recBuff[6] * 256;

  //assuming high power level
  if(binaryToCalibratedAnalogTemperature(caliInfo, 0, bytesTemperature, 
					 &temperature) < 0)
    return -1;

  *dblIntTemp = temperature;
  
  return 0;

//error printouts
sendError0:
  printf("Error : send failed\n");
  return -1;
sendError1:
  printf("Error : did not send all of the buffer\n");
  return -1;
recvError0:
  printf("Error : recv failed\n");
  return -1;
recvError1:  
  printf("Error : recv did not receive all of the buffer\n");
  return -1;
chksumError:
  printf("Error : received buffer has bad checksum\n");
  return -1;
commandByteError:
  printf("Error : received buffer has wrong command byte\n");
  return -1;
IOTypeError:  
  printf("Error : received buffer has wrong IOType\n");
  return -1;
channelError:  
  printf("Error : received buffer has wrong channel\n");
  return -1;

}
Beispiel #2
0
long eAIN(HANDLE Handle, 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(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(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;
}
Beispiel #3
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;

  if (isCalibrationInfoValid(CalibrationInfo) != 1)
  {
    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)
     || (hwver >= 1.30 && hv == 1 && ((ChannelP < 4 && ChannelN != 31)
                                       || ChannelN < 4)))
  {
    printf("eAIN error: Invalid negative channel\n");
    return -1;
  }

  if (hwver >= 1.30 && hv == 1 && ChannelP < 4) {}
  else if (ConfigIO != 0)
  {
    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 (Binary != 0)
  {
    *Voltage = (double)bytesVT;
  }
  else
  {
    if (ChannelP == 30)
    {
      if (binaryToCalibratedAnalogTemperature(CalibrationInfo, bytesVT, Voltage) < 0)
        return -1;
    }
    else
    {
      if (hwver < 1.30)
        error = binaryToCalibratedAnalogVoltage(CalibrationInfo, (int)(*DAC1Enable), ChannelN, bytesVT, Voltage);
      else
        error = binaryToCalibratedAnalogVoltage_hw130(CalibrationInfo, ChannelP, ChannelN, bytesVT, Voltage);
      if (error < 0)
        return -1;
    }
  }

  return 0;
}