Exemplo n.º 1
0
int get_scan(QSP_ARG_DECL  Spectral_Data *sdp)
{
	char pkt[6];		/* will contain either "Z1\n" or "Z0001" */
	int data_word = 1;	/* pg.12, 1 or 0 doesn't matter */
	char cmd[] = "Z";
	u_short len;
	u_short n_spec_recvd[1];
	Pxl_Mode_Info pxl_mode_info;

	/* BUG: we should have a routine here that checks
	 * if we have scans in memory or not.
	 * This will be better than sending a pkt
	 * and getting a NAK due to absence of spectra
	 * in data memory.
	 */

	make_pkt( pkt, cmd, data_word );

	send_pkt(QSP_ARG  pkt);

	len = strlen(pkt);

	if( get_echo(QSP_ARG  pkt) < 0 )
		return -1;

	if ( recv_a_byte(SINGLE_QSP_ARG) != ACK ) {
		WARN("ERROR: no ACK received");
		return -1;
	}

	if( get_spectrum(QSP_ARG  sdp, n_spec_recvd, &pxl_mode_info) < 0 )
		return -1;

	if( get_tail(SINGLE_QSP_ARG) < 0 )
		return -1;

	do_wavlen_crktion(sdp, n_spec_recvd[0], &pxl_mode_info);
	do_non_linear_crktion(sdp, n_spec_recvd[0]);

	return n_spec_recvd[0];

}
 int main(int argc, char *argv[]) {
 	int flag;
 	int error;
 	char type[16];
 	int device_count = 0;
 	int i;

    ////////////////////////////////////////////////////////////////////////////
    // parse & validate arguments
    ////////////////////////////////////////////////////////////////////////////
 	parseArgs(argc, argv);

 	if (dtg.year == 0)
 	{
 		printf("ERROR: invalid dtg provided\n");
 		usage();
 	}

 	printf("sampleNum is: %i\n", sampleNum);

 	if (sampleNum==0){
 		printf("Setting up the header file for the csv\n");
 	}else if (sampleNum >= 1){
 		printf("performing normal sampling\n");
 	}else {
 		printf("ERROR: incorrect scanNum option provided\n");
 		usage();
 	}

    ////////////////////////////////////////////////////////////////////////////

 	for(i = 0; i < SEABREEZE_MAX_DEVICES; i++) {
 		printf("\nOpening spectrometer %d.\n", i);
 		flag = seabreeze_open_spectrometer(i, &error);
 		printf("...Result is (%d) [%s]\n", flag, get_error_string(error));
 		if(0 == flag) {
 			device_count++;
 		} else {
 			break;
 		}
 	}
    

 	for(i = 0; i < device_count; i++) {
 		printf("\nGetting device %d name.\n", i);
 		seabreeze_get_model(i, &error, type, sizeof(type));
 		printf("...Result is (%s) [%s]\n", type, get_error_string(error));
 	}

 	printf("Number of devices found is: %d\n", device_count);

 	for(i = 0; i < device_count; i++) {
 		printf("\nSetting device %d integration time to 100ms.\n", i);
 		seabreeze_set_integration_time_microsec(i, &error, 100000);
 		//printf("...Result is [%s]\n", get_error_string(error));
 	}

 	if (deviceIndex < device_count){
 		printf("\n\nBegin sampling using device: %d\n", deviceIndex);

 		if (sampleNum == 0){
 			get_wavelengths(deviceIndex);
 		}else if (sampleNum>=1){
 			get_spectrum(deviceIndex);
 		}
 	}else{
 		printf("deviceIndex provided in arguments is out of range of the number of devices found" );
 		usage();
 	}
 	
 	//get_raw_spectrum_test(i);

 	////////////////////////////////////////////////////////////////////////////////
 	/////close the spectrometers
 	///////////////////////////////////////////////////////////////////////////////
 	for(i = 0; i < device_count; i++) {
 		printf("\nClosing spectrometer %d.\n", i);
 		flag = seabreeze_close_spectrometer(i, &error);
 		//printf("...Result is (%d) [%s]\n", flag, get_error_string(error));
 	}

 	seabreeze_shutdown();

 	return 0;
 }
Exemplo n.º 3
0
int spec_acq(QSP_ARG_DECL  Spectral_Data *sdp)
{
	const char *cmdp="S\0";
	int check_sum;
	int device_check_sum;
	char tmp[5];
	u_short i;
	int data_recvd;
	int n;
	u_short n_spec_recvd[1];
	Pxl_Mode_Info pxl_mode_info;

	//send_serial( usb2000_fd, cmdp, strlen(cmdp) );
	send_usb2000_packet(QSP_ARG  cmdp,strlen(cmdp));

	if( get_STX(SINGLE_QSP_ARG) < 0 )
		return -1;


	if( data_strg_mode == DISABLE ) {
		if( ( n = get_spectrum(QSP_ARG  sdp, n_spec_recvd, &pxl_mode_info) ) < 0 )
			return -1;

		/* In check sum mode the check sum is transmitted after the
		 * spectrum terminating header.
		 */

		if(chk_sum_mode == ENABLE) {
			check_sum = n;

			if(!ascii_mode) {

				for( i=0; i<2; i++) {
					if( ( data_recvd = recv_a_byte(SINGLE_QSP_ARG) ) < 0 )
						return -1;

					tmp[i] = (u_char)data_recvd;
				}

				sprintf(tmp, "%.2x%.2x", tmp[0], tmp[1]);

				tmp[4] = '\0';

				device_check_sum = strtol( tmp, NULL, 16 );

#ifdef DEBUG
sprintf(ERROR_STRING, "check_sum(received): 0x%x ", check_sum );
advise(ERROR_STRING);
#endif /* DEBUG */
				if( device_check_sum != check_sum ) {
					sprintf(ERROR_STRING, "ERROR: Unexpected check sum(0x%x) instead of 0x%x",
						check_sum, device_check_sum );
					WARN(ERROR_STRING);
					return -1;
				}

			} else {
				if( recv_a_value(SINGLE_QSP_ARG) != 0 )
					return -1;
			}
		}
	}

	if( get_tail(SINGLE_QSP_ARG) < 0 )
		return -1;

#ifdef DEBUG
if( debug & usb2000_debug ){
sprintf(ERROR_STRING,"case:%d n:%d x:%d y:%d",pxl_mode_info.pxl_case,pxl_mode_info.n ,pxl_mode_info.x, pxl_mode_info.y);
advise(ERROR_STRING);

for(i=0;i<10;i++) {
sprintf(ERROR_STRING,"pixel(%d):%d",i,pxl_mode_info.pixels[i]);
advise(ERROR_STRING);
}
}
#endif /* DEBUG */

	do_wavlen_crktion(sdp, n_spec_recvd[0], &pxl_mode_info);
	do_non_linear_crktion(sdp, n_spec_recvd[0]);

	return n_spec_recvd[0];
}