Exemplo n.º 1
0
/**
 * facq_comedi_misc_test_calibrated:
 * @dev: A comedi_t device.
 * @err: A #GError.
 *
 * Checks if the comedi device @dev, has been calibrated or not.
 * If a device was calibrated, a file with the calibration data
 * should exist. This function checks for this file.
 *
 * Returns: %TRUE if calibrated, %FALSE in other case.
 *
 * <para>
 * <note>
 * A malicious user can delete the file after the check is done,
 * but the comedi functions can deal with that. This is a simple
 * check.
 * </note>
 * </para>
 */
gboolean facq_comedi_misc_test_calibrated(comedi_t *dev,GError **err)
{
	gchar *cal_filename = NULL;
	gboolean ret = FALSE;

	cal_filename = comedi_get_default_calibration_path(dev);
	if(!cal_filename){
		g_set_error_literal(err,FACQ_COMEDI_MISC_ERROR,
					FACQ_COMEDI_MISC_ERROR_FAILED,
				comedi_strerror(comedi_errno()));
		g_free(cal_filename);
		return FALSE;
	}
	ret = g_file_test(cal_filename,G_FILE_TEST_EXISTS);
	g_free(cal_filename);
	return ret;
}
Exemplo n.º 2
0
bool ComediAnalogIOSoftCal::readCalibration()
{
        Logger(Debug, "ComediAnalogIOSoftCal::readCalibration()\n");
        m_calibrationFile = comedi_get_default_calibration_path(m_device);
        if (m_calibrationFile == NULL) {
                Logger(Critical, "comedi_get_default_calibration_path: %s.\n", comedi_strerror(comedi_errno()));
                return false;
        }
        else {
                Logger(Debug, "Using calibration file [%s].\n", m_calibrationFile);
        }

        m_calibration = comedi_parse_calibration_file(m_calibrationFile);
        if (m_calibration == NULL) {
                Logger(Critical, "comedi_parse_calibration_file: %s.\n", comedi_strerror(comedi_errno()));
                return false;
        }
        else {
                Logger(Debug, "Successfully parsed calibration file [%s].\n", m_calibrationFile);
        }
        return true;
}
Exemplo n.º 3
0
bool AnalogyAnalogIOSoftCal::readCalibration()
{
        Logger(Debug, "AnalogyAnalogIOSoftCal::readCalibration()\n");
        m_calibrationFile = comedi_get_default_calibration_path(m_device);
        if (m_calibrationFile == NULL) {
                Logger(Critical, "Unable to find a calibration file for [%s].\n", deviceFile());
                return false;
        }
        else {
                Logger(Debug, "Using calibration file [%s].\n", m_calibrationFile);
        }

        m_calibration = comedi_parse_calibration_file(m_calibrationFile);
        if (m_calibration == NULL) {
                Logger(Critical, "Unable to parse calibration file [%s].\n", m_calibrationFile);
                return false;
        }
        else {
                Logger(Debug, "Successfully parsed calibration file [%s].\n", m_calibrationFile);
        }
        return true;
}
Exemplo n.º 4
0
/**
 * facq_comedi_misc_get_polynomial:
 * @dev: A comedi_t device.
 * @subindex: The subdevice index.
 * @chanlist: A #FacqChanlist object.
 * @err: A #GError.
 *
 * The functions makes some magic to obtain a per channel,
 * comedi_polynomial_t array. Each polynomial can be used
 * to convert from comedi data to physical samples.
 * See <function>comedi_to_physical()</function> for more 
 * info.
 *
 * Returns: An array of comedi_polynomial_t members. Free it
 * when it's no longer needed. %NULL in case of error.
 * The array length equals the number of I/O Channels in the
 * chanlist.
 */
comedi_polynomial_t *facq_comedi_misc_get_polynomial(comedi_t *dev,guint subindex,const FacqChanlist *chanlist,GError **err)
{
	guint subd_flags = 0;
	guint i = 0, chan = 0, range = 0, aref = 0, iochans_n = 0;
	guint chanspec = 0;
	gchar *cal_filename = NULL;
	comedi_calibration_t *cc = NULL;
	GError *local_err = NULL;
	comedi_polynomial_t *p = NULL;

	g_return_val_if_fail(FACQ_IS_CHANLIST(chanlist),NULL);
	iochans_n = facq_chanlist_get_io_chans_n(chanlist);
	if(iochans_n < 1){
		g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR,
			FACQ_COMEDI_MISC_ERROR_FAILED,
				"Chanlist is empty");
		goto error;
	}
	cal_filename = comedi_get_default_calibration_path(dev);
	if(!cal_filename){
		g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR,
			FACQ_COMEDI_MISC_ERROR_FAILED,
				comedi_strerror(comedi_errno()));
		goto error;
	}
	cc = comedi_parse_calibration_file(cal_filename);
	if(!cc){
		g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR,
			FACQ_COMEDI_MISC_ERROR_FAILED,
				comedi_strerror(comedi_errno()));
		goto error;
	}
	g_free(cal_filename);
	subd_flags = comedi_get_subdevice_flags(dev,subindex);
	if(subd_flags < 0){
		g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR,
			FACQ_COMEDI_MISC_ERROR_FAILED,
				comedi_strerror(comedi_errno()));
		goto error;
	}
	for(i = 0;i < iochans_n;i++){
		chanspec = facq_chanlist_get_io_chanspec(chanlist,i);
		facq_chanlist_chanspec_to_src_values(chanspec,
						     &chan,
						     &range,
						     &aref,
						     NULL);
		if( comedi_apply_parsed_calibration(dev,subindex,
						chan,
						range,
						aref,
						cc) < 0){
			g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR,
				FACQ_COMEDI_MISC_ERROR_FAILED,
					comedi_strerror(comedi_errno()));
			goto error;
		}
	}
	if(subd_flags & SDF_SOFT_CALIBRATED){
		p = facq_comedi_misc_get_polynomial_soft(dev,
							 subindex,
							 chanlist,
							 cc,
							 &local_err);
		comedi_cleanup_calibration(cc);
	}
	else {
		comedi_cleanup_calibration(cc);
		p = facq_comedi_misc_get_polynomial_hard(dev,
							 subindex,
							 chanlist,
							 &local_err);
	}
	if(!p)
		goto error;

	return p;

	error:
	if(cal_filename)
		g_free(cal_filename);
	if(cc)
		comedi_cleanup_calibration(cc);
	if(local_err)
		g_propagate_error(err,local_err);
	return NULL;
}
Exemplo n.º 5
0
int DaqDevice::DAQcalibration(int subdev,int channel,int range_idx)
{
    int retval;
    int flags;
    comedi_calibration_t* parsed_calibration;
    comedi_polynomial_t* converter;
    comedi_conversion_direction options;

    if (COMEDI_AN_IN_SUB == subdev)
    {
	converter = &_converter_an_input[channel];
	options = COMEDI_TO_PHYSICAL;
    }
	
    else if (COMEDI_AN_OUT_SUB == subdev)
    {
	converter = &_converter_an_output[channel];
	options = COMEDI_FROM_PHYSICAL;
    }	
    else 
	return COMEDI_ERROR;

    flags = comedi_get_subdevice_flags(_dev, subdev);
    if(flags < 0)
    {
        return COMEDI_ERROR;
    }
    if(flags & SDF_SOFT_CALIBRATED) /* board uses software calibration */
    {
        char *calibration_file_path = comedi_get_default_calibration_path(_dev);

        /* parse a calibration file which was produced by the
                comedi_soft_calibrate program */
        parsed_calibration = comedi_parse_calibration_file(calibration_file_path);
        if(parsed_calibration == NULL)
        {
            return COMEDI_ERROR;
        }

        /* get the comedi_polynomial_t for the subdevice/channel/range
                we are interested in */

        retval = comedi_get_softcal_converter(subdev, channel, range_idx,
                                              options, parsed_calibration, converter);

        comedi_cleanup_calibration(parsed_calibration);
       

        if(retval < 0)
        {
            return COMEDI_ERROR;
        }
    }else /* board uses hardware calibration */
    {
        retval = comedi_get_hardcal_converter(_dev, subdev, channel, range_idx,
                                              options, converter);
        if(retval < 0)
        {
            return COMEDI_ERROR;
        }
    }

    return COMEDI_OK;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
	int i;
	struct board_struct *this_board;
	int device_status = STATUS_UNKNOWN;
	calibration_setup_t setup;
	int retval;
	parsed_options_t options;

	memset( &setup, 0, sizeof( setup ) );
	setup.sv_settling_time_ns = 99999;
	setup.sv_order = 10;

	memset( &options, 0, sizeof( options ) );
	options.do_dump = 0;
	options.do_reset = 0;
	options.do_calibrate = -1;
	options.do_results = 0;
	options.do_output = 1;
	options.file_path = "/dev/comedi0";
	parse_options( argc, argv, &options );
	verbose = options.verbose;

	setup.dev = comedi_open( options.file_path );
	if( setup.dev == NULL ) {
		fprintf( stderr, "comedi_open() failed, with device file name: %s\n",
			options.file_path );
		comedi_perror("comedi_open");
		exit(0);
	}

	if( options.save_file_path == NULL )
		options.save_file_path = comedi_get_default_calibration_path( setup.dev );
	if(!options.driver_name)
		options.driver_name = comedi_get_driver_name( setup.dev );
	if(!options.device_name)
		options.device_name = comedi_get_board_name( setup.dev );

	setup.ad_subdev=comedi_find_subdevice_by_type( setup.dev,COMEDI_SUBD_AI,0);
	setup.da_subdev=comedi_find_subdevice_by_type( setup.dev,COMEDI_SUBD_AO,0);
	setup.caldac_subdev=comedi_find_subdevice_by_type( setup.dev,COMEDI_SUBD_CALIB,0);
	setup.eeprom_subdev=comedi_find_subdevice_by_type( setup.dev,COMEDI_SUBD_MEMORY,0);

	for(i=0;i<n_drivers;i++){
		if(!strcmp(drivers[i].name,options.driver_name)){
			this_board = drivers+i;
			goto ok;
		}
	}
	fprintf(stderr, "Driver %s unknown\n", options.driver_name);
	return 1;

ok:

	retval = this_board->init_setup( &setup, options.device_name );
	if( retval < 0 ){
		fprintf(stderr, "init_setup() failed for %s\n", options.device_name );
		return 1;
	}
	device_status = setup.status;

	if(device_status<STATUS_DONE){
		printf("Warning: device may not be not fully calibrated due to "
			"insufficient information.\n"
			"Please file a bug report at https://bugs.comedi.org/ and attach this output.\n"
			"This output will also allow comedi_calibrate to execute more\n"
			"quickly in the future.\n");
		if(verbose<1){
			verbose=1;
			printf("Forcing option: --verbose\n");
		}
		if(device_status==STATUS_UNKNOWN){
			options.do_reset=1;
			options.do_dump=1;
			options.do_calibrate=0;
			options.do_results=0;
			printf("Forcing options: --reset --dump --no-calibrate --no-results\n");
		}
		if(device_status==STATUS_SOME){
			options.do_reset=1;
			options.do_dump=1;
			options.do_calibrate=1;
			options.do_results=1;
			printf("Forcing options: --reset --dump --calibrate --results\n");
		}
		if(device_status==STATUS_GUESS){
			options.do_reset=1;
			options.do_dump=1;
			options.do_calibrate=1;
			options.do_results=1;
			printf("Forcing options: --reset --dump --calibrate --results\n");
		}
	}
	if(verbose>=0){
		char *s = "$Id: comedi_calibrate.c,v 1.8 2008-01-11 13:29:19 abbotti Exp $";

		printf("%.*s\n",(int)strlen(s)-2,s+1);
		printf("Driver name: %s\n", options.driver_name);
		printf("Device name: %s\n", options.device_name);
		printf("%.*s\n",(int)strlen(this_board->id)-2,this_board->id+1);
		printf("Comedi version: %d.%d.%d\n",
			(comedi_get_version_code(setup.dev)>>16)&0xff,
			(comedi_get_version_code(setup.dev)>>8)&0xff,
			(comedi_get_version_code(setup.dev))&0xff);
	}