long getTdacCalibrationInfo(HANDLE hDevice, ue9TdacCalibrationInfo *caliInfo, uint8 DIOAPinNum) { int err; uint8 options, speedAdjust, sdaPinNum, sclPinNum; uint8 address, numByteToSend, numBytesToReceive, errorcode; uint8 bytesCommand[1]; uint8 bytesResponse[32]; uint8 ackArray[4]; err = 0; //Setting up I2C command for LJTDAC options = 0; //I2COptions : 0 speedAdjust = 0; //SpeedAdjust : 0 (for max communication speed of about 130 kHz) sdaPinNum = DIOAPinNum+1; //SDAPinNum : FIO channel connected to pin DIOB sclPinNum = DIOAPinNum; //SCLPinNum : FIO channel connected to pin DIOA address = (uint8)(0xA0); //Address : h0xA0 is the address for EEPROM numByteToSend = 1; //NumI2CByteToSend : 1 byte for the EEPROM address numBytesToReceive = 32; //NumI2CBytesToReceive : getting 32 bytes starting at EEPROM address specified in I2CByte0 bytesCommand[0] = 64; //I2CByte0 : Memory Address (starting at address 64 (DACA Slope) //Performing I2C low-level call err = I2C(hDevice, options, speedAdjust, sdaPinNum, sclPinNum, address, numByteToSend, numBytesToReceive, bytesCommand, &errorcode, ackArray, bytesResponse); if( errorcode != 0 ) { printf("Getting LJTDAC calibration info error : received errorcode %d in response\n", errorcode); err = -1; } if( err == -1 ) return err; caliInfo->ccConstants[0] = FPuint8ArrayToFPDouble(bytesResponse, 0); caliInfo->ccConstants[1] = FPuint8ArrayToFPDouble(bytesResponse, 8); caliInfo->ccConstants[2] = FPuint8ArrayToFPDouble(bytesResponse, 16); caliInfo->ccConstants[3] = FPuint8ArrayToFPDouble(bytesResponse, 24); caliInfo->prodID = 9; return err; }
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; }
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; }
long getCalibrationInfo(HANDLE hDevice, ue9CalibrationInfo *caliInfo) { BYTE sendBuffer[8], recBuffer[136]; int sentRec = 0, i = 0, j = 0, ccTotal = 0, count = 0; /* Setting up command */ sendBuffer[1] = (BYTE)(0xF8); //command byte sendBuffer[2] = (BYTE)(0x01); //number of data words sendBuffer[3] = (BYTE)(0x2A); //extended command number sendBuffer[6] = (BYTE)(0x00); for( i = 0; i < 5; i++ ) { /* Reading block 1 from memory */ sendBuffer[7] = (BYTE)i; //Blocknum = i extendedChecksum(sendBuffer, 8); sentRec = LJUSB_Write(hDevice, sendBuffer, 8); if( sentRec < 8 ) { if( sentRec == 0 ) printf("getCalibrationInfo error : write failed\n"); else printf("getCalibrationInfo error : did not write all of the buffer\n"); return -1; } sentRec = LJUSB_Read(hDevice, recBuffer, 136); if( sentRec < 136 ) { if( sentRec == 0 ) printf("getCalibrationInfo Error : read failed\n"); else printf("getCalibrationInfo Error : did not read all of the buffer\n"); } if( recBuffer[1] != (BYTE)(0xF8) || recBuffer[2] != (BYTE)(0x41) || recBuffer[3] != (BYTE)(0x2A) ) { printf("getCalibrationInfo error: incorrect command bytes for ReadMem response"); 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; }
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; }
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; }