Ejemplo n.º 1
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;
    }
Ejemplo n.º 2
0
static int openBoard( int board ) {
    MY_BOARD_HARDWARE *pBoardHard = myHardwareBoardList + board;
    MY_BOARD_SOFTWARE *pBoardSoft = mySoftwareBoardList + board;

    fprintf( stderr, "openBoard[%d]\n", board );
    fprintf( stderr, "sizeof(lsampl_t)=%d\n", sizeof(lsampl_t) );
    fprintf( stderr, "sizeof(sampl_t)=%d\n", sizeof(sampl_t) );

    if (pBoardHard == NULL || pBoardSoft == NULL) return 1;

    pBoardHard->p_comediFileHandle = comedi_open( pBoardHard->devicePath );

    if (pBoardHard->p_comediFileHandle == NULL) {
        fprintf( stderr, "comedi_open failed for board[%d] %s\n", board, pBoardHard->devicePath );
        return 1;
    }
    fprintf( stderr, "opened file\n" );
    
    pBoardHard->subDeviceNumber =
    comedi_find_subdevice_by_type(
        pBoardHard->p_comediFileHandle,
        COMEDI_SUBD_AI,
        0
    );
    
    if (pBoardHard->subDeviceNumber < 0) {
        fprintf( stderr, "subDeviceNum < 0 failed for board[%d]\n", board );
        return 1;
    }
    fprintf( stderr, "get subDevice=%d\n", pBoardHard->subDeviceNumber );

    int subDevFlags = comedi_get_subdevice_flags(
        pBoardHard->p_comediFileHandle,
        pBoardHard->subDeviceNumber
    );
    if (subDevFlags & SDF_PACKED) {
        fprintf( stderr, "subDevice using bit per channel\n" );
    } else {
        if (subDevFlags & SDF_LSAMPL) {
            pBoardHard->valueIsLsampl_t = 1;
            fprintf( stderr, "subDevice using long word lsampl_t per channel\n" );
        } else {
            fprintf( stderr, "subDevice using word sampl_t per channel\n" );
        }
    }

    pBoardHard->buffer_size_in_byte =
    comedi_get_buffer_size(
        pBoardHard->p_comediFileHandle,
        pBoardHard->subDeviceNumber
    );
    fprintf( stderr, "board[%d] hardware buffer size in BYTES=%d\n",
    board, pBoardHard->buffer_size_in_byte );
    if (pBoardHard->buffer_size_in_byte <= 0) {
        fprintf( stderr, "board buffer size faile\n" );
        return 1;
    }

    if (pBoardHard->valueIsLsampl_t) {
        pBoardHard->buffer_size_in_sample = pBoardHard->buffer_size_in_byte / sizeof(lsampl_t);
    } else {
        pBoardHard->buffer_size_in_sample = pBoardHard->buffer_size_in_byte / sizeof(sampl_t);
    }

    pBoardHard->buffer = mmap(
        NULL,
        pBoardHard->buffer_size_in_byte,
        PROT_READ,
        MAP_SHARED,
        comedi_fileno(pBoardHard->p_comediFileHandle),
        0
    );
    if (pBoardHard->buffer == MAP_FAILED) {
        fprintf( stderr, "mmap failed for board[%d]\n", board );
        return 1;
    }

    int numChannel = comedi_get_n_channels(
        pBoardHard->p_comediFileHandle,
        pBoardHard->subDeviceNumber
    );
    if (numChannel != pBoardSoft->numberOfActiveAnalogInputs) {
        fprintf( stderr, "number of channel for board[%d] from comedi=%d harccode=%d\n",
        board, numChannel, pBoardSoft->numberOfActiveAnalogInputs );
    }

#ifdef SUPPORT_CHANNEL_SPECIFIC_RANGE
    pBoardHard->maxDataIsChannelSpecific =
    comedi_maxdata_is_chan_specific(
        pBoardHard->p_comediFileHandle,
        pBoardHard->subDeviceNumber
    );
    pBoardHard->rangeIsChannelSpecific =
    comedi_maxdata_is_chan_specific(
        pBoardHard->p_comediFileHandle,
        pBoardHard->subDeviceNumber
    );
    if (pBoardHard->maxDataIsChannelSpecific) {
        fprintf( stderr, "board[%d] supports different max data per channel\n", board );
    }
    if (pBoardHard->rangeIsChannelSpecific) {
        fprintf( stderr, "board[%d] supports different range per channel\n", board );
    }
#endif

    return 0;
}