mbahar94 / qextserialport

Automatically exported from code.google.com/p/qextserialport
Other
0 stars 0 forks source link

Create a mini hyperterminal for embedded Board #171

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
read & write is not working

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<iostream>
#include <QtSerialPort/QtSerialPort>

using namespace std;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

        ui->BaudRate->setCurrentIndex(3);
        setting =new PortSettings;

}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::on_BaudRate_activated(int index)
{
}
void MainWindow::on_Databits_activated(int index)
{
}

void MainWindow::on_FlowCtrl_activated(int index)
{

}

void MainWindow::on_Parity_bits_activated(int index)
{

}

void MainWindow::on_Stop_bits_activated(int index)
{

}

void MainWindow::on_portbox_activated(int index)
{
    port = new QextSerialPort();
    if(!port->isOpen()){
    port->setPortName(ui->portbox->currentText());
    int i = port->open(QIODevice::ReadWrite);
     if(port->isOpen())
    {
         cout << "i ="<<i<<endl;
     } statusBar()->showMessage("not open",3000);
   }
}

void MainWindow::on_pushButton_3_clicked()
{
    int sb;
     sb=ui->BaudRate->currentIndex();
     switch(sb)
     {
        case 0:
                   if(setting->BaudRate =BAUD4800)
                   {
                     cout << "Baud_Rate 4800 is Set"<<endl;
                   }
                   else{
                      cout<< "Baud_Rate is not set!!!!" <<endl;
                   }
             break;
        case 1:
                   if(setting->BaudRate =BAUD9600)
                   {
                      cout << setting->BaudRate<<endl;
                     cout << "Baud_Rate 9600 is Set"<<endl;
                   }
                   else{
                      cout<< "Baud_Rate is not set!!!!" <<endl;
                   }
            break;
        case 2:
                   if(setting->BaudRate =BAUD19200)
                   {
                      cout << "Baud_Rate19200 is Set"<<endl;
                   }
                   else{
                      cout<< "Baud_Rate is not set!!!!" <<endl;
                   }
                   break;
        case 3:
                   if(setting->BaudRate =BAUD115200)
                   {
                      cout << "Baud_Rate 115200 is Set"<<endl;
                   }
                   else{
                      cout<< "Baud_Rate is not set!!!!" <<endl;
                   }
         break;
     default:
         break;

     }
     int pb;
     pb=ui->Parity_bits->currentIndex();
     switch(pb){

        case 0:
                setting->Parity = PAR_NONE;
                cout << "Parity is set"<<endl;
                break;
       default:
                setting->Parity = PAR_NONE;
                cout << "Please Select PAR_NONE"<<endl;
                break;
      }
    int db;
    db=ui->Databits->currentIndex();
    switch(db)
    {
        case 0:
               setting->DataBits = DATA_8;
               break;
        default:
               setting->DataBits = DATA_8;
               cout <<"Please select DATA_8"<<endl;
               break;
    }
    int stop;
    stop = ui->Stop_bits->currentIndex();
    switch(stop)
    {
        case 0:
            setting->StopBits =STOP_1;
            break;
        default:
            setting->StopBits =STOP_1;
            cout <<"Please select STOP_1"<<endl;
            break;
    }

    int fc;
    fc = ui->FlowCtrl->currentIndex();
    switch(fc)
    {

        case 0:
        setting->FlowControl = FLOW_OFF;
        break;
    default:
       setting->FlowControl = FLOW_OFF;
        cout << "Please Select NO"<<endl;
        break;
    }

}
void MainWindow::on_pushButton_2_clicked()
{

    if(port->isOpen())
    {
        port->readAll();
        cout << "Inside the byte is available"<<endl;
        ui->plainTextEdit->moveCursor(QTextCursor::End);
        ui->plainTextEdit->insertPlainText(QString::fromLatin1(port->readAll()));
    }
}

void MainWindow::on_plainTextEdit_objectNameChanged(const QString &objectName)
{
}

void MainWindow::on_pushButton_clicked()
{
    int count;
    if(port->isOpen())
    {
        count =port->write("Testing");
        cout << "count "<<count<<endl;
    }
}

Original issue reported on code.google.com by sushantb...@gmail.com on 22 Jul 2013 at 9:02