Example #1
0
long eDO(HANDLE Handle, long Channel, long State)
{
    uint8 sendDataBuff[4];
    uint8 Errorcode, ErrorFrame;

    if(Channel < 0 || Channel > 19)
    {
        printf("eD0 error: Invalid Channel\n");
        return -1;
    }

    /* Setting up Feedback command to set digital Channel to output and to set the state */
    sendDataBuff[0] = 13;             //IOType is BitDirWrite
    sendDataBuff[1] = Channel + 128;  //IONumber(bits 0-4) + Direction (bit 7)

    sendDataBuff[2] = 11;             //IOType is BitStateWrite
    sendDataBuff[3] = Channel + 128*((State > 0) ? 1 : 0);  //IONumber(bits 0-4) + State (bit 7)

    if(ehFeedback(Handle, sendDataBuff, 4, &Errorcode, &ErrorFrame, NULL, 0) < 0)
        return -1;
    if(Errorcode)
        return (long)Errorcode;

    return 0;
}
Example #2
0
bool ljU6ConfigPorts(HANDLE Handle) {
    /// set up IO ports
    uint8 sendDataBuff[6]; // recDataBuff[1];
    uint8 Errorcode, ErrorFrame;
    
    // setup one to be output, one input, and set output to zero
    sendDataBuff[0] = 13;       //IOType is BitDirWrite
    sendDataBuff[1] = (LJU6_LEVERPRESS_FIO & 0x0f) | (0 << 7);  //IONumber(bits 0-4) + Direction (bit 7; 1 is output)
    sendDataBuff[2] = 13;       //IOType is BitDirWrite
    sendDataBuff[3] = LJU6_REWARD_FIO & 0x0f | (1 << 7);  //IONumber(bits 0-4) + Direction (bit 7; 1 is output)
    sendDataBuff[4] = 11;             //IOType is BitStateWrite
    sendDataBuff[5] = (LJU6_REWARD_FIO & 0x0f) | (0 << 7);  //IONumber(bits 0-4) + State (bit 7)
    
    
    //printf("*****************Output %x %x %x %x\n", sendDataBuff[0], sendDataBuff[1], sendDataBuff[2], sendDataBuff[3]);
    
    if(ehFeedback(Handle, sendDataBuff, 6, &Errorcode, &ErrorFrame, NULL, 0) < 0) {
        printf("bug: ehFeedback error, see stdout");  // note we will get a more informative error on stdout
        goto cleanup;
    }
    if(Errorcode) {
        printf("ehFeedback: error with command, errorcode was %d");
        goto cleanup;
    }
    
    return true;
    
cleanup:
    closeUSBConnection(Handle);
    return false;
}
Example #3
0
long eDI(HANDLE Handle, long Channel, long *State)
{
    uint8 sendDataBuff[4], recDataBuff[1];
    uint8 Errorcode, ErrorFrame;

    if(Channel < 0 || Channel > 19)
    {
        printf("eDI error: Invalid Channel.\n");
        return -1;
    }


    /* Setting up Feedback command to set digital Channel to input and to read from it */
    sendDataBuff[0] = 13;       //IOType is BitDirWrite
    sendDataBuff[1] = Channel;  //IONumber(bits 0-4) + Direction (bit 7)

    sendDataBuff[2] = 10;       //IOType is BitStateRead
    sendDataBuff[3] = Channel;  //IONumber

    if(ehFeedback(Handle, sendDataBuff, 4, &Errorcode, &ErrorFrame, recDataBuff, 1) < 0)
        return -1;
    if(Errorcode)
        return (long)Errorcode;

    *State = recDataBuff[0];
    return 0;
}
Example #4
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;
}
Example #5
0
long eDI(HANDLE Handle, long ConfigIO, long Channel, long *State)
{
  uint8 sendDataBuff[4], recDataBuff[1];
  uint8 Errorcode, ErrorFrame;
  uint8 FIOAnalog, EIOAnalog, curFIOAnalog, curEIOAnalog, curTCConfig;
  long error;


  if (Channel < 0 || Channel > 19)
  {
    printf("eDI error: Invalid DI channel\n");
    return -1;
  }

  if (ConfigIO != 0 && Channel <= 15)
  {
    FIOAnalog = 255;
    EIOAnalog = 255;

    //Setting Channel to digital using FIOAnalog and EIOAnalog
    if (Channel <= 7)
      FIOAnalog = 255 - pow(2, Channel);
    else
      EIOAnalog = 255 - pow(2, (Channel - 8));

    //Using ConfigIO to get current FIOAnalog and EIOAnalog settings
    error = ehConfigIO(Handle, 0, 0, 0, 0, 0, &curTCConfig, NULL, &curFIOAnalog, &curEIOAnalog);
    if (error != 0)
      return error;

    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
      error = ehConfigIO(Handle, 12, curTCConfig, 0, FIOAnalog, EIOAnalog, NULL, NULL, &curFIOAnalog, &curEIOAnalog);
      if (error != 0)
        return error;
    }
  }

  /* Setting up Feedback command to set digital Channel to input and to read from it */
  sendDataBuff[0] = 13;       //IOType is BitDirWrite
  sendDataBuff[1] = Channel;  //IONumber(bits 0-4) + Direction (bit 7)

  sendDataBuff[2] = 10;       //IOType is BitStateRead
  sendDataBuff[3] = Channel;  //IONumber

  if (ehFeedback(Handle, sendDataBuff, 4, &Errorcode, &ErrorFrame, recDataBuff, 1) < 0)
    return -1;
  if (Errorcode)
    return (long)Errorcode;

  *State = recDataBuff[0];
  return 0;
}
Example #6
0
long eDO(HANDLE Handle, long ConfigIO, long Channel, long State)
{
  uint8 sendDataBuff[4];
  uint8 Errorcode, ErrorFrame, FIOAnalog, EIOAnalog;
  uint8 curFIOAnalog, curEIOAnalog, curTCConfig;
  long error;


  if (Channel < 0 || Channel > 19)
  {
    printf("eD0 error: Invalid DI channel\n");
    return -1;
  }

  if (ConfigIO != 0 && Channel <= 15)
  {
    FIOAnalog = 255;
    EIOAnalog = 255;

    //Setting Channel to digital using FIOAnalog and EIOAnalog
    if (Channel <= 7)
      FIOAnalog = 255 - pow(2, Channel);
    else
      EIOAnalog = 255 - pow(2, (Channel - 8));

    //Using ConfigIO to get current FIOAnalog and EIOAnalog settings
    error = ehConfigIO(Handle, 0, 0, 0, 0, 0, &curTCConfig, NULL, &curFIOAnalog, &curEIOAnalog);
    if (error != 0)
      return error;

    if ( !(FIOAnalog == curFIOAnalog && EIOAnalog == curEIOAnalog))
    {
      //Using ConfigIO to get current FIOAnalog and EIOAnalog settings
      FIOAnalog = FIOAnalog & curFIOAnalog;
      EIOAnalog = EIOAnalog & curEIOAnalog;

      //Using ConfigIO to set new FIOAnalog and EIOAnalog settings
      error = ehConfigIO(Handle, 12, curTCConfig, 0, FIOAnalog, EIOAnalog, NULL, NULL, &curFIOAnalog, &curEIOAnalog);
      if (error != 0)
        return error;
    }
  }

  /* Setting up Feedback command to set digital Channel to output and to set the state */
  sendDataBuff[0] = 13;             //IOType is BitDirWrite
  sendDataBuff[1] = Channel + 128;  //IONumber(bits 0-4) + Direction (bit 7)

  sendDataBuff[2] = 11;             //IOType is BitStateWrite
  sendDataBuff[3] = Channel + 128*((State > 0) ? 1 : 0);  //IONumber(bits 0-4) + State (bit 7)

  if (ehFeedback(Handle, sendDataBuff, 4, &Errorcode, &ErrorFrame, NULL, 0) < 0)
    return -1;
  if (Errorcode)
    return (long)Errorcode;

  return 0;
}
Example #7
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;
}
Example #8
0
bool ljU6WriteDI(HANDLE Handle, long Channel, long State) {
    
    uint8 sendDataBuff[2]; // recDataBuff[1];
    uint8 Errorcode, ErrorFrame;
    
    sendDataBuff[0] = 11;             //IOType is BitStateWrite
    sendDataBuff[1] = Channel + 128*((State > 0) ? 1 : 0);  //IONumber(bits 0-4) + State (bit 7)
    
    if(ehFeedback(Handle, sendDataBuff, 2, &Errorcode, &ErrorFrame, NULL, 0) < 0) {
        printf("bug: ehFeedback error, see stdout");  // note we will get a more informative error on stdout
        goto cleanup;
    }
    if(Errorcode) {
        printf("ehFeedback: error with command, errorcode was %d");
        goto cleanup;
    }
    
    return true;
    
cleanup:
    // Should do this in destructor?
    //closeUSBConnection(ljHandle);  
    return false;    
}
Example #9
0
bool ljU6ReadDI(HANDLE Handle, long Channel, long* State) {
    // returns: 1 on success, 0 on error
    // output written to State
    
    uint8 sendDataBuff[4], recDataBuff[1];
    uint8 Errorcode, ErrorFrame;
    
    sendDataBuff[0] = 10;       //IOType is BitStateRead
    sendDataBuff[1] = Channel;  //IONumber
    
    printf("entering ljU6ReadDI\n"); fflush(stdout);
    if(ehFeedback(Handle, sendDataBuff, 2, &Errorcode, &ErrorFrame, recDataBuff, 1) < 0) {
        printf("bug: ehFeedback error, see stdout");  // note we will get a more informative error on stdout
        return 0;
    }
    if(Errorcode) {
        printf("ehFeedback: error with command, errorcode was %d");
        return 0;
    }
    
    *State = (long int)recDataBuff[0];
    return 1;
    
}
Example #10
0
long eTCValues(HANDLE Handle, long *aReadTimers, long *aUpdateResetTimers, long *aReadCounters, long *aResetCounters, double *aTimerValues, double *aCounterValues, long Reserved1, long Reserved2)
{
    uint8 sendDataBuff[20], recDataBuff[24];
    uint8 Errorcode, ErrorFrame;
    int sendDataBuffSize, recDataBuffSize, i, j;
    int numTimers, dataCountCounter, dataCountTimer;

    /* Feedback */
    numTimers = 0;
    dataCountCounter = 0;
    dataCountTimer = 0;
    sendDataBuffSize = 0;
    recDataBuffSize = 0;

    for(i = 0; i < 4; i++)
    {
        if(aReadTimers[i] != 0 || aUpdateResetTimers[i] != 0)
        {
            sendDataBuff[sendDataBuffSize] = 42 + i*2;                                          //Timer
            sendDataBuff[1 + sendDataBuffSize] = ((aUpdateResetTimers[i] != 0) ? 1 : 0);        //UpdateReset
            sendDataBuff[2 + sendDataBuffSize] = (uint8)(((long)aTimerValues[i])&0x00ff);       //Value LSB
            sendDataBuff[3 + sendDataBuffSize] = (uint8)((((long)aTimerValues[i])&0xff00)/256); //Value MSB
            sendDataBuffSize += 4;
            recDataBuffSize += 4;
            numTimers++;
        }
    }

    for(i = 0; i < 2; i++)
    {
        if(aReadCounters[i] != 0 || aResetCounters[i] != 0)
        {
            sendDataBuff[sendDataBuffSize] = 54 + i;                                 //Counter
            sendDataBuff[1 + sendDataBuffSize] = ((aResetCounters[i] != 0) ? 1 : 0); //Reset
            sendDataBuffSize += 2;
            recDataBuffSize += 4;
        }
    }

    if(ehFeedback(Handle, sendDataBuff, sendDataBuffSize, &Errorcode, &ErrorFrame, recDataBuff, recDataBuffSize) < 0)
        return -1;
    if(Errorcode)
        return (long)Errorcode;

    for(i = 0; i < 4; i++)
    {
        aTimerValues[i] = 0;
        if(aReadTimers[i] != 0)
        {
            for(j = 0; j < 4; j++)
                aTimerValues[i] += (double)((long)recDataBuff[j + dataCountTimer*4]*pow(2, 8*j));
        }
        if(aReadTimers[i] != 0 || aUpdateResetTimers[i] != 0)
            dataCountTimer++;

        if(i < 2)
        {
            aCounterValues[i] = 0;
            if(aReadCounters[i] != 0)
            {
                for(j = 0; j < 4; j++)
                    aCounterValues[i] += (double)((long)recDataBuff[j + numTimers*4 + dataCountCounter*4]*pow(2, 8*j));
            }
            if(aReadCounters[i] != 0 || aResetCounters[i] != 0)
                dataCountCounter++;
        }
    }

    return 0;
}
Example #11
0
long eTCConfig(HANDLE Handle, long *aEnableTimers, long *aEnableCounters, long TCPinOffset, long TimerClockBaseIndex, long TimerClockDivisor, long *aTimerModes, double *aTimerValues, long Reserved1, long Reserved2)
{
    uint8 sendDataBuff[20];
    uint8 numTimers, counters, cNumTimers, cCounters, cPinOffset, Errorcode, ErrorFrame;
    int sendDataBuffSize, i;
    long error;

    if(TCPinOffset < 0 && TCPinOffset > 8)
    {
        printf("eTCConfig error: Invalid TCPinOffset.\n");
        return -1;
    }

    /* ConfigTimerClock */
    if(TimerClockBaseIndex == LJ_tc4MHZ || TimerClockBaseIndex ==  LJ_tc12MHZ || TimerClockBaseIndex == LJ_tc48MHZ ||
        TimerClockBaseIndex == LJ_tc1MHZ_DIV || TimerClockBaseIndex == LJ_tc4MHZ_DIV || TimerClockBaseIndex == LJ_tc12MHZ_DIV ||
        TimerClockBaseIndex == LJ_tc48MHZ_DIV)
        TimerClockBaseIndex = TimerClockBaseIndex - 20;

    error = ehConfigTimerClock(Handle, (uint8)(TimerClockBaseIndex + 128), (uint8)TimerClockDivisor, NULL, NULL);
    if(error != 0)
        return error;

    numTimers = 0;
    counters = 0;

    for(i = 0; i < 4; i++)
    {
        if(aEnableTimers[i] != 0)
            numTimers++;
        else
            i = 999;
    }

    for(i = 0; i < 2; i++)
    {
        if(aEnableCounters[i] != 0)
        {
            counters += pow(2, i);
        }
    }

    error = ehConfigIO(Handle, 1, numTimers, counters, TCPinOffset, &cNumTimers, &cCounters, &cPinOffset);
    if(error != 0)
        return error;

    if(numTimers > 0)
    {
        /* Feedback */
        for(i = 0; i < 8; i++)
            sendDataBuff[i] = 0;

        for(i = 0; i < numTimers; i++)
        {
            sendDataBuff[i*4] = 43 + i*2;                                         //TimerConfig
            sendDataBuff[1 + i*4] = (uint8)aTimerModes[i];                        //TimerMode
            sendDataBuff[2 + i*4] = (uint8)(((long)aTimerValues[i])&0x00ff);        //Value LSB
            sendDataBuff[3 + i*4] = (uint8)((((long)aTimerValues[i])&0xff00)/256);  //Value MSB
        }

        sendDataBuffSize = 4*numTimers;

        if(ehFeedback(Handle, sendDataBuff, sendDataBuffSize, &Errorcode, &ErrorFrame, NULL, 0) < 0)
            return -1;
        if(Errorcode)
            return (long)Errorcode;
    }

    return 0;
}
Example #12
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;
}
Example #13
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;
}
Example #14
0
long eTCConfig(HANDLE Handle, long *aEnableTimers, long *aEnableCounters, long TCPinOffset, long TimerClockBaseIndex, long TimerClockDivisor, long *aTimerModes, double *aTimerValues, long Reserved1, long Reserved2)
{
    uint8 sendDataBuff[8];
    uint8 FIOAnalog, EIOAnalog, curFIOAnalog, curEIOAnalog;
    uint8 TimerCounterConfig, curTimerCounterConfig, Errorcode, ErrorFrame;
    int sendDataBuffSize, numTimers, numCounters, i;
    long error;

    if(TCPinOffset < 0 && TCPinOffset > 8)
    {
        printf("eTCConfig error: Invalid TimerCounterPinOffset\n");
        return -1;
    }

    /* ConfigTimerClock */
    if(TimerClockBaseIndex == LJ_tc2MHZ || TimerClockBaseIndex ==  LJ_tc6MHZ || TimerClockBaseIndex == LJ_tc24MHZ ||
       TimerClockBaseIndex == LJ_tc500KHZ_DIV || TimerClockBaseIndex == LJ_tc2MHZ_DIV || TimerClockBaseIndex == LJ_tc6MHZ_DIV ||
       TimerClockBaseIndex == LJ_tc24MHZ_DIV)
    {
        TimerClockBaseIndex = TimerClockBaseIndex - 10;
    }
    else if(TimerClockBaseIndex == LJ_tc4MHZ || TimerClockBaseIndex ==  LJ_tc12MHZ || TimerClockBaseIndex == LJ_tc48MHZ ||
            TimerClockBaseIndex == LJ_tc1MHZ_DIV || TimerClockBaseIndex == LJ_tc4MHZ_DIV || TimerClockBaseIndex == LJ_tc12MHZ_DIV ||
            TimerClockBaseIndex == LJ_tc48MHZ_DIV)
    {
        TimerClockBaseIndex = TimerClockBaseIndex - 20;
    }

    error = ehConfigTimerClock(Handle, (uint8)(TimerClockBaseIndex + 128), (uint8)TimerClockDivisor, NULL, NULL);
    if(error != 0)
        return error;

    //Using ConfigIO to get current FIOAnalog and curEIOAnalog settings
    error = ehConfigIO(Handle, 0, 0, 0, 0, 0, NULL, NULL, &curFIOAnalog, &curEIOAnalog);
    if(error != 0)
        return error;

    numTimers = 0;
    numCounters = 0;
    TimerCounterConfig = 0;
    FIOAnalog = 255;
    EIOAnalog = 255;

    for(i = 0; i < 2; i++)
    {
        if(aEnableTimers[i] != 0)
            numTimers++;
        else
            i = 999;
    }

    for(i = 0; i < 2; i++)
    {
        if(aEnableCounters[i] != 0)
        {
            numCounters++;
            TimerCounterConfig += pow(2, (i+2));
        }
    }

    TimerCounterConfig += numTimers + TCPinOffset*16;

    for(i = 0; i < numCounters + numTimers; i++)
    {
        if(i + TCPinOffset < 8)
            FIOAnalog = FIOAnalog - pow(2, i + TCPinOffset);
        else
            EIOAnalog = EIOAnalog - pow(2, (i + TCPinOffset - 8));
    }

    FIOAnalog = FIOAnalog & curFIOAnalog;
    EIOAnalog = EIOAnalog & curEIOAnalog;
    error = ehConfigIO(Handle, 13, TimerCounterConfig, 0, FIOAnalog, EIOAnalog, &curTimerCounterConfig, NULL, &curFIOAnalog, &curEIOAnalog);
    if(error != 0)
        return error;

    if(numTimers > 0)
    {
        /* Feedback */
        for(i = 0; i < 8; i++)
            sendDataBuff[i] = 0;

        for(i = 0; i < numTimers; i++)
        {
            sendDataBuff[i*4] = 43 + i*2;  //TimerConfig
            sendDataBuff[1 + i*4] = (uint8)aTimerModes[i];  //TimerMode
            sendDataBuff[2 + i*4] = (uint8)(((long)aTimerValues[i])&0x00ff);  //Value LSB
            sendDataBuff[3 + i*4] = (uint8)((((long)aTimerValues[i])&0xff00)/256);  //Value MSB
        }

        sendDataBuffSize = 4*numTimers;

        if(ehFeedback(Handle, sendDataBuff, sendDataBuffSize, &Errorcode, &ErrorFrame, NULL, 0) < 0)
            return -1;
        if(Errorcode)
            return (long)Errorcode;
    }

    return 0;
}