当前位置: 首页>>代码示例>>C++>>正文


C++ QSerialPortInfo::availablePorts方法代码示例

本文整理汇总了C++中QSerialPortInfo::availablePorts方法的典型用法代码示例。如果您正苦于以下问题:C++ QSerialPortInfo::availablePorts方法的具体用法?C++ QSerialPortInfo::availablePorts怎么用?C++ QSerialPortInfo::availablePorts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSerialPortInfo的用法示例。


在下文中一共展示了QSerialPortInfo::availablePorts方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LoadSettings

bool MainWindow::LoadSettings()
{
    bool returnvalue = false;
    QSettings settings("thunderbug","SpherebotSettings");
    settings.beginGroup("settings");
    curFile = settings.value("fileName", "").toString();
    curDir = settings.value("currentDirectory", "").toString();
    qDebug() << "curdir"<< curDir<<endl;
    if(!curFile.isEmpty())
    {
        if(QFile::exists(curFile))
        {
            qDebug()<<"load last file.";
            loadFile(curFile);
            returnvalue = true;
        }
    }
    qDebug()<<"load: "<<curFile;
    QString SavedPortName = settings.value("PortName", "").toString();
    QSerialPortInfo info;
    portList = info.availablePorts();
    for(int i = 0; i < portList.size();i++)
    {
        if(QString::compare(portList.at(i).portName(),SavedPortName) == 0)
        {
            ui->portBox->setCurrentIndex(i);
            bot->connectWithBot(SavedPortName);
        }
    }
    settings.endGroup();
    qDebug()<<"settings loaded: ";
    return returnvalue;
}
开发者ID:marianaleksandrov,项目名称:Spherebot-Host-GUI,代码行数:33,代码来源:mainwindow.cpp

示例2: resetPortList

void MainWindow::resetPortList()
{
    QSerialPortInfo info;
    portList = info.availablePorts();
    ui->portBox->clear();
    for(int i=0;i<portList.size();i++)
    {
        ui->portBox->addItem(portList[i].portName());
    }
}
开发者ID:marianaleksandrov,项目名称:Spherebot-Host-GUI,代码行数:10,代码来源:mainwindow.cpp

示例3: Edit

bool ProjectProperties::Edit(Project * project)
{
	if (project == NULL) {
		return false;
	}
	ok = false;	

	ui.stackedWidget->setCurrentIndex(0);
	ui.menuList->setCurrentRow(0);

	ui.lblName->setText("General options for project '" + project->name + "':");
	
	// set board names combobox
	ui.cbBoardName->clear();
	map <QString, BoardDef>::iterator board;
	for (board = config.boards.begin(); board != config.boards.end() ;board++) {
		ui.cbBoardName->addItem(board->first);
		if (board->first == project->boardName) {
			ui.cbBoardName->setCurrentIndex(ui.cbBoardName->count()-1);
		}
	}
	if (ui.cbBoardName->currentIndex() < 0) {
		if (ui.cbBoardName->count() > 0) {
			ui.cbBoardName->setCurrentIndex(0);
		}
	}	

	// get list of serial ports
	// to do: use QSerialPort

	ui.cbSerialPort->clear();
	ui.cbSerialPort->addItem("N/A");

	QSerialPortInfo serial;
	for (int i=0; i < serial.availablePorts().count();i++) {
		ui.cbSerialPort->addItem(serial.availablePorts().at(i).portName());
	}
	
	/*ui.cbSerialPort->addItem("COM 1");
	ui.cbSerialPort->addItem("COM 2");
	ui.cbSerialPort->addItem("COM 3");
	ui.cbSerialPort->addItem("COM 4");
	ui.cbSerialPort->addItem("COM 5");
	ui.cbSerialPort->addItem("COM 6");
	*/
	ui.cbSerialPort->setCurrentIndex(0);
	for (int i=0; i < ui.cbSerialPort->count(); i++) {
		if (project->serialPort == ui.cbSerialPort->itemText(i)) {
			ui.cbSerialPort->setCurrentIndex(i);
		}
	}

	// populate programmers list
	ui.cbExternalProgrammer->clear();
	map <QString, ProgrammerDef>::iterator prog;
	for (prog = config.programmers.begin(); prog != config.programmers.end(); prog++) {
		ui.cbExternalProgrammer->addItem(prog->first);
		if (prog->first == project->programmer) {
			ui.cbExternalProgrammer->setCurrentIndex(ui.cbExternalProgrammer->count()-1);
		}
	}
	if (ui.cbExternalProgrammer->currentIndex() < 0) {
		if (ui.cbExternalProgrammer->count() > 0) {
			ui.cbExternalProgrammer->setCurrentIndex(0);
		}
	}	

	if (project->programmer == "") {
		ui.rbNoExternalProgrammer->setChecked(true);
		ui.cbExternalProgrammer->setEnabled(false);
	} else {
		ui.rbYesExternalProgrammer->setChecked(true);
		ui.cbExternalProgrammer->setEnabled(true);
	}

	exec();

	if (ok == false) {
		return false;
	}

	project->serialPort = ui.cbSerialPort->itemText(ui.cbSerialPort->currentIndex());
	if (project->serialPort == "N/A") {
		project->serialPort = "";
	}

	if (ui.rbNoExternalProgrammer->isChecked()) {
		project->programmer = "";
	} else {
		project->programmer = ui.cbExternalProgrammer->itemText(ui.cbExternalProgrammer->currentIndex());
	}

	project->boardName = ui.cbBoardName->itemText(ui.cbBoardName->currentIndex());
	
	return true;
}
开发者ID:sherckuith,项目名称:mariamole,代码行数:96,代码来源:projectproperties.cpp

示例4: GetLeonardoSerialPort

QString Builder::GetLeonardoSerialPort(QString defaultPort)
{
    QStringList before, after;
    QSerialPortInfo serialList;
    QSerialPort port;

    SetPercentage(100);

    for (int i=0; i < serialList.availablePorts().count(); i++) {
        before.append(serialList.availablePorts().at(i).portName());
    }

    /*#ifdef Q_OS_WIN
       	PrepareSerialPort(project->serialPort, "1200");
    #endif*/
    port.setPortName(project->serialPort);
    port.setFlowControl(QSerialPort::NoFlowControl);
    port.setBaudRate(QSerialPort::Baud1200);
    port.setParity(QSerialPort::NoParity);
    port.setStopBits(QSerialPort::OneStop);
    port.setDataBits(QSerialPort::Data8);
    bool open = port.open (QIODevice::ReadWrite);
//#endif
    if (open == false) {
        progress->SetPhase(BuildWindowTypes::detectingLeonardo2);
        msg.Add("Could not reset board automatically via serial port " + project->serialPort + "! Press RESET button at your board NOW!", mtWarning);
    }
    /*char buffer[20] = "Hello!\r\n";
    port.write ((const char *)buffer);*/
    //QThread::msleep(10);
    port.close();

    QThread::msleep(100);

    int counter = 50;
    after.clear();
    bool warningMessage = true;
    while (counter > 0) {
        QSerialPortInfo newSerialList;
        for (int i=0; i < newSerialList.availablePorts().count(); i++) {
            after.append(newSerialList.availablePorts().at(i).portName());
        }

        for (int i=0; i < after.count(); i++) {
            if (before.indexOf(after.at(i)) < 0) {
                return after.at(i);
            }
        }
        QThread::msleep(120);
        counter--;

        if ( (progress->value() > 40) && warningMessage) {
            warningMessage = false;
            progress->SetPhase(BuildWindowTypes::detectingLeonardo2);
            msg.Add("Could not reset board automatically via serial port " + project->serialPort + "! Press RESET button at your board NOW!", mtWarning);
        }

        SetPercentage(100 - counter * 2);
        if (GetCancel()) {
            counter = 0;
            break;
        }
    }

    msg.Add("Could not detect Leonardo serial port for programming. Please try pressing the RESET button at your board when you see the dialog message 'Detecting Leonardo port...'!", mtError);
    return "";
}
开发者ID:Ermakov-D,项目名称:mariamole,代码行数:67,代码来源:builder.cpp


注:本文中的QSerialPortInfo::availablePorts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。