本文整理汇总了C++中QSerialPortInfo类的典型用法代码示例。如果您正苦于以下问题:C++ QSerialPortInfo类的具体用法?C++ QSerialPortInfo怎么用?C++ QSerialPortInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSerialPortInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
bool SerialCommandQueue::open(QSerialPortInfo info)
{
if (isConnected()) {
qCritical("Already connected to serial device");
return false;
}
qDebug() << "connecting to " << info.portName();
#if defined(Q_OS_OSX)
// Note: This should be info.portName(). Changed here as a workaround for:
// https://bugreports.qt.io/browse/QTBUG-45127
serial->setPortName(info.systemLocation());
#else
serial->setPortName(info.portName());
#endif
serial->setBaudRate(QSerialPort::Baud115200);
if (!serial->open(QIODevice::ReadWrite)) {
qDebug() << "Could not connect to serial device. Error: " << serial->error()
<< serial->errorString();
return false;
}
return true;
}
示例2: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->console->clear();
timerMOTOR = new QTimer(this);
ui->comboBox_baundrate->addItem("57600",QSerialPort::Baud57600);
ui->comboBox_baundrate->addItem("9600",QSerialPort::Baud9600);
for(QSerialPortInfo port : QSerialPortInfo::availablePorts())
ui->comboBox_port->addItem(port.portName(),port.description());
serialhandler = new SerialHandler(this);
connect(serialhandler,SIGNAL(console(QString)),ui->console,SLOT(insertPlainText(QString)));
connect(serialhandler,SIGNAL(motor1(int)),ui->bar_m1,SLOT(setValue(int)));
connect(serialhandler,SIGNAL(motor2(int)),ui->bar_m2,SLOT(setValue(int)));
connect(serialhandler,SIGNAL(motor3(int)),ui->bar_m3,SLOT(setValue(int)));
connect(serialhandler,SIGNAL(motor4(int)),ui->bar_m4,SLOT(setValue(int)));
ui->pushButton_connect->click();
}
示例3: settings
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;
}
示例4: foreach
foreach (const QSerialPortInfo &info, BlinkyTape::findBlinkyTapeBootloaders()) {
report.append(" " + info.portName() + "\r");
report.append(" Manufacturer: " + info.manufacturer() + "\r");
report.append(" Description: " + info.description() + "\r");
report.append(" VID: 0x" + QString::number(info.vendorIdentifier(),16) + "\r");
report.append(" PID: 0x" + QString::number(info.productIdentifier(),16) + "\r");
}
示例5: QSerialPortInfo
void StatusBar::setDeviceInfo(const QSerialPort *port)
{
QSerialPortInfo info = QSerialPortInfo(*port);
if (info.isValid()) {
QString deviceInfo = QString("%1 %2 @%3").arg(info.manufacturer()).arg(info.description()).arg(info.portName());
m_lb_deviceName->setText(deviceInfo);
}
}
示例6: 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());
}
}
示例7: foreach
// Found the available ports, associated vendor id and product id
foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
if(serialPortInfo.vendorIdentifier() == found_vendorID){
if(serialPortInfo.productIdentifier() == found_productID){
arm_portname = serialPortInfo.portName();
arm_port_is_available = true;
}
}
}
}
示例8: PrintPortInfo
QT_USE_NAMESPACE
void CardReader::PrintPortInfo(const QSerialPortInfo &info)
{
QTextStream cout(stdout);
cout << "Name : " << info.portName() << endl
<< "Description : " << info.description() << endl
<< "Manufacturer: " << info.manufacturer() << endl
<< "Is busy : " << info.isBusy() << endl
<< endl;
}
示例9: QWidget
serialportconnectioncontrols::serialportconnectioncontrols(QWidget *parent) :
QWidget(parent),
ui(new Ui::serialportconnectioncontrols)
{
ui->setupUi(this);
connected = false;
QList <QSerialPortInfo> ports = portInfo.availablePorts();
QSerialPortInfo tmp;
for(int i=0;i<ports.size();i++)
{
tmp = ports.at(i);
ui->PortBox->addItem(tmp.portName());
}
autoconnect = true;
}
示例10: QSerialPort
/*!
* \brief Rs232DevicePrivate::Rs232DevicePrivate - CTor
* \param info
* \param parent
*/
Rs232DevicePrivate::Rs232DevicePrivate(const QSerialPortInfo &info, QObject *parent) :
QSerialPort(info, parent)
{
m_debug = false;
qDebug() << headDebug << "CTor" << info.portName();
// Faccio partire un timer: se entro il suo timeout non ho trovato il converter mi autodistruggo
connect (&m_timerAutodelete, SIGNAL(timeout()), this, SLOT(deleteLater()));
m_timerAutodelete.start(2000);
connect (&m_timerSendGetId, SIGNAL(timeout()), this, SLOT(sendMsgGetId()));
// Sono riuscito a configurare la porta?
if (configPort())
{
// Si, la porta e' fisica e non virtuale.
m_statoParser = STATO_RS232_DLE_STX;
m_checksum = 0;
connect(this, SIGNAL(error(QSerialPort::SerialPortError)),
this, SLOT(errorSlot(QSerialPort::SerialPortError)));
connect(this, SIGNAL(readyRead()), this, SLOT(fromDeviceSlot()));
// Spedisco il messaggio per sapere se e' collegato un converter
sendMsgGetId();
}
}
示例11: foreach
foreach (QSerialPortInfo info, QSerialPortInfo::availablePorts())
{
//QListWidgetItem * item = new QListWidgetItem( info.portName(),this->ui->list);
QListWidgetItem * item = new QListWidgetItem( info.portName());
this->ui->list->addItem(item);
item->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable);
item->setCheckState(Qt::Checked);
}
示例12: operator
bool operator() (const QSerialPortInfo &serialPortInfo) const
{
return serialPortInfo.portName() == m_serialPortName;
}
示例13: sortPorts
bool sortPorts(QSerialPortInfo const & s1, QSerialPortInfo const & s2)
{
return s1.portName() < s2.portName();
}
示例14: SetPercentage
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 "";
}
示例15: 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;
}