示例#1
0
//**********************************************************************************************************************
SimpleTerminal::SimpleTerminal(QSerialPort *port, QObject *parent) :
    QObject(parent),
    _statusText(QString()),
    _port(port),
    _som(""),
    _eom("\r"),
    _inputHistory(),
    _inputHistoryIdx(-1),
    _is_msg_open(false),
    _cmdParser(nullptr)
{
    Q_CHECK_PTR(_port);

    _cmdParser = new CommandParser(*this);

    // Restore settings
    restoreSettings();

    refreshStatusText();

    QObject::connect(_port, SIGNAL(readyRead()), this, SLOT(read()));
    QObject::connect(_port, SIGNAL(baudRateChanged(qint32,QSerialPort::Directions)), this, SLOT(settingsChanged()));
    QObject::connect(_port, SIGNAL(dataBitsChanged(QSerialPort::DataBits)), this, SLOT(settingsChanged()));
    QObject::connect(_port, SIGNAL(flowControlChanged(QSerialPort::FlowControl)), this, SLOT(settingsChanged()));
    QObject::connect(_port, SIGNAL(parityChanged(QSerialPort::Parity)), this, SLOT(settingsChanged()));
    QObject::connect(_port, SIGNAL(stopBitsChanged(QSerialPort::StopBits)), this, SLOT(settingsChanged()));
    QObject::connect(this, SIGNAL(somChanged()), this, SLOT(settingsChanged()));
    QObject::connect(this, SIGNAL(eomChanged()), this, SLOT(settingsChanged()));

}
示例#2
0
/*!
    \property QSerialPort::flowControl
    \brief the desired flow control mode

    If the setting is successful, returns true; otherwise returns false and sets
    an error code which can be obtained by accessing the value of the
    QSerialPort::error property.
*/
bool QSerialPort::setFlowControl(FlowControl flow)
{
    Q_D(QSerialPort);

    if (d->setFlowControl(flow)) {
        if (d->flow != flow) {
            d->flow = flow;
            emit flowControlChanged(d->flow);
        }
        return true;
    }

    return false;
}
示例#3
0
/*!
    \property QSerialPort::flowControl
    \brief the desired flow control mode

    If the setting is successful or set before opening the port, returns true;
    otherwise returns false and sets an error code which can be obtained by
    accessing the value of the QSerialPort::error property.

    \note If the setting is set before opening the port, the actual serial port
    setting is done automatically in the \l{QSerialPort::open()} method right
    after that the opening of the port succeeds.

    The default value is NoFlowControl, i.e. no flow control.
*/
bool QSerialPort::setFlowControl(FlowControl flowControl)
{
    Q_D(QSerialPort);

    if (!isOpen() || d->setFlowControl(flowControl)) {
        if (d->flowControl != flowControl) {
            d->flowControl = flowControl;
            emit flowControlChanged(d->flowControl);
        }
        return true;
    }

    return false;
}
示例#4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //вывод ошибок в log
    connect(&port,SIGNAL(error(QString)),this,SLOT(printErrorMessage(QString)));

    connect(ui->send_pushButton,SIGNAL(clicked()),this,SLOT(sendMessage()));
    connect(ui->run_button,SIGNAL(clicked()),this,SLOT(runScript()));
    connect(ui->comPort_comboBox,SIGNAL(currentTextChanged(QString)),&port,SLOT(serialPortChanged(QString)));

    //получение списка всех портов и добавление их в comPort_comboBox
    foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
       ui->comPort_comboBox->addItem(info.portName(),Qt::DisplayRole);

    //привязка изменения настроек в интерфейсе к сетерам
    connect(ui->bitsRate_comboBox,SIGNAL(currentTextChanged(QString)),&port,SLOT(baudRateChanged(QString)));
    connect(ui->parity__comboBox,SIGNAL(currentTextChanged(QString)),&port,SLOT(parityChanged(QString)));
    connect(ui->dataBits_comboBox,SIGNAL(currentTextChanged(QString)),&port,SLOT(dataBitsChanged(QString)));
    connect(ui->stopBits_comboBox,SIGNAL(currentTextChanged(QString)),&port,SLOT(stopBitsChanged(QString)));
    connect(ui->flowControl_comboBox,SIGNAL(currentTextChanged(QString)),&port,SLOT(flowControlChanged(QString)));
    connect(ui->comPort_comboBox,SIGNAL(currentTextChanged(QString)),this,SLOT(setDefault(QString)));
    //ввывод ошибок в log
    connect(&port,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(error(QSerialPort::SerialPortError)));
    //добавление в всех возможных вариантов настроек в интерфейс
    ui->bitsRate_comboBox->addItems(comPortSettings::bitsRates);
    ui->dataBits_comboBox->addItems(comPortSettings::dataBits);
    ui->parity__comboBox->addItems(comPortSettings::parityBits);
    ui->stopBits_comboBox->addItems(comPortSettings::stopBits);
    ui->flowControl_comboBox->addItems(comPortSettings::flowControl);
    setDefault("");

    QFileDialog* fileDialog = new QFileDialog(this,QString("Open Script"),QString(""),QString("*.txt"));
    connect(ui->open_button, SIGNAL(clicked()), fileDialog, SLOT(open()));       //TODO: роскоментить в финальном варианте (а то система тормозит)
    connect(fileDialog, SIGNAL(fileSelected(QString)), ui->filePath_lineEdit,    //поєднання підтверження вибору файлу та завантаження
            SLOT(setText(QString)));
    //привязка действий к кнопкам выбора режима
    connect(ui->hex_radioButton,SIGNAL(clicked()),this,SLOT(setHexMode()));
    connect(ui->text_radioButton,SIGNAL(clicked()),this,SLOT(setTextMode()));
    emit ui->hex_radioButton->clicked();
    //слушаем порт
    connect(&port,SIGNAL(readData(QString)),this,SLOT(printReceivedMessage(QString)));
    loadSettings();
}