Esempio n. 1
0
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    //Initialize the memory map where the data points are buffered, and read the datapoints from it
    tt_buf* buf;
    int timetagger;
    
    if (nrhs == 1 && mxIsDouble(prhs[0])) {
        //If there is only one argument, and it is a double, then change the time tagger number
        //to open
        timetagger = (int)mxGetScalar(prhs[0]);
    } else {
        //If the arguments are wrong, display a help message and exit
        mexErrMsgTxt("Inputs:\n\tNumber of timetagger (starting from 0) to open.\nOutputs:\n\tResolution of data in seconds per time bin");
        return;
    }

    //Open the time tagger
    buf = tt_open(timetagger);

    if (buf) {
        
        
        plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
        *mxGetPr(plhs[0]) = (double)tt_resolution(buf);
        
        
        //Close the buffer
        tt_close(buf);
        
	} else {
        mexErrMsgTxt("Unable to connect to time tagger - is the timetagger software running?");
	}
}
Esempio n. 2
0
static int
initialize_tooltalk(void) {
  int rcode;

  tt_procid = tt_open();
  if ((rcode = tt_ptr_error(tt_procid)) != TT_OK) {
    return rcode;
  }
  
  if ((rcode = tt_session_join(tt_default_session())) != TT_OK) { 
    return (rcode);
  }    
}
Esempio n. 3
0
/*
 * remover::open_tt()
 */
Tt_status remover::
open_tt()
{
	char *process_id = tt_open();
	Tt_status err = tt_ptr_error( process_id );
	if (err == TT_OK) {
		_process_id = process_id;
		_tt_opened = TRUE;
	} else if (err > TT_WRN_LAST) {
		fprintf( stderr,
			 "%s: tt_open(): %s\n",
			 (char *)_process_name, tt_status_message(err) );
	}
	return err;
}
Esempio n. 4
0
int InitializeTooltalk(void)
{
    char * procid;
    Tt_status status;
    int fd;

    procid = tt_default_procid();
    status = tt_ptr_error(procid);
    if ((status == TT_ERR_NOMP) || (status == TT_ERR_PROCID)) {
	/*
	 * We need to try to establish a connection
	 */
	procid = tt_open();
	status = tt_ptr_error(procid);
	if (status != TT_OK) {
	    ToolTalkError("Could not connect to ToolTalk:\n%s\n", status);
	    return (False);
	}
	tt_free(procid);

	/*
	 * Determine the Tooltalk fildes.
	 */
	fd = tt_fd();
	status = tt_int_error(fd);
	if (status != TT_OK) {
	    ToolTalkError("Could not connect to ToolTalk:\n%s\n", status);
	    tt_close();
	    ttfdG = -1;
	    return(False);
	}
	else {
	    ttfdG = fd;
	}

#ifdef DtActUseXtOverSelect
	/*
	 * Add the ToolTalk file descriptor to the set monitored by Xt
	 */
	XtAddInput(fd, (XtPointer)XtInputReadMask, input_handler, 0);
#endif /* DtActUseXtOverSelect */
    }

    return (True);
}
Esempio n. 5
0
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    tt_buf* buf;
    double* delays;
    
    int timetagger = 0;
    double time = 0.0;
    double dbl_radius = 0.0;
    uint64_t radius = 0;
    

    if (nrhs == 4 && mxIsDouble(prhs[0]) && mxIsDouble(prhs[1]) && mxIsDouble(prhs[2]) && mxIsDouble(prhs[3])) {
        time = mxGetScalar(prhs[0]);
        dbl_radius = mxGetScalar(prhs[1]);
        timetagger = (int)mxGetScalar(prhs[2]);
        radius = (uint64_t)mxGetScalar(prhs[3]);
    } else if (nrhs == 3 && mxIsDouble(prhs[0]) && mxIsDouble(prhs[1]) && mxIsDouble(prhs[2])) {
        time = mxGetScalar(prhs[0]);
        dbl_radius = mxGetScalar(prhs[1]);
        timetagger = (int)mxGetScalar(prhs[2]);
    } else if (nrhs == 2 && mxIsDouble(prhs[0]) && mxIsDouble(prhs[1])) {
        time = mxGetScalar(prhs[0]);
        dbl_radius = mxGetScalar(prhs[1]);
    } else {
        mexErrMsgTxt("Inputs:\n\ttime in seconds to calculate delays from\n\tpulse radius in seconds (coincidence is within +- this)\n\t[optional=0] timetagger to dump from.\n\t[optional]Same as radius, except it is in time bins rather than seconds\nOutputs:\n\tArray of delays between channels");
    }
    
    buf = tt_open(timetagger);
    if (buf) {
        
        plhs[0]=mxCreateDoubleMatrix(1,tt_channels(buf),mxREAL);
        delays = mxGetPr(plhs[0]);
        
        tt_delays(buf,time,dbl_radius,radius,delays);
        
        tt_close(buf);
    } else {
        mexErrMsgTxt("Unable to connect to time tagger - is the timetagger software running?");
    }

}
Esempio n. 6
0
/*
 * rcopier::open_tt()
 */
Tt_status rcopier::
open_tt()
{
	char *process_id = tt_open();
	Tt_status err = tt_ptr_error( process_id );
	if (err == TT_OK) {
		_process_id = process_id;
		_tt_opened = TRUE;
	} else if (err > TT_WRN_LAST) {
		fprintf( stderr,
			 "%s: Could not initialize ToolTalk because %s\n",
			 (char *)_process_name,
#ifndef TT_STATUS_MSG_TO_DO
			 _tt_enumname( (Tt_status)err )
#else
			 tt_status_message( err )
#endif
		       );
	}
	return err;
}
Esempio n. 7
0
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    tt_buf* buffer;
    int timetagger;
    uint64_t datapoints;

    
    uint64_t total;	//The total amount of data in the buffer
    uint64_t i;		//Temporary loop variable
    uint64_t j=0;
    double *channels=NULL, *timebins;
    
    if (nrhs == 2 && mxIsDouble(prhs[0]) && mxIsDouble(prhs[1])) {
        timetagger = (int)mxGetScalar(prhs[0]);
        datapoints = (uint64_t)mxGetScalar(prhs[1]);
    } else {
        mexErrMsgTxt("Inputs:\n\tTime tag buffer to dump from.\n\tNumber of datapoints to dump.\nOutputs:\n\tArray of time stamps\n\tArray of corresponding channels");
        return;
    }
    
    if (datapoints==0) {
        mexErrMsgTxt("No datapoints were specified!");
        return;
    }
    
    buffer = tt_open(timetagger);
    if (buffer) {
        total = tt_datapoints(buffer);
        
        if (datapoints > total) {
            mexPrintf("Warning: Not enough datapoints! Only reading saved datapoints!\n");
            datapoints = total;
        }
        if (datapoints > tt_maxdata(buffer)) {
            mexPrintf("Warning: There are not enough datapoints saved. Only reading to end of buffer!\n");
            datapoints = tt_maxdata(buffer);    //Only read up to the entire buffer
        }

        
        if (nlhs>=2) {
            plhs[0] = mxCreateDoubleMatrix(1,(int)datapoints,mxREAL);
            channels = mxGetPr(plhs[0]);
            plhs[1] = mxCreateDoubleMatrix(1,(int)datapoints,mxREAL);
            timebins = mxGetPr(plhs[1]);
        } else {
            plhs[0] = mxCreateDoubleMatrix(1,(int)datapoints,mxREAL);
            timebins = mxGetPr(plhs[0]);
        }
        
        //Read the array of data
        if (isnan(tt_resolution(buffer))) {
            mexPrintf("Warning: Resolution unset. Returning raw data.\n");
            if (channels) {
                for (i=total-datapoints;i<total;i++) {
                    channels[j] = (double)tt_channel(buffer,i)+1.0;	//Matlab has this weird off by one thing...
                    timebins[j] = (double)tt_tag(buffer,i);
                    j++;
                }
            } else {
                for (i=total-datapoints;i<total;i++) {
                    timebins[j] = (double)tt_tag(buffer,i);
                    j++;
                }
            }
        } else {
            if (channels) {
                for (i=total-datapoints;i<total;i++) {
                    channels[j] = (double)tt_channel(buffer,i)+1.0;	//Matlab has this weird off by one thing...
                    timebins[j] = (double)tt_tag(buffer,i)*tt_resolution(buffer);
                    j++;
                }
            } else {
                for (i=total-datapoints;i<total;i++) {
                    timebins[j] = (double)tt_tag(buffer,i)*tt_resolution(buffer);
                    j++;
                }
            }
        }
        
        
        tt_close(buffer);
        
    } else {
        mexErrMsgTxt("Unable to connect to time tag buffer! Is all necessary software running?");
    }

}