ComediAnalogOutputSoftCal::ComediAnalogOutputSoftCal(const char *deviceFile, uint outputSubdevice, uint writeChannel, double outputConversionFactor, uint aref, bool resetOutput) : ComediAnalogIOSoftCal(deviceFile, outputSubdevice, &writeChannel, 1, PLUS_MINUS_TEN, aref), m_outputConversionFactor(outputConversionFactor), m_resetOutput(resetOutput) { Logger(Debug, "ComediAnalogOutputSoftCal::ComediAnalogOutputSoftCal()\n"); int flag = comedi_get_softcal_converter(m_subdevice, m_channels[0], m_range, COMEDI_FROM_PHYSICAL, m_calibration, &m_converter); if (flag != 0) { Logger(Critical, "comedi_get_softcal_converter: %s.\n", comedi_strerror(comedi_errno())); throw "Error in comedi_get_softcal_converter()"; } #ifdef TRIM_ANALOG_OUTPUT // get physical data range for subdevice (min, max, phys. units) m_dataRange = comedi_get_range(m_device, m_subdevice, m_channels[0], m_range); Logger(Debug, "Range for 0x%x (%s):\n\tmin = %g\n\tmax = %g\n", m_dataRange, (m_dataRange->unit == UNIT_volt ? "volts" : "milliamps"), m_dataRange->min, m_dataRange->max); if(m_dataRange == NULL) { Logger(Critical, "comedi_get_range: %s.\n", comedi_strerror(comedi_errno())); throw "Error in comedi_get_range()"; } #endif }
static comedi_polynomial_t *facq_comedi_misc_get_polynomial_soft(comedi_t *dev,guint subindex,const FacqChanlist *chanlist,comedi_calibration_t *cc,GError **err) { comedi_polynomial_t *p = NULL; guint iochans_n = 0, i = 0; guint chanspec = 0, chan = 0, range = 0; enum comedi_conversion_direction *dir = NULL; iochans_n = facq_chanlist_get_io_chans_n(chanlist); p = g_new0(comedi_polynomial_t,iochans_n); dir = facq_chanlist_get_comedi_conversion_direction_list(chanlist,NULL); for(i = 0;i < iochans_n;i++){ chanspec = facq_chanlist_get_io_chanspec(chanlist,i); facq_chanlist_chanspec_to_src_values(chanspec, &chan,&range, NULL,NULL); if( comedi_get_softcal_converter(subindex, chan, range, dir[i], cc, &p[i]) < 0){ g_set_error_literal(err,FACQ_COMEDI_MISC_ERROR, FACQ_COMEDI_MISC_ERROR_FAILED, comedi_strerror(comedi_errno())); g_free(dir); return NULL; } } g_free(dir); return p; }
ComediAnalogInputSoftCal::ComediAnalogInputSoftCal(const char *deviceFile, uint inputSubdevice, uint readChannel, double inputConversionFactor, uint range, uint aref) : ComediAnalogIOSoftCal(deviceFile, inputSubdevice, &readChannel, 1, range, aref), m_inputConversionFactor(inputConversionFactor) { Logger(Debug, "ComediAnalogInputSoftCal::ComediAnalogInputSoftCal()\n"); int flag = comedi_get_softcal_converter(m_subdevice, m_channels[0], m_range, COMEDI_TO_PHYSICAL, m_calibration, &m_converter); if (flag != 0) { Logger(Critical, "comedi_get_softcal_converter: %s.\n", comedi_strerror(comedi_errno())); throw "Error in comedi_get_softcal_converter()"; } }
AnalogyAnalogOutputSoftCal::AnalogyAnalogOutputSoftCal(const char *deviceFile, uint outputSubdevice, uint writeChannel, double outputConversionFactor, uint aref, bool resetOutput) : AnalogyAnalogIOSoftCal(deviceFile, outputSubdevice, &writeChannel, 1, PLUS_MINUS_TEN, aref), m_outputConversionFactor(outputConversionFactor), m_resetOutput(resetOutput) { Logger(Debug, "AnalogyAnalogOutputSoftCal::AnalogyAnalogOutputSoftCal()\n"); int flag = comedi_get_softcal_converter(m_subdevice, m_channels[0], m_range, COMEDI_FROM_PHYSICAL, m_calibration, &m_converter); if (flag != 0) { Logger(Critical, "Unable to get converter for sw-calibrated device.\n"); throw "Error in comedi_get_softcal_converter()"; } }
int cal() { int subdevai, subdevao; // printf("calibrating.."); fflush(stdout); devc = comedi_open("/dev/comedi0"); if (!devc) { printf("Unable to open (6071) %s.\n", "/dev/comedi0"); return 1; } subdevai = comedi_find_subdevice_by_type(devc, COMEDI_SUBD_AI, 0); subdevao = comedi_find_subdevice_by_type(devc, COMEDI_SUBD_AO, 0); comcal = comedi_parse_calibration_file("/usr/var/lib/comedi/calibrations/ni_pcimio_pci-6289_comedi0"); comedi_get_softcal_converter(subdevai,0, 0, COMEDI_TO_PHYSICAL, comcal, &conv_ai); comedi_get_softcal_converter(subdevao,0, 0, COMEDI_FROM_PHYSICAL, comcal, &conv_ao); //comedi_cleanup_calibration_file(cal); comedi_close(devc); //printf("done\n");fflush(stdout); return 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; }