Пример #1
0
ComediChan::ComediChan(comedi_t *dev, unsigned minor, unsigned subdev, unsigned chan, unsigned range, unsigned aref, const double * range_override_min, const double * range_override_max, DAQTaskProxy *daq)
  : m_dev(dev), m_minor(minor), m_subdev(subdev), m_chan(chan), m_range(range), m_aref(aref), daq(daq)
{

  m_isdio = m_isai = m_isao = false;

  int t = comedi_get_subdevice_type(m_dev, m_subdev);
  if (t == COMEDI_SUBD_AO) m_isao = true;
  else if (t == COMEDI_SUBD_AI) m_isai = true;
  else if (t == COMEDI_SUBD_DIO) m_isdio = true;
  else {
    err = "Invalid parameters.";
    return;
  }
  if (range_override_min) m_rangeMin = *range_override_min;
  else {
    comedi_range *r = comedi_get_range(dev, subdev, chan, range);
    if (!r) { err = "Invalid parameters."; return; }
    m_rangeMin = r->unit == UNIT_mA ? r->min*1e3 : r->min;
  }
  if (range_override_max) m_rangeMax = *range_override_max;
  else {
    comedi_range *r = comedi_get_range(dev, subdev, chan, range);
    if (!r) { err = "Invalid parameters."; return; }
    m_rangeMax = r->unit == UNIT_mA ? r->max*1e3 : r->max;
  }
  m_maxdata = comedi_get_maxdata(dev, subdev, chan);
  if (!m_maxdata) m_maxdata = 1;
  err = "";
}
Пример #2
0
bool ComediDigitalIO::openDevice()
{
        Logger(Debug, "ComediDigitalIO::openDevice()\n");
        m_device = comedi_open(m_deviceFile);
        if(m_device == NULL) {
                comedi_perror(m_deviceFile);
                return false;
        }
	if (comedi_get_subdevice_type(m_device, m_subdevice) != COMEDI_SUBD_DIO) {
		Logger(Critical, "ComediDigitalIO::openDevice() - Subdevice is not DIO.\n");
		if (!closeDevice())
			Logger(Critical, "ComediDigitalIO::openDevice() - Failed to close device.\n");
		return false;
	}
        return true;
}
Пример #3
0
int main(int argc, char *argv[])
{
	int ret;
	int stype;
	int i;
	struct parsed_options options;

	init_parsed_options(&options);
	options.subdevice = -1;
	parse_options(&options, argc, argv);

	device = comedi_open(options.filename);
	if(!device){
		comedi_perror(options.filename);
		exit(-1);
	}
	if(options.subdevice < 0)
	{
		options.subdevice = comedi_find_subdevice_by_type(device, COMEDI_SUBD_DIO, 0);
		if(options.subdevice < 0){
			fprintf(stderr,"No dio subdevice found.\n");
			exit(-1);
		}
	}
	stype = comedi_get_subdevice_type(device, options.subdevice);
	if(stype != COMEDI_SUBD_DIO){
		printf("%d is not a digital I/O subdevice\n", options.subdevice);
		exit(-1);
	}

	printf("configuring pin %d for output...\n", chan_dat);
	ret = comedi_dio_config(device, options.subdevice, chan_dat, COMEDI_OUTPUT);

	printf("configuring pin %d for output...\n", chan_clk);
	ret = comedi_dio_config(device, options.subdevice, chan_clk, COMEDI_OUTPUT);

	for(i = 0; i < 0x100; i++){
		write_bits(options.subdevice, i);
	}
	//write_bits(0xa5);

	return 0;
}
Пример #4
0
int main(int argc, char *argv[])
{
	int ret;
	int stype;
	struct parsed_options options;

	init_parsed_options(&options);
	parse_options(&options, argc, argv);

	device = comedi_open(options.filename);
	if(!device){
		comedi_perror(options.filename);
		exit(-1);
	}

	stype = comedi_get_subdevice_type(device, options.subdevice);
	if(stype != COMEDI_SUBD_DIO){
		printf("%d is not a digital I/O subdevice\n", options.subdevice);
		exit(-1);
	}

	printf("configuring pin %d on subdevice %d ", options.channel, options.subdevice);
	if(options.value)
	{
		printf("for output.\n");
		ret = comedi_dio_config(device, options.subdevice, options.channel, COMEDI_OUTPUT);
	}else
	{
		printf("for input.\n");
		ret = comedi_dio_config(device, options.subdevice, options.channel, COMEDI_INPUT);
	}
	if(ret < 0){
		comedi_perror("comedi_dio_config");
		exit(-1);
	}
	return 0;
}
Пример #5
0
/**
 * facq_comedi_misc_test_chanlist:
 * @dev: A comedi_t device.
 * @subindex: A subdevice index.
 * @chanlist: A #FacqChanlist object.
 * @err: A #GError.
 *
 * Checks if the provided #FacqChanlist, @chanlist, can be used with
 * the subdevice @subindex, in the device @dev.
 *
 * Returns: %TRUE if supported %FALSE in other case.
 */
gboolean facq_comedi_misc_test_chanlist(comedi_t *dev,guint subindex,const FacqChanlist *chanlist,GError **err)
{
	GError *local_err = NULL;
	guint i = 0, len = 0, iochans_n = 0;
	guint n_channels = 0, n_ranges = 0, subd_flags = 0;
	guint chanspec = 0, chan = 0, range = 0, aref = 0, flags = 0;
	FacqChanDir dir = 0;
	gint subdevice_type = 0;

	g_return_val_if_fail(FACQ_IS_CHANLIST(chanlist),FALSE);
	len = facq_chanlist_get_length(chanlist);
	iochans_n = facq_chanlist_get_io_chans_n(chanlist);
	if(len < 1 || iochans_n == 0){
		g_set_error(&local_err,FACQ_COMEDI_MISC_ERROR,
				FACQ_COMEDI_MISC_ERROR_FAILED,
					"Chanlist needs at least one I/O channel");
		goto error;
	}
	subdevice_type = comedi_get_subdevice_type(dev,subindex);
	if(subdevice_type < 0){
		g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR,
				FACQ_COMEDI_MISC_ERROR_FAILED,
					comedi_strerror(comedi_errno()));
		goto error;
	}
	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;
	}
	n_channels = comedi_get_n_channels(dev,subindex);
	if(n_channels < 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 < len;i++){
		chanspec = facq_chanlist_get_io_chanspec(chanlist,i);
		facq_chanlist_chanspec_to_src_values(chanspec,
							&chan,&range,
								&aref,&flags);
		dir = facq_chanlist_get_io_chan_direction(chanlist,i);
		n_ranges = comedi_get_n_ranges(dev,subindex,chan);
		if(n_ranges < 0){
			g_set_error_literal(&local_err,FACQ_COMEDI_MISC_ERROR,
				FACQ_COMEDI_MISC_ERROR_FAILED,
					comedi_strerror(comedi_errno()));
			goto error;	
		}
		if(!facq_comedi_misc_test_chanspec(n_channels,n_ranges,
						subd_flags,chan,range,
						aref,flags,dir,
						subdevice_type,
						&local_err))
			goto error;
	}
	return TRUE;

	error:
	if(local_err)
		g_propagate_error(err,local_err);
	return FALSE;
}
Пример #6
0
/**
 * @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;
    }