Ejemplo n.º 1
0
void resetU6(uint8 res){
/*
  Resets U3
*/
  uint8 resetIn[4], resetOut[4];
  long int ii=0, error=0;

  for (ii=0; ii<4; ii++){
    resetIn[ii]=0;
    resetOut[ii]=0;
  }
  resetIn[1] = 0x99;
  resetIn[2] = res;
  resetIn[3] = 0x00;
  resetIn[0] = normalChecksum8(resetIn,4);

  if( (error = LJUSB_BulkWrite(hU6, U6_PIPE_EP1_OUT, resetIn, 4)) < 4){
    LJUSB_BulkRead(hU6, U6_PIPE_EP2_IN, resetOut, 4); 
    printf("U6 Reset error: %s\n", errormsg[(int)resetOut[3]]);
    closeUSBConnection(hU6);
    return;
  }
  printf ("....U6 device reset \n");
  return;
}
Ejemplo n.º 2
0
static void LJUSB_U3_FirmwareHardwareVersion(HANDLE hDevice, struct LJUSB_FirmwareHardwareVersion * fhv)
{
    unsigned long i = 0, r = 0;
    unsigned long epOut = U3_PIPE_EP1_OUT, epIn = U3_PIPE_EP2_IN;
    const unsigned long COMMAND_LENGTH = 26;
    const unsigned long RESPONSE_LENGTH = 38;
    BYTE command[COMMAND_LENGTH];
    BYTE response[RESPONSE_LENGTH];

    for (i = 0; i < COMMAND_LENGTH; i++) {
        command[i] = 0;
    }
    for (i = 0; i < RESPONSE_LENGTH; i++) {
        response[i] = 0;
    }

    //Checking firmware for U3.  Using ConfigU3 Low-level command
    command[0] = 11;
    command[1] = (BYTE)(0xF8);
    command[2] = (BYTE)(0x0A);
    command[3] = (BYTE)(0x08);

    LJUSB_BulkWrite(hDevice, epOut, command, COMMAND_LENGTH);

    if ((r = LJUSB_BulkRead(hDevice, epIn, response, RESPONSE_LENGTH)) < RESPONSE_LENGTH) {
        fprintf(stderr, "ConfigU3 response failed when getting firmware and hardware versions\n");
        fprintf(stderr, "Response was:\n");
        for (i = 0; i < r; i++) {
            fprintf(stderr, "%d ", response[i]);
        }
        fprintf(stderr, "\n");
        return;
    }

    if (response[1] != command[1] || response[2] != (BYTE)(0x10) || response[3] != command[3]) {
        fprintf(stderr, "Invalid ConfigU3 command bytes when getting firmware and hardware versions\n");
        fprintf(stderr, "Response was:\n");
        for (i = 0; i < r; i++) {
            fprintf(stderr, "%d ", response[i]);
        }
        fprintf(stderr, "\n");
        return;
    }

    fhv->firmwareMajor = response[10];
    fhv->firmwareMinor = response[9];
    fhv->hardwareMajor = response[14];
    fhv->hardwareMinor = response[13];

    return;
}
Ejemplo n.º 3
0
static void LJUSB_UE9_FirmwareHardwareVersion(HANDLE hDevice, struct LJUSB_FirmwareHardwareVersion * fhv)
{
    unsigned long i = 0, r = 0;
    unsigned long epOut = UE9_PIPE_EP1_OUT, epIn = UE9_PIPE_EP1_IN;
    const unsigned long COMMAND_LENGTH = 38;
    const unsigned long RESPONSE_LENGTH = 38;
    BYTE command[COMMAND_LENGTH];
    BYTE response[RESPONSE_LENGTH];

    for (i = 0; i < COMMAND_LENGTH; i++) {
        command[i] = 0;
    }
    for (i = 0; i < RESPONSE_LENGTH; i++) {
        response[i] = 0;
    }

    //Checking firmware for UE9.  Using CommConfig Low-level command
    command[0] = 137;
    command[1] = (BYTE)(0x78);
    command[2] = (BYTE)(0x10);
    command[3] = (BYTE)(0x01);

    LJUSB_BulkWrite(hDevice, epOut, command, COMMAND_LENGTH);

    if ((r = LJUSB_BulkRead(hDevice, epIn, response, RESPONSE_LENGTH)) < RESPONSE_LENGTH) {
        fprintf(stderr, "CommConfig response failed when getting firmware and hardware versions\n");
        fprintf(stderr, "Response was:\n");
        for (i = 0; i < r; i++) {
            fprintf(stderr, "%d ", response[i]);
        }
        fprintf(stderr, "\n");
        return;
    }

    if (response[1] != command[1] || response[2] != command[2] || response[3] != command[3]) {
        fprintf(stderr, "Invalid CommConfig command bytes when getting firmware and hardware versions\n");
        fprintf(stderr, "Response was:\n");
        for (i = 0; i < r; i++) {
            fprintf(stderr, "%d ", response[i]);
        }
        fprintf(stderr, "\n");
        return;
    }

    fhv->firmwareMajor = response[37];
    fhv->firmwareMinor = response[36];
    /* TODO: Add hardware major and minor */

    return;
}
Ejemplo n.º 4
0
long ehConfigIO(HANDLE hDevice, uint8 inWriteMask, uint8 inNumberTimersEnabled, uint8 inCounterEnable, uint8 inPinOffset, uint8 *outNumberTimersEnabled, uint8 *outCounterEnable, uint8 *outPinOffset)
{
    uint8 sendBuff[16], recBuff[16];
    uint16 checksumTotal;
    int sendChars, recChars, i;

    sendBuff[1] = (uint8)(0xF8);  //Command byte
    sendBuff[2] = (uint8)(0x05);  //Number of data words
    sendBuff[3] = (uint8)(0x0B);  //Extended command number

    sendBuff[6] = inWriteMask;  //Writemask

    sendBuff[7] = inNumberTimersEnabled;
    sendBuff[8] = inCounterEnable;
    sendBuff[9] = inPinOffset;

    for(i = 10; i < 16; i++)
        sendBuff[i] = 0;

    extendedChecksum(sendBuff, 16);

    //Sending command to U6
    if( (sendChars = LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuff, 16)) < 16)
    {
        if(sendChars == 0)
            printf("ehConfigIO error : write failed\n");
        else
            printf("ehConfigIO error : did not write all of the buffer\n");
        return -1;
    }

    //Reading response from U6
    if( (recChars = LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuff, 16)) < 16)
    {
        if(recChars == 0)
            printf("ehConfigIO error : read failed\n");
        else
            printf("ehConfigIO error : did not read all of the buffer\n");
        return -1;
    }

    checksumTotal = extendedChecksum16(recBuff, 16);
    if( (uint8)((checksumTotal / 256 ) & 0xff) != recBuff[5])
    {
        printf("ehConfigIO error : read buffer has bad checksum16(MSB)\n");
        return -1;
    }

    if( (uint8)(checksumTotal & 0xff) != recBuff[4])
    {
        printf("ehConfigIO error : read buffer has bad checksum16(LBS)\n");
        return -1;
    }

    if( extendedChecksum8(recBuff) != recBuff[0])
    {
        printf("ehConfigIO error : read buffer has bad checksum8\n");
        return -1;
    }

    if( recBuff[1] != (uint8)(0xF8) || recBuff[2] != (uint8)(0x05) || recBuff[3] != (uint8)(0x0B) )
    {
        printf("ehConfigIO error : read buffer has wrong command bytes\n");
        return -1;
    }

    if( recBuff[6] != 0)
    {
        printf("ehConfigIO error : read buffer received errorcode %d\n", recBuff[6]);
        return (int)recBuff[6];
    }

    if(outNumberTimersEnabled != NULL)
        *outNumberTimersEnabled = recBuff[7];
    if(outCounterEnable != NULL)
        *outCounterEnable = recBuff[8];
    if(outPinOffset != NULL)
        *outPinOffset = recBuff[9];

    return 0;
}
Ejemplo n.º 5
0
long I2C(HANDLE hDevice, uint8 I2COptions, uint8 SpeedAdjust, uint8 SDAPinNum, uint8 SCLPinNum, uint8 Address, uint8 NumI2CBytesToSend, uint8 NumI2CBytesToReceive, uint8 *I2CBytesCommand, uint8 *Errorcode, uint8 *AckArray, uint8 *I2CBytesResponse)
{
    uint8 *sendBuff, *recBuff;
    int sendChars, recChars, sendSize, recSize, i, ret;
    uint16 checksumTotal = 0;
    uint32 ackArrayTotal, expectedAckArray;

    *Errorcode = 0;
    ret = 0;
    sendSize = 6 + 8 + ((NumI2CBytesToSend%2 != 0)?(NumI2CBytesToSend + 1):(NumI2CBytesToSend));
    recSize = 6 + 6 + ((NumI2CBytesToReceive%2 != 0)?(NumI2CBytesToReceive + 1):(NumI2CBytesToReceive));

    sendBuff = malloc(sizeof(uint8)*sendSize);
    recBuff = malloc(sizeof(uint8)*recSize);

    sendBuff[sendSize - 1] = 0;

    //I2C command
    sendBuff[1] = (uint8)(0xF8);          //command byte
    sendBuff[2] = (sendSize - 6)/2;       //number of data words = 4 + NumI2CBytesToSend
    sendBuff[3] = (uint8)(0x3B);          //extended command number

    sendBuff[6] = I2COptions;             //I2COptions
    sendBuff[7] = SpeedAdjust;            //SpeedAdjust
    sendBuff[8] = SDAPinNum;              //SDAPinNum
    sendBuff[9] = SCLPinNum;              //SCLPinNum
    sendBuff[10] = Address;               //Address
    sendBuff[11] = 0;                     //Reserved
    sendBuff[12] = NumI2CBytesToSend;     //NumI2CByteToSend
    sendBuff[13] = NumI2CBytesToReceive;  //NumI2CBytesToReceive

    for(i = 0; i < NumI2CBytesToSend; i++)
        sendBuff[14 + i] = I2CBytesCommand[i];  //I2CByte

    extendedChecksum(sendBuff, sendSize);

    //Sending command to U6
    sendChars = LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuff, sendSize);
    if(sendChars < sendSize)
    {
        if(sendChars == 0)
            printf("I2C Error : write failed\n");
        else
            printf("I2C Error : did not write all of the buffer\n");
        ret = -1;
        goto cleanmem;
    }

    //Reading response from U6
    recChars = LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuff, recSize);
    if(recChars < recSize)
    {
        if(recChars == 0)
            printf("I2C Error : read failed\n");
        else
        {
            printf("I2C Error : did not read all of the buffer\n");
            if(recChars >= 12)
                *Errorcode = recBuff[6];
        }
        ret = -1;
        goto cleanmem;
    }

    *Errorcode = recBuff[6];

    AckArray[0] = recBuff[8];
    AckArray[1] = recBuff[9];
    AckArray[2] = recBuff[10];
    AckArray[3] = recBuff[11];

    for(i = 0; i < NumI2CBytesToReceive; i++)
        I2CBytesResponse[i] = recBuff[12 + i];

    if((uint8)(extendedChecksum8(recBuff)) != recBuff[0])
    {
        printf("I2C Error : read buffer has bad checksum (%d)\n", recBuff[0]);
        ret = -1;
    }

    if(recBuff[1] != (uint8)(0xF8))
    {
        printf("I2C Error : read buffer has incorrect command byte (%d)\n", recBuff[1]);
        ret = -1;
    }

    if(recBuff[2] != (uint8)((recSize - 6)/2))
    {
        printf("I2C Error : read buffer has incorrect number of data words (%d)\n", recBuff[2]);
        ret = -1;
    }

    if(recBuff[3] != (uint8)(0x3B))
    {
        printf("I2C Error : read buffer has incorrect extended command number (%d)\n", recBuff[3]);
        ret = -1;
    }

    checksumTotal = extendedChecksum16(recBuff, recSize);
    if( (uint8)((checksumTotal / 256) & 0xff) != recBuff[5] || (uint8)(checksumTotal & 255) != recBuff[4])
    {
        printf("I2C error : read buffer has bad checksum16 (%d)\n", checksumTotal);
        ret = -1;
    }

    //ackArray should ack the Address byte in the first ack bit
    ackArrayTotal = AckArray[0] + AckArray[1]*256 + AckArray[2]*65536 + AckArray[3]*16777216;
    expectedAckArray = pow(2.0,  NumI2CBytesToSend+1)-1;
    if(ackArrayTotal != expectedAckArray)
        printf("I2C error : expected an ack of %d, but received %d\n", expectedAckArray, ackArrayTotal);

cleanmem:
    free(sendBuff);
    free(recBuff);
    sendBuff = NULL;
    recBuff = NULL;

    return ret;
}
Ejemplo n.º 6
0
long getCalibrationInfo(HANDLE hDevice, u6CalibrationInfo *caliInfo)
{
    uint8 sendBuffer[64], recBuffer[64];
    int sentRec = 0;
    int i = 0;
    int offset = 0;

    /* sending ConfigU6 command to get see if hi res */
    sendBuffer[1] = (uint8)(0xF8);  //command byte
    sendBuffer[2] = (uint8)(0x0A);  //number of data words
    sendBuffer[3] = (uint8)(0x08);  //extended command number

    //setting WriteMask0 and all other bytes to 0 since we only want to read the response
    for(i = 6; i < 26; i++)
        sendBuffer[i] = 0;

    extendedChecksum(sendBuffer, 26);

    sentRec = LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuffer, 26);
    if(sentRec < 26)
    {
        if(sentRec == 0)
            goto writeError0;
        else
            goto writeError1;
    }

    sentRec = LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuffer, 38);
    if(sentRec < 38)
    {
        if(sentRec == 0)
            goto readError0;
        else
            goto readError1;
    }

    if(recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x10) || recBuffer[3] != (uint8)(0x08))
        goto commandByteError;

    caliInfo->hiRes  = (((recBuffer[37]&8) == 8)?1:0);

    for(i = 0; i < 10; i++)
    {
        /* reading block i from memory */
        sendBuffer[1] = (uint8)(0xF8);  //command byte
        sendBuffer[2] = (uint8)(0x01);  //number of data words
        sendBuffer[3] = (uint8)(0x2D);  //extended command number
        sendBuffer[6] = 0;
        sendBuffer[7] = (uint8)i;       //Blocknum = i
        extendedChecksum(sendBuffer, 8);

        sentRec = LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuffer, 8);
        if(sentRec < 8)
        {
            if(sentRec == 0)
                goto writeError0;
            else
                goto writeError1;
        }

        sentRec = LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuffer, 40);
        if(sentRec < 40)
        {
            if(sentRec == 0)
                goto readError0;
            else
                goto readError1;
        }

        if(recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x11) || recBuffer[3] != (uint8)(0x2D))
            goto commandByteError;

        offset = i*4;

        //block data starts on byte 8 of the buffer
        caliInfo->ccConstants[offset] = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
        caliInfo->ccConstants[offset + 1] = FPuint8ArrayToFPDouble(recBuffer + 8, 8);
        caliInfo->ccConstants[offset + 2] = FPuint8ArrayToFPDouble(recBuffer + 8, 16);
        caliInfo->ccConstants[offset + 3] = FPuint8ArrayToFPDouble(recBuffer + 8, 24);
    }

    caliInfo->prodID = 6;

    return 0;

writeError0:
    printf("Error : getCalibrationInfo write failed\n");
    return -1;

writeError1:
    printf("Error : getCalibrationInfo did not write all of the buffer\n");
    return -1;

readError0:
    printf("Error : getCalibrationInfo read failed\n");
    return -1;

readError1:
    printf("Error : getCalibrationInfo did not read all of the buffer\n");
    return -1;

commandByteError:
    printf("Error : getCalibrationInfo received wrong command bytes for ReadMem\n");
    return -1;
}
Ejemplo n.º 7
0
HANDLE openUSBConnection(int localID)
{
    BYTE sendBuffer[26], recBuffer[38];
    uint16 checksumTotal = 0;
    HANDLE hDevice = 0;
    uint32 numDevices = 0;
    uint32 dev;
    int i;

    numDevices = LJUSB_GetDevCount(U6_PRODUCT_ID);
    if(numDevices == 0)
    {
        printf("Open error: No U6 devices could be found\n");
        return NULL;
    }

    for(dev = 1;  dev <= numDevices; dev++)
    {
        hDevice = LJUSB_OpenDevice(dev, 0, U6_PRODUCT_ID);
        if(hDevice != NULL)
        {
            if(localID < 0)
            {
                return hDevice;
            }
            else
            {
                checksumTotal = 0;

                //setting up a U6Config
                sendBuffer[1] = (uint8)(0xF8);
                sendBuffer[2] = (uint8)(0x0A);
                sendBuffer[3] = (uint8)(0x08);

                for(i = 6; i < 26; i++)
                    sendBuffer[i] = (uint8)(0x00);

                extendedChecksum(sendBuffer, 26);

                if(LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuffer, 26) != 26)
                    goto locid_error;

                if(LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuffer, 38) != 38)
                    goto locid_error;

                checksumTotal = extendedChecksum16(recBuffer, 38);
                if( (uint8)((checksumTotal / 256) & 0xff) != recBuffer[5])
                    goto locid_error;

                if( (uint8)(checksumTotal & 0xff) != recBuffer[4])
                    goto locid_error;

                if( extendedChecksum8(recBuffer) != recBuffer[0])
                    goto locid_error;

                if( recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x10) ||
                    recBuffer[3] != (uint8)(0x08) )
                    goto locid_error;

                if( recBuffer[6] != 0)
                    goto locid_error;

                if( (int)recBuffer[21] == localID)
                    return hDevice;
                else
                    LJUSB_CloseDevice(hDevice);
            } //else localID >= 0 end
        } //if hDevice != NULL end
    } //for end

    printf("Open error: could not find a U6 with a local ID of %d\n", localID);
    return NULL;

locid_error:
    printf("Open error: problem when checking local ID\n");
    return NULL;
}
Ejemplo n.º 8
0
long ehFeedback(HANDLE hDevice, uint8 *inIOTypesDataBuff, long inIOTypesDataSize, uint8 *outErrorcode, uint8 *outErrorFrame, uint8 *outDataBuff, long outDataSize)
{
    uint8 *sendBuff, *recBuff;
    uint16 checksumTotal;
    int sendChars, recChars, i, sendDWSize, recDWSize, commandBytes, ret;

    ret = 0;
    commandBytes = 6;

    if(((sendDWSize = inIOTypesDataSize + 1)%2) != 0)
        sendDWSize++;
    if(((recDWSize = outDataSize + 3)%2) != 0)
        recDWSize++;

    sendBuff = malloc(sizeof(uint8)*(commandBytes + sendDWSize));
    recBuff = malloc(sizeof(uint8)*(commandBytes + recDWSize));

    if(sendBuff == NULL || recBuff == NULL)
    {
        ret = -1;
        goto cleanmem;
    }

    sendBuff[sendDWSize + commandBytes - 1] = 0;

    /* Setting up Feedback command */
    sendBuff[1] = (uint8)(0xF8);  //Command byte
    sendBuff[2] = sendDWSize/2;   //Number of data words (.5 word for echo, 1.5
                                   //words for IOTypes)
    sendBuff[3] = (uint8)(0x00);  //Extended command number

    sendBuff[6] = 0;    //Echo

    for(i = 0; i < inIOTypesDataSize; i++)
        sendBuff[i+commandBytes+1] = inIOTypesDataBuff[i];

    extendedChecksum(sendBuff, (sendDWSize+commandBytes));

    //Sending command to U6
    if( (sendChars = LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuff, (sendDWSize+commandBytes))) < sendDWSize+commandBytes)
    {
        if(sendChars == 0)
            printf("ehFeedback error : write failed\n");
        else
            printf("ehFeedback error : did not write all of the buffer\n");
        ret = -1;
        goto cleanmem;
    }

    //Reading response from U6
    if( (recChars = LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuff, (commandBytes+recDWSize))) < commandBytes+recDWSize)
    {
        if(recChars == -1)
        {
            printf("ehFeedback error : read failed\n");
            ret = -1;
            goto cleanmem;
        }
        else if(recChars < 8)
        {
            printf("ehFeedback error : response buffer is too small\n");
            for(i = 0; i < recChars; i++)
                printf("%d ", recBuff[i]);
            ret = -1;
            goto cleanmem;
        }
        else
            printf("ehFeedback error : did not read all of the expected buffer (received %d, expected %d )\n", recChars, commandBytes+recDWSize);
    }

    checksumTotal = extendedChecksum16(recBuff, recChars);
    if( (uint8)((checksumTotal / 256 ) & 0xff) != recBuff[5])
    {
        printf("ehFeedback error : read buffer has bad checksum16(MSB)\n");
        ret = -1;
        goto cleanmem;
    }

    if( (uint8)(checksumTotal & 0xff) != recBuff[4])
    {
        printf("ehFeedback error : read buffer has bad checksum16(LBS)\n");
        ret = -1;
        goto cleanmem;
    }

    if( extendedChecksum8(recBuff) != recBuff[0])
    {
        printf("ehFeedback error : read buffer has bad checksum8\n");
        ret = -1;
        goto cleanmem;
    }

    if( recBuff[1] != (uint8)(0xF8) || recBuff[3] != (uint8)(0x00) )
    {
        printf("ehFeedback error : read buffer has wrong command bytes \n");
        ret = -1;
        goto cleanmem;
    }

    *outErrorcode = recBuff[6];
    *outErrorFrame = recBuff[7];

    for(i = 0; i+commandBytes+3 < recChars && i < outDataSize; i++)
        outDataBuff[i] = recBuff[i+commandBytes+3];

cleanmem:
    free(sendBuff);
    free(recBuff);
    sendBuff = NULL;
    recBuff = NULL;

    return ret;
}
Ejemplo n.º 9
0
long ehConfigTimerClock(HANDLE hDevice, uint8 inTimerClockConfig, uint8 inTimerClockDivisor, uint8 *outTimerClockConfig, uint8 *outTimerClockDivisor)
{
    uint8 sendBuff[10], recBuff[10];
    uint16 checksumTotal;
    int sendChars, recChars;

    sendBuff[1] = (uint8)(0xF8);  //Command byte
    sendBuff[2] = (uint8)(0x02);  //Number of data words
    sendBuff[3] = (uint8)(0x0A);  //Extended command number

    sendBuff[6] = 0;   //Reserved
    sendBuff[7] = 0;   //Reserved

    sendBuff[8] = inTimerClockConfig;   //TimerClockConfig
    sendBuff[9] = inTimerClockDivisor;  //TimerClockDivisor
    extendedChecksum(sendBuff, 10);

    //Sending command to U6
    if( (sendChars = LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuff, 10)) < 10)
    {
        if(sendChars == 0)
            printf("ehConfigTimerClock error : write failed\n");
        else
            printf("ehConfigTimerClock error : did not write all of the buffer\n");
        return -1;
    }

    //Reading response from U6
    if( (recChars = LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuff, 10)) < 10)
    {
        if(recChars == 0)
            printf("ehConfigTimerClock error : read failed\n");
        else
            printf("ehConfigTimerClock error : did not read all of the buffer\n");
        return -1;
    }

    checksumTotal = extendedChecksum16(recBuff, 10);
    if( (uint8)((checksumTotal / 256 ) & 0xff) != recBuff[5])
    {
        printf("ehConfigTimerClock error : read buffer has bad checksum16(MSB)\n");
        return -1;
    }

    if( (uint8)(checksumTotal & 0xff) != recBuff[4])
    {
        printf("ehConfigTimerClock error : read buffer has bad checksum16(LBS)\n");
        return -1;
    }

    if( extendedChecksum8(recBuff) != recBuff[0])
    {
        printf("ehConfigTimerClock error : read buffer has bad checksum8\n");
        return -1;
    }

    if( recBuff[1] != (uint8)(0xF8) || recBuff[2] != (uint8)(0x02) || recBuff[3] != (uint8)(0x0A) )
    {
        printf("ehConfigTimerClock error : read buffer has wrong command bytes\n");
        return -1;
    }

    if(outTimerClockConfig != NULL)
        *outTimerClockConfig = recBuff[8];

    if(outTimerClockDivisor != NULL)
        *outTimerClockDivisor = recBuff[9];

    if( recBuff[6] != 0)
    {
        printf("ehConfigTimerClock error : read buffer received errorcode %d\n", recBuff[6]);
        return recBuff[6];
    }

    return 0;
}
Ejemplo n.º 10
0
long getCalibrationInfo(HANDLE hDevice, ue9CalibrationInfo *caliInfo)
{
  uint8 sendBuffer[8];
  uint8 recBuffer[136];
  int sentRec = 0;

  /* reading block 0 from memory */
  sendBuffer[1] = (uint8)(0xF8);  //command byte
  sendBuffer[2] = (uint8)(0x01);  //number of data words
  sendBuffer[3] = (uint8)(0x2A);  //extended command number
  sendBuffer[6] = (uint8)(0x00);
  sendBuffer[7] = (uint8)(0x00);  //Blocknum = 0
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuffer, 8);
  if(sentRec < 8)
  {
    if(sentRec == 0)
      goto writeError0;
    else  
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuffer, 136);
  if(sentRec < 136)
  {
    if(sentRec == 0)
      goto readError0;
    else  
      goto readError1;
  }

  if(recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x41) || recBuffer[3] != (uint8)(0x2A))
    goto commandByteError;

  //block data starts on byte 8 of the buffer
  caliInfo->unipolarSlope[0] = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->unipolarOffset[0] = FPuint8ArrayToFPDouble(recBuffer + 8, 8);
  caliInfo->unipolarSlope[1] = FPuint8ArrayToFPDouble(recBuffer + 8, 16);
  caliInfo->unipolarOffset[1] = FPuint8ArrayToFPDouble(recBuffer + 8, 24);
  caliInfo->unipolarSlope[2] = FPuint8ArrayToFPDouble(recBuffer + 8, 32);
  caliInfo->unipolarOffset[2] = FPuint8ArrayToFPDouble(recBuffer + 8, 40);
  caliInfo->unipolarSlope[3] = FPuint8ArrayToFPDouble(recBuffer + 8, 48);
  caliInfo->unipolarOffset[3] = FPuint8ArrayToFPDouble(recBuffer + 8, 56);

  /* reading block 1 from memory */
  sendBuffer[7] = (uint8)(0x01);    //Blocknum = 1
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuffer, 8);
  if(sentRec < 8)
  {
    if(sentRec == 0)
      goto writeError0;
    else  
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuffer, 136);
  if(sentRec < 136)
  {
    if(sentRec == 0)
      goto readError0;
    else  
      goto readError1;
  }

  if(recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x41) || recBuffer[3] != (uint8)(0x2A))
  {
    goto commandByteError;
  }

  caliInfo->bipolarSlope = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->bipolarOffset = FPuint8ArrayToFPDouble(recBuffer + 8, 8);

  /* reading block 2 from memory */
  sendBuffer[7] = (uint8)(0x02);    //Blocknum = 2
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuffer, 8);
  if(sentRec < 8)
  {
    if(sentRec == 0)
      goto writeError0;
    else  
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuffer, 136);
  if(sentRec < 136)
  {
    if(sentRec == 0)
      goto readError0;
    else  
      goto readError1;
  }

  if(recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x41) || recBuffer[3] != (uint8)(0x2A))
  {
    goto commandByteError;
  }

  caliInfo->DACSlope[0] = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->DACOffset[0] = FPuint8ArrayToFPDouble(recBuffer + 8, 8);
  caliInfo->DACSlope[1] = FPuint8ArrayToFPDouble(recBuffer + 8, 16);
  caliInfo->DACOffset[1] = FPuint8ArrayToFPDouble(recBuffer + 8, 24);
  caliInfo->tempSlope = FPuint8ArrayToFPDouble(recBuffer + 8, 32);
  caliInfo->tempSlopeLow = FPuint8ArrayToFPDouble(recBuffer + 8, 48);
  caliInfo->calTemp = FPuint8ArrayToFPDouble(recBuffer + 8, 64);
  caliInfo->Vref = FPuint8ArrayToFPDouble(recBuffer + 8, 72);
  caliInfo->VrefDiv2 = FPuint8ArrayToFPDouble(recBuffer + 8, 88);
  caliInfo->VsSlope = FPuint8ArrayToFPDouble(recBuffer + 8, 96);

  /* reading block 3 from memory */
  sendBuffer[7] = (uint8)(0x03);    //Blocknum = 3
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuffer, 8);
  if(sentRec < 8)
  {
    if(sentRec == -1)
      goto writeError0;
    else  
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuffer, 136);
  if(sentRec < 136)
  {
    if(sentRec == -1)
      goto readError0;
    else  
      goto readError1;
  }

  if(recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x41) || recBuffer[3] != (uint8)(0x2A))
    goto commandByteError;

  //block data starts on byte 8 of the buffer
  caliInfo->hiResUnipolarSlope = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->hiResUnipolarOffset = FPuint8ArrayToFPDouble(recBuffer + 8, 8);

  /* reading block 4 from memory */
  sendBuffer[7] = (uint8)(0x04);    //Blocknum = 4
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuffer, 8);
  if(sentRec < 8)
  {
    if(sentRec == -1)
      goto writeError0;
    else  
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuffer, 136);
  if(sentRec < 136)
  {
    if(sentRec == -1)
      goto readError0;
    else  
      goto readError1;
  }

  if(recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x41) || recBuffer[3] != (uint8)(0x2A))
    goto commandByteError;

  //block data starts on byte 8 of the buffer
  caliInfo->hiResBipolarSlope = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->hiResBipolarOffset = FPuint8ArrayToFPDouble(recBuffer + 8, 8);
  caliInfo->prodID = 9;

  return 0;

writeError0: 
  printf("Error : getCalibrationInfo write failed\n");
  return -1;

writeError1:
  printf("Error : getCalibrationInfo did not write all of the buffer\n");
  return -1;

readError0:
  printf("Error : getCalibrationInfo read failed\n");
  return -1;

readError1:
  printf("Error : getCalibrationInfo did not read all of the buffer\n");
  return -1;

commandByteError:
  printf("Error : received buffer at byte 1, 2, or 3 are not 0xA3, 0x01, 0x2A \n");
  return -1;
}
Ejemplo n.º 11
0
long ehTimerCounter(HANDLE hDevice, uint8 inTimerClockDivisor, uint8 inEnableMask, uint8 inTimerClockBase, uint8 inUpdateReset, uint8 *inTimerMode, uint16 *inTimerValue, uint8 *inCounterMode, uint32 *outTimer, uint32 *outCounter)
{
  uint8 sendBuff[30], recBuff[40];
  int sendChars, recChars, i, j;
  uint16 checksumTotal;

  sendBuff[1] = (uint8)(0xF8);  //command byte
  sendBuff[2] = (uint8)(0x0C);  //number of data words
  sendBuff[3] = (uint8)(0x18);  //extended command number

  sendBuff[6] = inTimerClockDivisor;  //TimerClockDivisor
  sendBuff[7] = inEnableMask;  //EnableMask
  sendBuff[8] = inTimerClockBase;  //TimerClockBase

  sendBuff[9] = inUpdateReset;  //UpdateReset

  for(i = 0; i < 6; i++)
  {
    sendBuff[10 + i*3] = inTimerMode[i];                        //TimerMode
    sendBuff[11 + i*3] = (uint8)(inTimerValue[i]&0x00FF);       //TimerValue (low byte)
    sendBuff[12 + i*3] = (uint8)((inTimerValue[i]&0xFF00)/256); //TimerValue (high byte)
  }

  for(i = 0; i < 2; i++)
    sendBuff[28 + i] = inCounterMode[i];  //CounterMode

  extendedChecksum(sendBuff, 30);

  //Sending command to UE9
  sendChars = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuff, 30);
  if(sendChars < 30)
  {
    if(sendChars == 0)
      printf("ehTimerCounter error : write failed\n");
    else
      printf("ehTimerCounter error : did not write all of the buffer\n");
    return -1;
  }

  //Reading response from UE9
  recChars = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuff, 40);
  if(recChars < 40)
  {
    if(recChars == 0)
      printf("ehTimerCounter error : read failed\n");
    else
      printf("ehTimerCounter error : did not read all of the buffer\n");
    return -1;
  }

  checksumTotal = extendedChecksum16(recBuff, 40);
  if( (uint8)((checksumTotal / 256) & 0xff) != recBuff[5])
  {
    printf("ehTimerCounter error : read buffer has bad checksum16(MSB)\n");
    return -1;
  }

  if( (uint8)(checksumTotal & 0xff) != recBuff[4])
  {
    printf("ehTimerCounter error : read buffer has bad checksum16(LBS)\n");
    return -1;
  }

  if( extendedChecksum8(recBuff) != recBuff[0])
  {
    printf("ehTimerCounter error : read buffer has bad checksum8\n");
    return -1;
  }

  if(recBuff[1] != (uint8)(0xF8) || recBuff[2] != (uint8)(0x11) || recBuff[3] != (uint8)(0x18))
  {
    printf("ehTimerCounter error : read buffer has wrong command bytes for TimerCounter\n");
    return -1;
  }

  if(outTimer != NULL)
  {
    for(i = 0; i < 6; i++)
    {
      outTimer[i] = 0;
      for(j = 0; j < 4; j++)
        outTimer[i] += recBuff[8 + j + i*4]*pow(2, 8*j);
    }
  }

  if(outCounter != NULL)
  {
    for(i = 0; i < 2; i++)
    {
      outCounter[i] = 0;
      for(j = 0; j < 4; j++)
        outCounter[i] += recBuff[32 + j + i*4]*pow(2, 8*j);
    }
  }

  return recBuff[6];
}
Ejemplo n.º 12
0
long ehDIO_Feedback(HANDLE hDevice, uint8 channel, uint8 direction, uint8 *state)
{
  uint8 sendBuff[34], recBuff[64];
  int sendChars, recChars;
  int i;
  uint8 tempDir, tempState, tempByte;
  uint16 checksumTotal;

  sendBuff[1] = (uint8)(0xF8);  //command byte
  sendBuff[2] = (uint8)(0x0E);  //number of data words
  sendBuff[3] = (uint8)(0x00);  //extended command number

  for(i = 6; i < 34; i++)
    sendBuff[i] = 0;

  tempDir = ((direction < 1) ? 0 : 1);
  tempState = ((*state < 1) ? 0 : 1);

  if(channel <=  7)
  {
    tempByte = pow(2, channel);
    sendBuff[6] = tempByte;
    if(tempDir)
        sendBuff[7] = tempByte;
    if(tempState)
        sendBuff[8] = tempByte;
  }
  else if(channel <= 15)
  {
    tempByte = pow(2, (channel - 8));
    sendBuff[9] = tempByte;
    if(tempDir)
        sendBuff[10] = tempByte;
    if(tempState)
        sendBuff[11] = tempByte;
  }
  else if(channel <= 19)
  {
    tempByte = pow(2, (channel - 16));
    sendBuff[12] = tempByte;
    if(tempDir)
        sendBuff[13] = tempByte*16;
    if(tempState)
        sendBuff[13] += tempByte;
  }
  else if(channel <= 22)
  {
    tempByte = pow(2, (channel - 20));
    sendBuff[14] = tempByte;
    if(tempDir)
        sendBuff[15] = tempByte*16;
    if(tempState)
        sendBuff[15] += tempByte;
  }
  else
  {
    printf("DIO Feedback error: Invalid Channel\n");
    return -1;
  }

  extendedChecksum(sendBuff, 34);

  //Sending command to UE9
  sendChars = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuff, 34);
  if(sendChars < 34)
  {
    if(sendChars == 0)
      printf("DIO Feedback error : write failed\n");
    else  
      printf("DIO Feedback error : did not write all of the buffer\n");
    return -1;
  }

  //Reading response from UE9
  recChars = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuff, 64);
  if(recChars < 64)
  {
    if(recChars == 0)
      printf("DIO Feedback error : read failed\n");
    else  
      printf("DIO Feedback error : did not read all of the buffer\n");
    return -1;
  }

  checksumTotal = extendedChecksum16(recBuff, 64);
  if( (uint8)((checksumTotal / 256) & 0xff) != recBuff[5])
  {
    printf("DIO Feedback error : read buffer has bad checksum16(MSB)\n");
    return -1;
  }

  if( (uint8)(checksumTotal & 0xff) != recBuff[4])
  {
    printf("DIO Feedback error : read buffer has bad checksum16(LBS)\n");
    return -1;
  }

  if( extendedChecksum8(recBuff) != recBuff[0])
  {
    printf("DIO Feedback error : read buffer has bad checksum8\n");
    return -1;
  }

  if(recBuff[1] != (uint8)(0xF8) || recBuff[2] != (uint8)(0x1D) || recBuff[3] != (uint8)(0x00))
  {
    printf("DIO Feedback error : read buffer has wrong command bytes \n");
    return -1;
  }

  if(channel <=  7)
    *state = ((recBuff[7]&tempByte) ? 1 : 0);
  else if(channel <= 15)
    *state = ((recBuff[9]&tempByte) ? 1 : 0);
  else if(channel <= 19)
    *state = ((recBuff[10]&tempByte) ? 1 : 0);
  else if(channel <= 22)
    *state = ((recBuff[11]&tempByte) ? 1 : 0);

  return 0;
}
Ejemplo n.º 13
0
long ehSingleIO(HANDLE hDevice, uint8 inIOType, uint8 inChannel, uint8 inDirBipGainDACL, uint8 inStateResDACH, uint8 inSettlingTime, uint8 *outIOType, uint8 *outChannel, uint8 *outDirAINL, uint8 *outStateAINM, uint8 *outAINH)
{
  uint8 sendBuff[8], recBuff[8];
  int sendChars, recChars;

  sendBuff[1] = (uint8)(0xA3);    //command byte
  sendBuff[2] = inIOType;         //IOType
  sendBuff[3] = inChannel;        //Channel
  sendBuff[4] = inDirBipGainDACL; //Dir/BipGain/DACL
  sendBuff[5] = inStateResDACH;   //State/Resolution/DACH
  sendBuff[6] = inSettlingTime;  //Settling time
  sendBuff[7] = 0;                //Reserved
  sendBuff[0] = normalChecksum8(sendBuff, 8);

  //Sending command to UE9
  sendChars = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuff, 8);
  if(sendChars < 8)
  {
    if(sendChars == 0)
      printf("SingleIO error : write failed\n");
    else
      printf("SingleIO error : did not write all of the buffer\n");
    return -1;
  }

  //Reading response from UE9
  recChars = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuff, 8);
  if(recChars < 8)
  {
    if(recChars == 0)
      printf("SingleIO error : read failed\n");
    else
      printf("SingleIO error : did not read all of the buffer\n");
      return -1;
  }

  if((uint8)(normalChecksum8(recBuff, 8)) != recBuff[0])
  {
    printf("SingleIO error : read buffer has bad checksum\n");
    return -1;
  }

  if(recBuff[1] != (uint8)(0xA3))
  {
    printf("SingleIO error : read buffer has wrong command byte\n");
    return -1;
  }

  if(outIOType != NULL)
    *outIOType = recBuff[2];
  if(outChannel != NULL)
    *outChannel = recBuff[3];
  if(outDirAINL != NULL)
    *outDirAINL = recBuff[4];
  if(outStateAINM != NULL)
    *outStateAINM = recBuff[5];
  if(outAINH != NULL)
    *outAINH = recBuff[6];

  return 0;
}
Ejemplo n.º 14
0
long ehConfigIO(HANDLE hDevice, uint8 inWriteMask, uint8 inTimerCounterConfig, uint8 inDAC1Enable, uint8 inFIOAnalog, uint8 inEIOAnalog, uint8 *outTimerCounterConfig, uint8 *outDAC1Enable, uint8 *outFIOAnalog, uint8 *outEIOAnalog)
{
    uint8 sendBuff[12], recBuff[12];
    uint16 checksumTotal;
    int sendChars, recChars;

    sendBuff[1] = (uint8)(0xF8);  //Command byte
    sendBuff[2] = (uint8)(0x03);  //Number of data words
    sendBuff[3] = (uint8)(0x0B);  //Extended command number

    sendBuff[6] = inWriteMask;  //Writemask

    sendBuff[7] = 0;            //Reserved
    sendBuff[8] = inTimerCounterConfig;  //TimerCounterConfig
    sendBuff[9] = inDAC1Enable; //DAC1 enable : not enabling
    sendBuff[10] = inFIOAnalog; //FIOAnalog
    sendBuff[11] = inEIOAnalog; //EIOAnalog
    extendedChecksum(sendBuff, 12);

    //Sending command to U3
    if( (sendChars = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, sendBuff, 12)) < 12)
    {
        if(sendChars == 0)
            printf("ehConfigIO error : write failed\n");
        else
            printf("ehConfigIO error : did not write all of the buffer\n");
        return -1;
    }

    //Reading response from U3
    if( (recChars = LJUSB_BulkRead(hDevice, U3_PIPE_EP2_IN, recBuff, 12)) < 12)
    {
        if(recChars == 0)
            printf("ehConfigIO error : read failed\n");
        else
            printf("ehConfigIO error : did not read all of the buffer\n");
        return -1;
    }

    checksumTotal = extendedChecksum16(recBuff, 12);
    if( (uint8)((checksumTotal / 256 ) & 0xff) != recBuff[5])
    {
        printf("ehConfigIO error : read buffer has bad checksum16(MSB)\n");
        return -1;
    }

    if( (uint8)(checksumTotal & 0xff) != recBuff[4])
    {
        printf("ehConfigIO error : read buffer has bad checksum16(LBS)\n");
        return -1;
    }

    if( extendedChecksum8(recBuff) != recBuff[0])
    {
        printf("ehConfigIO error : read buffer has bad checksum8\n");
        return -1;
    }

    if( recBuff[1] != (uint8)(0xF8) || recBuff[2] != (uint8)(0x03) || recBuff[3] != (uint8)(0x0B) )
    {
        printf("ehConfigIO error : read buffer has wrong command bytes\n");
        return -1;
    }

    if( recBuff[6] != 0)
    {
        printf("ehConfigIO error : read buffer received errorcode %d\n", recBuff[6]);
        return (int)recBuff[6];
    }

    if(outTimerCounterConfig != NULL)
        *outTimerCounterConfig = recBuff[8];
    if(outDAC1Enable != NULL)
        *outDAC1Enable = recBuff[9];
    if(outFIOAnalog != NULL)
        *outFIOAnalog = recBuff[10];
    if(outEIOAnalog != NULL)
        *outEIOAnalog = recBuff[11];

    return 0;
}
Ejemplo n.º 15
0
long getCalibrationInfo(HANDLE hDevice, u3CalibrationInfo *caliInfo)
{
  uint8 sendBuffer[8], recBuffer[40];
  uint8 cU3SendBuffer[26], cU3RecBuffer[38];
  int sentRec = 0;
  int i = 0;

  /* sending ConfigU3 command to get hardware version and see if HV */
  cU3SendBuffer[1] = (uint8)(0xF8);  //command byte
  cU3SendBuffer[2] = (uint8)(0x0A);  //number of data words
  cU3SendBuffer[3] = (uint8)(0x08);  //extended command number

  //setting WriteMask0 and all other bytes to 0 since we only want to read the response
  for (i = 6; i < 26; i++)
    cU3SendBuffer[i] = 0;

  extendedChecksum(cU3SendBuffer, 26);

  sentRec = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, cU3SendBuffer, 26);
  if (sentRec < 26)
  {
    if (sentRec == 0)
      goto writeError0;
    else
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, U3_PIPE_EP1_IN, cU3RecBuffer, 38);
  if (sentRec < 38)
  {
    if (sentRec == 0)
      goto readError0;
    else
      goto readError1;
  }

  if (cU3RecBuffer[1] != (uint8)(0xF8) || cU3RecBuffer[2] != (uint8)(0x10) || cU3RecBuffer[3] != (uint8)(0x08))
    goto commandByteError;

  caliInfo->hardwareVersion = cU3RecBuffer[14] + cU3RecBuffer[13]/100.0;
  caliInfo->highVoltage = (((cU3RecBuffer[37]&18) == 18)?1:0);

  /* reading block 0 from memory */
  sendBuffer[1] = (uint8)(0xF8);  //command byte
  sendBuffer[2] = (uint8)(0x01);  //number of data words
  sendBuffer[3] = (uint8)(0x2D);  //extended command number
  sendBuffer[6] = 0;
  sendBuffer[7] = 0;              //Blocknum = 0
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, sendBuffer, 8);
  if (sentRec < 8)
  {
    if (sentRec == 0)
      goto writeError0;
    else
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, U3_PIPE_EP1_IN, recBuffer, 40);
  if (sentRec < 40)
  {
    if (sentRec == 0)
      goto readError0;
    else
      goto readError1;
  }

  if (recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x11) || recBuffer[3] != (uint8)(0x2D))
    goto commandByteError;

  //block data starts on byte 8 of the buffer
  caliInfo->ainSESlope = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->ainSEOffset = FPuint8ArrayToFPDouble(recBuffer + 8, 8);
  caliInfo->ainDiffSlope = FPuint8ArrayToFPDouble(recBuffer + 8, 16);
  caliInfo->ainDiffOffset = FPuint8ArrayToFPDouble(recBuffer + 8, 24);

  /* reading block 1 from memory */
  sendBuffer[7] = 1;    //Blocknum = 1
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, sendBuffer, 8);
  if (sentRec < 8)
  {
    if (sentRec == 0)
      goto writeError0;
    else
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, U3_PIPE_EP1_IN, recBuffer, 40);;

  if (sentRec < 40)
  {
    if (sentRec == 0)
      goto readError0;
    else
      goto readError1;
  }

  if (recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x11) || recBuffer[3] != (uint8)(0x2D))
    goto commandByteError;

  caliInfo->dacSlope[0] = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->dacOffset[0] = FPuint8ArrayToFPDouble(recBuffer + 8, 8);
  caliInfo->dacSlope[1] = FPuint8ArrayToFPDouble(recBuffer + 8, 16);
  caliInfo->dacOffset[1] = FPuint8ArrayToFPDouble(recBuffer + 8, 24);

  /* reading block 2 from memory */
  sendBuffer[7] = 2;    //Blocknum = 2
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, sendBuffer, 8);
  if (sentRec < 8)
  {
    if (sentRec == 0)
      goto writeError0;
    else
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, U3_PIPE_EP1_IN, recBuffer, 40);
  if (sentRec < 40)
  {
    if (sentRec == 0)
      goto readError0;
    else
      goto readError1;
  }

  if (recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x11) || recBuffer[3] != (uint8)(0x2D))
    goto commandByteError;

  caliInfo->tempSlope = FPuint8ArrayToFPDouble(recBuffer + 8, 0);
  caliInfo->vref = FPuint8ArrayToFPDouble(recBuffer + 8, 8);
  caliInfo->vref15 = FPuint8ArrayToFPDouble(recBuffer + 8, 16);
  caliInfo->vreg = FPuint8ArrayToFPDouble(recBuffer + 8, 24);

  /* reading block 3 from memory */
  sendBuffer[7] = 3;    //Blocknum = 3
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, sendBuffer, 8);
  if (sentRec < 8)
  {
    if (sentRec == 0)
      goto writeError0;
    else
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, U3_PIPE_EP1_IN, recBuffer, 40);
  if (sentRec < 40)
  {
    if (sentRec == 0)
      goto readError0;
    else
      goto readError1;
  }

  if (recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x11) || recBuffer[3] != (uint8)(0x2D))
    goto commandByteError;

  for (i = 0; i < 4; i++)
    caliInfo->hvAINSlope[i] = FPuint8ArrayToFPDouble(recBuffer + 8, i*8);

  /* reading block 4 from memory */
  sendBuffer[7] = 4;    //Blocknum = 4
  extendedChecksum(sendBuffer, 8);

  sentRec = LJUSB_BulkWrite(hDevice, U3_PIPE_EP1_OUT, sendBuffer, 8);
  if (sentRec < 8)
  {
    if (sentRec == 0)
      goto writeError0;
    else
      goto writeError1;
  }

  sentRec = LJUSB_BulkRead(hDevice, U3_PIPE_EP1_IN, recBuffer, 40);
  if (sentRec < 40)
  {
    if (sentRec == 0)
      goto readError0;
    else
      goto readError1;
  }

  if (recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x11) || recBuffer[3] != (uint8)(0x2D))
    goto commandByteError;

  for (i = 0; i < 4; i++)
    caliInfo->hvAINOffset[i] = FPuint8ArrayToFPDouble(recBuffer + 8, i*8);

  caliInfo->prodID = 3;

  return 0;

writeError0:
  printf("Error : getCalibrationInfo write failed\n");
  return -1;

writeError1:
  printf("Error : getCalibrationInfo did not write all of the buffer\n");
  return -1;

readError0:
  printf("Error : getCalibrationInfo read failed\n");
  return -1;

readError1:
  printf("Error : getCalibrationInfo did not read all of the buffer\n");
  return -1;

commandByteError:
  printf("Error : getCalibrationInfo received wrong command bytes for ReadMem\n");
  return -1;
}
Ejemplo n.º 16
0
long getCalibrationInfo(HANDLE hDevice, ue9CalibrationInfo *caliInfo)
{
    uint8 sendBuffer[8];
    uint8 recBuffer[136];
    int sentRec = 0, i = 0, j = 0, ccTotal = 0, count = 0;

    /* Setting up command */
    sendBuffer[1] = (uint8)(0xF8);  //command byte
    sendBuffer[2] = (uint8)(0x01);  //number of data words
    sendBuffer[3] = (uint8)(0x2A);  //extended command number
    sendBuffer[6] = (uint8)(0x00);

    for (i = 0; i < 5; i ++)
    {
        /* reading block 1 from memory */
        sendBuffer[7] = (uint8)i;    //Blocknum = i
        extendedChecksum(sendBuffer, 8);

        sentRec = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuffer, 8);
        if (sentRec < 8)
        {
            if (sentRec == 0)
                printf("Error : getCalibrationInfo write failed\n");
            else
                printf("Error : getCalibrationInfo did not write all of the buffer\n");
            return -1;
        }

        sentRec = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuffer, 136);
        if (sentRec < 136)
        {
            if (sentRec == 0)
                printf("Error : getCalibrationInfo read failed\n");
            else  
                printf("Error : getCalibrationInfo did not read all of the buffer\n");
        }

        if (recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x41) || recBuffer[3] != (uint8)(0x2A))
        {
            printf("Error : received buffer at byte 1, 2, or 3 are not 0xA3, 0x01, 0x2A \n");
            return -1;
        }

        //Reading out calbration constants
        if (i == 0)
            ccTotal = 8;
        if (i == 1)
            ccTotal = 2;
        if (i == 2)
            ccTotal = 13;
        if (i == 3)
            ccTotal = 2;
        if (i == 4)
            ccTotal = 2;

        for (j = 0; j < ccTotal; j++)
        {
            if (i != 2 || (i == 2 && j != 5 && j != 7) )
            {
                //block data starts on byte 8 of the buffer
                caliInfo->ccConstants[count] = FPuint8ArrayToFPDouble(recBuffer + 8, j*8);
                count++;
            }
        }
    }

    caliInfo->prodID = 9;

    return 0;
}
Ejemplo n.º 17
0
//Sends a TimerCounter low-level command to enable and set two Timers 
//(FIO0, FIO1) and two Counters (FIO2, FIO3), then sends a TimerCounter 
//command a second later to read from the Counters and last sends a 
//TimerCounter command to disable the Timers and Counters. 
int timerCounter_example(HANDLE hDevice)
{
    //Note: if using the quadrature input timer mode, the returned 32 bit integer
    //      is signed
    uint8 sendBuff[30], recBuff[40];
    int sendChars, recChars, i;
    uint32 cnt;

    //Enable timers and counters
    sendBuff[1] = (uint8)(0xF8);  //command byte
    sendBuff[2] = (uint8)(0x0C);  //number of data words
    sendBuff[3] = (uint8)(0x18);  //extended command number
    sendBuff[6] = (uint8)(0x03);  //TimerClockDivisor = 3
    sendBuff[7] = (uint8)(0x9A);  //Updating: 2 Timers enabled, Counter0 and 
                                  //Counter1 enabled
    sendBuff[8] = (uint8)(0x00);  //TimerClockConfig = 750 kHz (if using system 
                                  //clock, call ControlConfig first and set the 
                                  //PowerLevel to a fixed state)
    sendBuff[9] = (uint8)(0x00);  //UpdateReset - not resetting anything
    sendBuff[10] = (uint8)(0x00); //Timer0Mode = 16-Bit PWM

    //Timer0Value = 32768
    sendBuff[11] = (uint8)(0x00); //Timer0Value (low byte)
    sendBuff[12] = (uint8)(0x80); //Timer0Value (high byte)

    //Timer1Value = 32768
    sendBuff[13] = (uint8)(0x01); //Timer1Mode = 8-Bit PWM
    sendBuff[14] = (uint8)(0x00); //Timer1Value (low byte)
    sendBuff[15] = (uint8)(0x80); //Timer1Value (high byte)

    //timer modes and values for timers 2 - 5, which are not enabled
    for(i = 16; i < 28; i++)
        sendBuff[i] = (uint8)(0x00);

    sendBuff[28] = (uint8)(0x00);  //Counter0Mode (pass 0)
    sendBuff[29] = (uint8)(0x00);  //Counter1Mode (pass 0) 

    extendedChecksum(sendBuff, 30);

    //Sending command to UE9
    sendChars = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuff, 30);
    if(sendChars < 30)
    {
        if(sendChars == 0)
            goto writeError0;
        else
            goto writeError1;
    }

    //Reading response from UE9
    recChars = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuff, 40);
    if(recChars < 40)
    {
        if(recChars == 0)
            goto readError0;
        else
            goto readError1;
    }

    if(errorCheck(recBuff) == -1)
        return -1;

    //wait 1 sec, read counters
    sleep(1);

    sendBuff[1] = (uint8)(0xF8);  //command bytes
    sendBuff[2] = (uint8)(0x0C);  //number of data words  
    sendBuff[3] = (uint8)(0x18);  //extended command number    

    //Not updating our configuration, just want to back the counters
    for(i = 6; i < 30; i++)
    sendBuff[i] = (uint8)(0x00);

    extendedChecksum(sendBuff, 30);

    //Sending command to UE9
    sendChars = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuff, 30);
    if(sendChars < 30)
    {
        if(sendChars == 0)
            goto writeError0;
        else
            goto writeError1;
    }

    //Reading response from UE9
    recChars = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuff, 40);
    if(recChars < 40)
    {
        if(recChars == 0)
            goto readError0;
        else  
            goto readError1;
    }

    if(errorCheck(recBuff) == -1)
        return -1;

    printf("Current counts from counters after 1 second:\n");
    for(i = 0; i < 2; i++)
    {
        cnt = (unsigned int)recBuff[32 + 4*i] + (unsigned int)recBuff[33 + 4*i]*256 + 
              (unsigned int)recBuff[34 + 4*i]*65536 + (unsigned int)recBuff[35 + 4*i]*16777216;
        printf("  Counter%d : %u\n", i, cnt);
    }

    //disable timers and counters
    sendBuff[1] = (uint8)(0xF8);  //command bytes
    sendBuff[2] = (uint8)(0x0C);  //number of data words
    sendBuff[3] = (uint8)(0x18);  //extended command number
    sendBuff[6] = (uint8)(0x00);  //TimerClockDivisor = 0
    sendBuff[7] = (uint8)(0x80);  //Updating: 0 Timers enabled, Counter0 and 
                                //Counter1 disabled 

    //setting bytes 8 - 30 to zero since nothing is enabled
    for(i = 8; i < 30; i++)
        sendBuff[i] = (uint8)(0x00);

    extendedChecksum(sendBuff, 30);

    //Sending command to UE9
    sendChars = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuff, 30);
    if(sendChars < 30)
    {
        if(sendChars == 0)
            goto writeError0;
        else
            goto writeError1;
    }

    //Reading response from UE9
    recChars = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuff, 40);
    if(recChars < 40)
    {
        if(recChars == 0)
            goto readError0;
        else
            goto readError1;
    }

    if(errorCheck(recBuff) == -1)
        return -1;

    return 0;

writeError0: 
    printf("Error : write failed\n");
    return -1;

writeError1:
    printf("Error : did not write all of the buffer\n");
    return -1;

readError0:
    printf("Error : read failed\n");
    return -1;

readError1:
    printf("Error : did not read all of the buffer\n");
    return -1;
}
Ejemplo n.º 18
0
HANDLE openUSBConnection(int localID)
{
  BYTE buffer[38];
  uint16 checksumTotal = 0;
  HANDLE hDevice = 0;
  uint32 numDevices = 0;
  uint32 dev;
  int i;

  numDevices = LJUSB_GetDevCount(UE9_PRODUCT_ID);
  if(numDevices == 0) 
  {
    printf("Open error: No UE9 devices could be found\n");
    return NULL;
  }

  for(dev = 1;  dev <= numDevices; dev++) 
  {
    hDevice = LJUSB_OpenDevice(dev, 0, UE9_PRODUCT_ID);
    if(hDevice != NULL)
    {
      if(localID < 0)
      {
        return hDevice;
      }
      else
      {
        checksumTotal = 0;

        //setting up a CommConfig command
        buffer[1] = (BYTE)(0x78);
        buffer[2] = (BYTE)(0x10);
        buffer[3] = (BYTE)(0x01);

        for(i = 6; i < 38; i++)
          buffer[i] = (BYTE)(0x00);

        extendedChecksum(buffer,38);

        if(LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, buffer, 38) != 38)
          goto locid_error;

        for(i = 0; i < 38; i++)
          buffer[i] = 0;

        if(LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, buffer, 38) != 38)
          goto locid_error;

        checksumTotal = extendedChecksum16(buffer, 38);
        if( (BYTE)((checksumTotal / 256) & 0xff) != buffer[5])
          goto locid_error;

        if( (BYTE)(checksumTotal & 0xff) != buffer[4])
          goto locid_error;

        if( extendedChecksum8(buffer) != buffer[0])
          goto locid_error;

        if( buffer[1] != (BYTE)(0x78) || buffer[2] != (BYTE)(0x10) || buffer[3] != (BYTE)(0x01) )
          goto locid_error;

        if( (int)buffer[8] == localID)
          return hDevice;
        else 
          LJUSB_CloseDevice(hDevice);

      } //else localID >= 0 end
    }  //if hDevice != NULL end
  } //for end

  printf("Open error: could not find a UE9 with a local ID of %d\n", localID);
  return NULL;

locid_error:
  printf("Open error: problem when checking local ID\n");
  return NULL;
}