int generic_cal_ao(calibration_setup_t *setup, const generic_layout_t *layout ) { int channel, range, num_ao_ranges, num_ao_channels, retval; comedi_calibration_setting_t *current_cal; if(setup->da_subdev >= 0 && setup->do_output) { assert( comedi_range_is_chan_specific( setup->dev, setup->da_subdev ) == 0 ); num_ao_ranges = comedi_get_n_ranges( setup->dev, setup->da_subdev, 0 ); if( num_ao_ranges < 0 ) return -1; num_ao_channels = comedi_get_n_channels( setup->dev, setup->da_subdev ); if( num_ao_channels < 0 ) return -1; }else num_ao_ranges = num_ao_channels = 0; for( channel = 0; channel < num_ao_channels; channel++ ) { for( range = 0; range < num_ao_ranges; range++ ) { current_cal = sc_alloc_calibration_setting(setup->new_calibration); generic_prep_dac_caldacs( setup, layout, channel, range ); generic_do_dac_channel( setup, layout, setup->new_calibration, current_cal, channel, range ); } } retval = write_calibration_file(setup->cal_save_file_path, setup->new_calibration); return retval; }
int generic_cal_by_range( calibration_setup_t *setup, const generic_layout_t *layout ) { int channel, range, num_ai_ranges, num_ao_ranges, num_ao_channels, retval; comedi_calibration_setting_t *current_cal; int postgain_bip, postgain_unip; assert( comedi_range_is_chan_specific( setup->dev, setup->ad_subdev ) == 0 ); num_ai_ranges = comedi_get_n_ranges( setup->dev, setup->ad_subdev, 0 ); if( num_ai_ranges < 0 ) return -1; if(setup->da_subdev >= 0 && setup->do_output ) { assert( comedi_range_is_chan_specific( setup->dev, setup->da_subdev ) == 0 ); num_ao_ranges = comedi_get_n_ranges( setup->dev, setup->da_subdev, 0 ); if( num_ao_ranges < 0 ) return -1; num_ao_channels = comedi_get_n_channels( setup->dev, setup->da_subdev ); if( num_ao_channels < 0 ) return -1; }else num_ao_ranges = num_ao_channels = 0; if( layout->adc_postgain_offset( 0 ) >= 0 ) { /* bipolar postgain */ current_cal = sc_alloc_calibration_setting(setup->new_calibration); generic_do_adc_postgain_offset( setup, layout, current_cal, 0, 0 ); sc_push_channel( current_cal, SC_ALL_CHANNELS ); for( range = 0; range < num_ai_ranges; range++ ) if( is_bipolar( setup->dev, setup->ad_subdev, 0, range ) ) sc_push_range( current_cal, range ); postgain_bip = setup->caldacs[ layout->adc_postgain_offset( 0 ) ].value; /* unipolar postgain */ if( layout->do_adc_unipolar_postgain ) { current_cal = sc_alloc_calibration_setting(setup->new_calibration); generic_do_adc_postgain_offset( setup, layout, current_cal, 0, 1 ); sc_push_channel( current_cal, SC_ALL_CHANNELS ); } for( range = 0; range < num_ai_ranges; range++ ) if( is_unipolar( setup->dev, setup->ad_subdev, 0, range ) ) sc_push_range( current_cal, range ); postgain_unip = setup->caldacs[ layout->adc_postgain_offset( 0 ) ].value; }else postgain_bip = postgain_unip = -1; for( range = 0; range < num_ai_ranges; range++ ) { current_cal = sc_alloc_calibration_setting(setup->new_calibration); generic_prep_adc_caldacs( setup, layout, 0, range ); if( is_unipolar( setup->dev, setup->ad_subdev, 0, range ) ) update_caldac( setup, layout->adc_postgain_offset( 0 ), postgain_unip ); else update_caldac( setup, layout->adc_postgain_offset( 0 ), postgain_bip ); generic_do_adc_channel( setup, layout, current_cal, 0, range ); sc_push_channel( current_cal, SC_ALL_CHANNELS ); } for( channel = 0; channel < num_ao_channels; channel++ ) { for( range = 0; range < num_ao_ranges; range++ ) { current_cal = sc_alloc_calibration_setting(setup->new_calibration); generic_prep_dac_caldacs( setup, layout, channel, range ); generic_do_dac_channel( setup, layout, setup->new_calibration, current_cal, channel, range ); } } retval = write_calibration_file(setup->cal_save_file_path, setup->new_calibration); return retval; }
/** * @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; }