/** * facq_comedi_misc_can_calibrate * @dev: A comedi_t device. * @subindex: The subdevice index. * @err: A #GError. * * Checks if a subdevice can be calibrated, in affirmative case returns * the supported calibration type. * * Returns: -1 in case of error, 0 if device can't be calibrated, 1 if * device can be soft-calibrated, 2 if device is hard-calibrated. */ gint facq_comedi_misc_can_calibrate(comedi_t *dev,guint subindex,GError **err) { guint subd_flags = 0; GError *local_err = NULL; const gchar *driver_name = NULL; guint i = 0, drivers_len = 6; const gchar * const drivers[] = { "ni_pcimio", "ni_atmio", "ni_mio_cs", "cb_pcidas", "cb_pcidas64", "ni_labpc" }; 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; } if(subd_flags & SDF_SOFT_CALIBRATED) return 1; else { driver_name = comedi_get_driver_name(dev); if(!driver_name){ 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 < drivers_len;i++) if(g_strcmp0(driver_name,drivers[i]) == 0) return 2; } return 0; error: if(local_err) g_propagate_error(err,local_err); return -1; }
/* * facq_comedi_misc_can_poll: * @dev: A comedi_t device. * @err: A #GError NOT optional, check it. * * Some drivers can make the kernel crash when using poll() * with them, we blacklist them here to know if we can do * poll() or not. * * Returns: %TRUE if you can do poll() or %FALSE in the other case. */ gboolean facq_comedi_misc_can_poll(comedi_t *dev,GError **err) { const gchar * const drivers[] = { "comedi_test" }; guint drivers_len = 1, i = 0; const gchar *driver_name = NULL; driver_name = comedi_get_driver_name(dev); if(!driver_name){ g_set_error_literal(err,FACQ_COMEDI_MISC_ERROR, FACQ_COMEDI_MISC_ERROR_FAILED, comedi_strerror(comedi_errno())); return FALSE; } for(i = 0;i < drivers_len;i++) if(g_strcmp0(driver_name,drivers[i]) == 0) return FALSE; return TRUE; }
/** * @brief Get the information from Comedi library * */ void MainWindow::GetComediInfo() { int i,j; int n_subdevices,type; int chan,n_chans; int n_ranges; int subdev_flags; comedi_range *rng; ChannelList.clear(); // at the moment we are using the default device const char optionsfilename[]="/dev/comedi0"; QString DeviceName=AppSettings.value(Key_Comedi_Device_Name).toString(); if (DeviceName.length()<=0) DeviceName=optionsfilename; it = comedi_open(optionsfilename); if(!it) { QMessageBox::warning(this, optionsfilename, tr("Can not open the device\n"), QMessageBox::Ok); }; cbComediDevice->addItem(optionsfilename,1); AppSettings.setValue(Key_Comedi_Device_Name,DeviceName); QString buffer="Overall info:\n"; //buffer+=QString printf(" Version code: 0x%06x\n", comedi_get_version_code(it)); buffer+=QString(" Comedi version code: 0x%06x\n").arg(comedi_get_version_code(it)); buffer+=QString(" Driver name: %1\n").arg(comedi_get_driver_name(it)); buffer+=QString(" Board name: %1\n").arg(comedi_get_board_name(it)); n_subdevices = comedi_get_n_subdevices(it); buffer+=QString(" Number of subdevices: %1\n").arg(n_subdevices); tlComediInfo->setText(buffer); int channel_unique_id=1; // Now scan subdevices for(i = 0; i < n_subdevices; i++) { buffer.clear(); type = comedi_get_subdevice_type(it, i); if(type==COMEDI_SUBD_UNUSED) continue; QTextEdit * tabText=new QTextEdit; buffer+=QString("Subdevice %1\n").arg(i); buffer+=QString("Type: %1 (%2)\n").arg(type).arg(subdevice_types[type]); subdev_flags = comedi_get_subdevice_flags(it, i); QString flagsstring; flagsstring.sprintf("flags: 0x%08x\n",subdev_flags); buffer+=flagsstring; n_chans=comedi_get_n_channels(it,i); buffer+=QString(" Number of channels: %1\n").arg(n_chans); if ((type==1)||(type==2)) // Analog input or output { for(chan=0;chan<n_chans;chan++) { // here! ChannelList.append(AIO_channel(QString(optionsfilename),i,chan,0,type==1,++channel_unique_id)); }; }; if(!comedi_maxdata_is_chan_specific(it,i)) { buffer+=QString(" Maximal data value: %1\n").arg((unsigned long)comedi_get_maxdata(it,i,0)); } else { buffer+=QString(" Maximal data value is channel specific:\n"); for(chan=0;chan<n_chans;chan++) { buffer+=QString(" Channel %1: %2\n").arg(chan).arg ((unsigned long)comedi_get_maxdata(it,i,chan)); } }; buffer+=QString(" ranges:\n"); if (!comedi_range_is_chan_specific(it,i)) { n_ranges=comedi_get_n_ranges(it,i,0); buffer+=QString(" All channels:"); for(j=0;j<n_ranges;j++) { rng=comedi_get_range(it,i,0,j); // buffer+=QString(" [%g,%g]",rng->min,rng->max); buffer+=QString(" [%1,%2]").arg(rng->min).arg(rng->max); } buffer+=QString("\n"); } else { for (chan=0;chan<n_chans;chan++) { n_ranges=comedi_get_n_ranges(it,i,chan); printf(" chan%d:",chan); for(j=0;j<n_ranges;j++) { rng=comedi_get_range(it,i,chan,j); printf(" [%g,%g]",rng->min,rng->max); } printf("\n"); } } tabText->setText(buffer); tabWidget->addTab(tabText,QString("subdevice %1").arg(i)); } //printf(" command:\n"); //get_command_stuff(it,i); tabWidget->setTabText(0,tr("Connections")); // Create channles we might need; all are input channels save one Ini_ImI= new AIO_channel(Key_Im_Input,1); Ini_CmdI= new AIO_channel(Key_Cmd_Input,1); Ini_CmI= new AIO_channel(Key_Cm_Tlgf_Input,1); Ini_GainT= new AIO_channel(Key_Gain_Tlgf_Input,1); Ini_FreqT= new AIO_channel(Key_Freq_Tlgf_Input,1); Ini_LswT= new AIO_channel(Key_Lsw_Tlgf_Input,1); Ini_CmdO= new AIO_channel(Key_Cmd_Output,0); for (int ch=0;ch<ChannelList.count();ch++) { if (ChannelList[ch].is_input) { cbxAI_Im->addItem(ChannelList[ch].Description(),ChannelList[ch].ID()); if (ChannelList[ch]==Ini_ImI) { int zzz=cbxAI_Im->count(); cbxAI_Im->setCurrentIndex(zzz-1); }; cbxAI_Cmd->addItem(ChannelList[ch].Description(),ChannelList[ch].ID()); if (ChannelList[ch]==Ini_CmdI) { cbxAI_Cmd->setCurrentIndex(cbxAI_Cmd->count()-1); }; cbxAI_Cm_tlg->addItem(ChannelList[ch].Description(),ChannelList[ch].ID()); if (ChannelList[ch]==Ini_CmI) { cbxAI_Cm_tlg->setCurrentIndex(cbxAI_Cm_tlg->count()-1); }; cbxAI_Gain_tlg->addItem(ChannelList[ch].Description(),ChannelList[ch].ID()); if (ChannelList[ch]==Ini_GainT){ cbxAI_Gain_tlg->setCurrentIndex(cbxAI_Gain_tlg->count()-1); }; cbxAI_Freq_tlg->addItem(ChannelList[ch].Description(),ChannelList[ch].ID()); if (ChannelList[ch]==Ini_FreqT) { cbxAI_Freq_tlg->setCurrentIndex(cbxAI_Freq_tlg->count()-1); }; cbxAI_Lsw_tlg->addItem(ChannelList[ch].Description(),ChannelList[ch].ID()); if (ChannelList[ch]==Ini_LswT) { cbxAI_Lsw_tlg->setCurrentIndex(cbxAI_Lsw_tlg->count()-1); }; } else { cbxAO_Cmd->addItem(ChannelList[ch].Description(),ChannelList[ch].ID()); if (ChannelList[ch]==Ini_CmdO) { cbxAO_Cmd->setCurrentIndex(cbxAO_Cmd->count()-1); }; }; }; return; }
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); }