Exemplo n.º 1
0
/**
 * @brief KWP2000
 *
 * @param parent
 */
kwp2000::kwp2000(QObject *parent) :
    QObject(parent),
    destModule(-1),
    normRecvTimeout(100),
    diagSession(0)
{
    elmThread = new QThread(this);
    tpThread = new QThread(this);

    elm = new elm327();
    tp = new tp20(elm);

    elm->moveToThread(elmThread);
    tp->moveToThread(tpThread);

    elmThread->start();
    tpThread->start();

    connect(tp, SIGNAL(response(QByteArray*)), this, SLOT(recvKWP(QByteArray*)));

    connect(elm, SIGNAL(log(QString, int)), this, SIGNAL(log(QString, int)));
    connect(tp, SIGNAL(log(QString, int)), this, SIGNAL(log(QString, int)));
    connect(tp, SIGNAL(elmInitDone(bool)), this, SIGNAL(elmInitDone(bool)));
    connect(elm, SIGNAL(portClosed()), this, SIGNAL(portClosed()));
//    connect(elm, SIGNAL(receivedData()), &longloop, SLOT(quit()));

    connect(tp, SIGNAL(channelOpened(bool)), this, SLOT(channelOpenedClosed(bool)));
    connect(tp, SIGNAL(channelOpened(bool)), this, SIGNAL(channelOpened(bool)));

    initModuleNames();
    initResponseCodes();
}
QSerialConsoleWindow::QSerialConsoleWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::QSerialConsoleWindow)
{
    ui->setupUi(this);
    _portSettingsDialog = new QDialog(this);
    _dialogButtonBox = new QDialogButtonBox(_portSettingsDialog);
    _mainLayout = new QVBoxLayout(_portSettingsDialog);
    _serialPort = new QSerialDevice();
    addToolBar(_serialPort->toolbar());
    _dialogButtonBox->addButton(QDialogButtonBox::Ok);
    _portSettingsDialog->setWindowTitle("Port Settings");
    _mainLayout->addWidget(_serialPort->widget());
    _mainLayout->addWidget(_dialogButtonBox);
    _protocol = new Protocol();

    _consoleWidget = new QConsoleWidget(ui->consoleFrame);
    _consoleWidget->showBanner("Welcome to QSerialConsole v 1.0\n");
    portClosed();

    connect(_serialPort, SIGNAL(portOpened()), this, SLOT(portOpened()));
    connect(_serialPort, SIGNAL(portClosed()), this, SLOT(portClosed()));
    connect(_serialPort, SIGNAL(msgAvailable(QByteArray)), _protocol, SLOT(decode(QByteArray)));
    connect(_protocol, SIGNAL(dataDecoded(QByteArray)), _consoleWidget, SLOT(showIncomingMessage(QByteArray)));
    connect(_consoleWidget, SIGNAL(newOutgoingMessage(QByteArray)), _protocol, SLOT(encode(QByteArray)));
    connect(_protocol, SIGNAL(dataEncoded(QByteArray)), _serialPort, SLOT(write(QByteArray)));
    connect(_dialogButtonBox, SIGNAL(accepted()), _portSettingsDialog, SLOT(close()));
}
Exemplo n.º 3
0
void MdGpsSerial::closePort()
{
    if ( port )
        port->closePort();
    emit showStatusMessage ("MdGpsSerial: Serial Port closed");
    emit portClosed();
}
void MdQextSerialCom::closePort()
{
    if ( port ) {
        port->close();
        qDebug("is open: %d", port->isOpen());
    }
    emit showStatusMessage ("Serial Port closed");
    emit portClosed();
}
void SerialPortControl::closePort (void)
{
    if (serialPort->isOpen())
    {
        serialPort->close();
        this->cleanBuffer();
        emit portClosed();
    }
    else
        qDebug("The port is already closed");
}
void SerialPort::on_openButton_clicked()
{
	// Make sure things are clear
	serial->close();
	emit(portClosed());
	
	// read in all the settings and open the port
	serial->setPortName(choosePort->currentText());
	switch(chooseBaudRate->currentIndex())
	{
		case 0:
			serial->setBaudRate(BAUD9600);
			break;
		case 1:
			serial->setBaudRate(BAUD19200);
			break;
		case 2:
			serial->setBaudRate(BAUD38400);
			break;
		case 3:
			serial->setBaudRate(BAUD57600);
			break;
		case 4:
			serial->setBaudRate(BAUD115200);
	}
	serial->setDataBits( (DataBitsType)(chooseDataBits->currentIndex()) );
	serial->setParity( (ParityType)(chooseParity->currentIndex()) );
	serial->setStopBits( (StopBitsType)(chooseStopBits->currentIndex()) );
	serial->setFlowControl( (FlowType)(chooseFlowControl->currentIndex()) );
	serial->setTimeout(0,100);
	
	if(serial->open())
	{
		timer->start();
		emit(portOpened());
	}
}
Exemplo n.º 7
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    kwp(this),
    appSettings(new QSettings("vagblocks.ini", QSettings::IniFormat, this)),
    serialConfigured(false),
    storedRow(-1), storedCol(-1),
    currentlyLogging(false)
{
    /*
    QFile roboto(":/resources/Roboto-Regular.ttf");
    roboto.open(QIODevice::ReadOnly);
    if (QFontDatabase::addApplicationFontFromData(roboto.readAll()) < 0) {
        // error
    }
    roboto.close();
    */

    ui->setupUi(this);

    QString svnRev = APP_SVN_REV;
    int colonAt = svnRev.indexOf(":");
    if (colonAt > 0) {
        svnRev = svnRev.mid(colonAt+1);
    }
    QString appVer = APP_VERSION;
    aboutDialog = new about(appVer, svnRev, this);
    serSettings = new serialSettingsDialog(this);
    settingsDialog = new settings(appSettings, this);

    connect(ui->action_About, SIGNAL(triggered()), aboutDialog, SLOT(show()));
    connect(ui->actionApplication_settings, SIGNAL(triggered()), settingsDialog, SLOT(show()));

    setupBlockArray(ui->blocksLayout);

    connect(&kwp, SIGNAL(log(QString, int)), this, SLOT(log(QString, int)));
    connect(&kwp, SIGNAL(newBlockData(int)), this, SLOT(newBlockData(int)));
    connect(&kwp, SIGNAL(blockOpen(int)), this, SLOT(blockOpen(int)));
    connect(&kwp, SIGNAL(blockClosed(int)), this, SLOT(blockClosed(int)));
    connect(&kwp, SIGNAL(channelOpen(bool)), this, SLOT(channelOpen(bool)));
    connect(&kwp, SIGNAL(elmInitialised(bool)), this, SLOT(elmInitialised(bool)));
    connect(&kwp, SIGNAL(portOpened(bool)), this, SLOT(portOpened(bool)));
    connect(&kwp, SIGNAL(portClosed()), this, SLOT(portClosed()));
    connect(&kwp, SIGNAL(newModuleInfo(QStringList)), this, SLOT(moduleInfoReceived(QStringList)));
    connect(&kwp, SIGNAL(newEcuInfo(QStringList)), this, SLOT(ecuInfoReceived(QStringList)));
    connect(ui->pushButton_log, SIGNAL(clicked(bool)), this, SLOT(startLogging(bool)));
    connect(&kwp, SIGNAL(labelsLoaded(bool)), this, SLOT(labelsLoaded(bool)));
    connect(ui->lineEdit_moduleNum, SIGNAL(textChanged(QString)), this, SLOT(clearUI()));
    connect(ui->comboBox_modules, SIGNAL(activated(int)), this, SLOT(selectNewModule(int)));
    connect(&kwp, SIGNAL(moduleListRefreshed()), this, SLOT(refreshModules()));
    connect(ui->pushButton_refresh, SIGNAL(clicked()), &kwp, SLOT(openGW_refresh()));
    connect(&kwp, SIGNAL(sampleFormatChanged()), this, SLOT(sampleFormatChanged()));
    connect(&kwp, SIGNAL(loggingStarted()), this, SLOT(loggingStarted()));
    connect(settingsDialog, SIGNAL(settingsChanged()), this, SLOT(updateSettings()));

    for (int i = 0; i < 16; i++) { // setup running average for sample rate
        avgList.append(0);
    }

    restoreSettings();

    if (serialConfigured) {
        kwp.setSerialParams(serSettings->getSettings());
        QMetaObject::invokeMethod(&kwp, "openPort", Qt::QueuedConnection);
    }

    connect(serSettings, SIGNAL(settingsApplied()), this, SLOT(connectToSerial()));
    refreshModules(true);
}
void SerialPort::closePort()
{
	serial->close();
	emit(portClosed());
}