Exemple #1
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;
}
Exemple #2
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;
}
Exemple #3
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;
}
Exemple #4
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;
}
Exemple #5
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;
}
Exemple #6
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;
}