Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    HANDLE hDevice;
    u6CalibrationInfo caliInfo;

    //Opening first found U6 over USB
    if( (hDevice = openUSBConnection(-1)) == NULL )
        goto done;

    //Getting calibration information from U6
    if( getCalibrationInfo(hDevice, &caliInfo) < 0 )
        goto close;

    if( ConfigIO_example(hDevice) != 0 )
        goto close;

    //Stopping any previous streams
    StreamStop(hDevice);

    if( StreamConfig_example(hDevice) != 0 )
        goto close;

    if( StreamStart(hDevice) != 0 )
        goto close;

    StreamData_example(hDevice, &caliInfo);
    StreamStop(hDevice);

close:
    closeUSBConnection(hDevice);
done:
    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    int socketFD;
    ue9CalibrationInfo caliInfo;

    if(argc < 2)
    {
        printf("Please enter an ip address to connect to.\n");
        exit(0);
    }
    else if(argc > 2)
    {
        printf("Too many arguments.\nPlease enter only an ip address.\n");
        exit(0);
    }

    //Opening TCP connection to UE9
    if( (socketFD = openTCPConnection(argv[1], ue9_port)) < 0)
        goto done;

    //Getting calibration information from UE9
    if(getCalibrationInfo(socketFD, &caliInfo) < 0)
        goto close;

    allIO(socketFD, &caliInfo);

close:
    if(closeTCPConnection(socketFD) < 0)
    {
        printf("Error: failed to close socket\n");
        return 1;
    }
done:
    return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  int socketFDA, socketFDB;
  ue9CalibrationInfo caliInfo;
  socketFDA = -1;
  socketFDB = -1;

  if(argc < 2)
  {
    printf("Please enter an ip address to connect to.\n");
    exit(0);
  }
  else if(argc > 2)
  {
    printf("Too many arguments.\nPlease enter only an ip address.\n");
    exit(0);
  }

  ipAddress = argv[1];

  if( (socketFDA = openTCPConnection(ipAddress, ue9_portA)) < 0)
    goto exit;

  doFlush(socketFDA);

  if( (socketFDB = openTCPConnection(ipAddress, ue9_portB)) < 0)
    goto close;

  if(getCalibrationInfo(socketFDA, &caliInfo) < 0)
    goto close;

  if(StreamConfig_example(socketFDA) != 0)
    goto close;

  if(StreamStart(socketFDA) != 0)
    goto close;

  StreamData_example(socketFDA, socketFDB, &caliInfo);
  StreamStop(socketFDA, 1);

close:
  if(closeTCPConnection(socketFDA) < 0)
    printf("Error: failed to close socket (portA)\n");
  if(closeTCPConnection(socketFDB) < 0)
    printf("Error: failed to close socket (portB)\n");
exit:
  return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
    HANDLE hDevice;
    ue9CalibrationInfo caliInfo;

    //Opening first found UE9 over USB
    if( (hDevice = openUSBConnection(-1)) == NULL )
        goto done;

    //Getting calibration information from UE9
    if( getCalibrationInfo(hDevice, &caliInfo) < 0 )
        goto close;

    allIO(hDevice, &caliInfo);

close:
    closeUSBConnection(hDevice);
done:
    return 0;
}
Ejemplo n.º 5
0
int startConnectionUE9 (CONNECTION *ret) {

	printf("Trying to connect to UE9...");

	//Opening TCP connection to UE9
	 if( ( (ret->socketFD = openTCPConnection(DEFAULTIP, DEFAULTPORT)) < 0)) //retunrs true if succesfull, native UE9 
	 {
			return -1;
	 }
	 else{
		 //Getting calibration information from UE9  (Necessary for communication)
		if( (getCalibrationInfo(ret->socketFD, &ret->caliInfo) < 0))
		{
				return -2;
		}		
		else{
			return 0; //Everything perfect
		}
	 } 
}
Ejemplo n.º 6
0
int labjackSetup(){
  long int localID=-1;
  long int count=0;
  long int error=0;

/*
  Open first found U6 over USB
*/
  printf("opening usb .... ");

  while (count < 5) {
    if( (hU6 = openUSBConnection(localID)) == NULL){
      count++;
      printf("Opening failed; reseting and attempting %li of 5 more times \n",count);
      printf ("....U6 device reset \n");
      resetU6(0x01);                       // 0x00 = soft reset; 0x01 = reboot
      sleep (2);
      resetU6(0x01);                       // 0x00 = soft reset; 0x01 = reboot
      sleep (2);
      if (count > 5) return 0;
    } 
    else {
      count = 5;
    }
  }

  printf("opened usb\n");
/*
  Get calibration information from U6
*/
  printf("getting calib .... ");
  error = getCalibrationInfo(hU6, &caliInfo);
  if(error != 0){
    printf("\n%li - %s\n",error, errormsg[error]);
    closeUSBConnection(hU6);
    return 0;
  } 
  printf("got calib \n");

  return;
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
  int socketFD, i, j;
  ue9CalibrationInfo caliInfo;
  long error;
  double dblVoltage, dblIntTemp, TKelvin[NTHERMS];
  long alngEnableTimers[6], alngTimerModes[6], alngEnableCounters[2], 
    alngReadTimers[6];
  long alngUpdateResetTimers[6], alngReadCounters[2], alngResetCounters[2];
  double adblTimerValues[6], adblCounterValues[2];

  char datafile[80];
  
  int                hour, lasthour;
  time_t             timep;
  struct tm          tm;
  FILE *data_fd, *tnow_fd, *cal_fd;

  double cal_coeffs[2][NTHERMS];  

/* Calibration coefficients were determined from the night of
   2005/05/15, calibrating using the HOBO */

//       26.011521      0.89395315
//       3.8793608      0.96553796
//       21.189119      0.89810403
//       24.789991      0.89390865

// There *must* be a better way to do this
  cal_coeffs[0][3] = 26.011521;
  cal_coeffs[1][3] = 0.89395315;
  cal_coeffs[0][2] = 3.8793608;
  cal_coeffs[1][2] = 0.96553796;
  cal_coeffs[0][1] = 21.189119;
  cal_coeffs[1][1] = 0.89810403;
  cal_coeffs[0][0] = 24.789991;
  cal_coeffs[1][0] = 0.89390865;

  cal_fd = fopen("ThermometerCalibrationConstants.txt", "w");
  for (j=0; j<4; j++) {
    for (i=0; i<2; i++) {
      fprintf(cal_fd,"%12.8f ",
	      cal_coeffs[i][j]);
    }
    fprintf(cal_fd,"\n");
  }
  fprintf(cal_fd,"\n");
  fflush(cal_fd);
  fclose(cal_fd);

  // Ugh.  Can't remember how to do this.
//  cal_fd = fopen("ThermometerCalibrationConstants.txt", "r");
//  for (j=0; j<4; j++) {
//    for (i=0; i<2; i++) {
//      cal_coeffs[i][j] = fscanf(cal_fd,"%12f ");
//      printf("%12.8f ",cal_coeffs[i][j]);
//    }
//    printf("\n");
//  }
//  fclose(cal_fd);
//

  for(i = 0; i < 6; i++)
  {
    alngEnableTimers[i] = 0;
    alngTimerModes[i] = 0;
    adblTimerValues[i] = 0.0;
    alngReadTimers[i] = 0;
    alngUpdateResetTimers[i] = 0;
    if(i < 2)
    {
      alngEnableCounters[i] = 0;
      alngReadCounters[i] = 0;
      alngResetCounters[i] = 0;
      adblCounterValues[i] = 0.0;
    }
  }
  
  if(argc < 2)
  {
    printf("Please enter an ip address to connect to.\n");
    exit(0);
  }
  else if(argc > 2)
  {
    printf("Too many arguments.\nPlease enter only an ip address.\n");
    exit(0);
  }

  //Opening TCP connection to UE9
  printf("Opening TCP connection to %s\n",argv[1]);
  if( (socketFD = openTCPConnection(argv[1], ue9_port)) < 0)
    goto done;

  //Getting calibration information from UE9
  printf("Getting calibration information.\n");
  if(getCalibrationInfo(socketFD, &caliInfo) < 0)
    goto close;

  //Disable all timers and counters
  for(i = 0; i < 6; i++)
    alngEnableTimers[i] = 0;
  alngEnableCounters[0] = 0;
  alngEnableCounters[1] = 0;
  if((error = eTCConfig(socketFD, alngEnableTimers, alngEnableCounters, 
			0, 0, 0, alngTimerModes, adblTimerValues, 0, 0)) != 0)
    goto close;
  printf("Calling eTCConfig to disable all timers and counters\n");

  time(&timep);
  tm = *localtime(&timep);
  // There is a way to get UT time ...
  //  tm = *uttime(&timep);
  hour = tm.tm_hour;
  lasthour = hour;

  sprintf(datafile,"%04i%02i%02i_%02i%02i.txt",
	  tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min);

  data_fd = fopen(datafile, "w");

  printf("\nBegin acquiring data.\n");
  printf("Type ctrl-C to quit.\n");

  while(1) {

    time(&timep);
    tm = *localtime(&timep);
    hour = tm.tm_hour;
    
    if (hour != lasthour){
      fclose(data_fd);
      sprintf(datafile,"%04i%02i%02i_%02i00.txt",
	  tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour);
      data_fd = fopen(datafile, "w");
    }

    fprintf(data_fd,"%04i/%02i/%02i  %02i:%02i:%02i   ",
	   tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday, 
	   tm.tm_hour, tm.tm_min, tm.tm_sec);

    dblIntTemp = 0;
    if(readIntTemp(socketFD, &caliInfo, &dblIntTemp) < 0)
      goto close;
    fprintf(data_fd,"%.3f  ",dblIntTemp);

    // Read the voltage from AIN0-3 using 0-5 volt range at 16 bit resolution
    for (i=0; i<NTHERMS; i++)
      {
        if((error = eAIN(socketFD, &caliInfo, i, 0, &dblVoltage, LJ_rgUNI5V, 
			 16, 0, 0, 0, 0)) != 0)
          goto close;
	TKelvin[i] = (dblVoltage * 100) * 
	  cal_coeffs[1][i] + cal_coeffs[0][i];
      }

    // Print data out to file
    for (i=0; i<NTHERMS; i++)
      {
	fprintf(data_fd,"%10.3f   ", TKelvin[i]);
      }
    fprintf(data_fd,"\n");
    fflush(data_fd);

    tnow_fd = fopen("TNow","w");

    for (i=0; i<NTHERMS; i++)
      {
	fprintf(tnow_fd,"%10.3f   ", TKelvin[i]);
      }
    fprintf(tnow_fd,"\n");
    fflush(tnow_fd);
    fclose(tnow_fd);

	sleep(1);
//    usleep(1000);
    
    lasthour = hour;
  }

close:
  if(error > 0)
    printf("Received an error code of %ld\n", error);
  if(closeTCPConnection(socketFD) < 0)
  {
    printf("Error: failed to close socket\n");
    return 1;
  }
done:
  return 0;
}