Hi all,
anyone use before qextserialport? I need some help in getting it to work properly. I have a arm development board which does not have any keyboard attached so I need to hyper terminal my laptop to the board for keyboard entry.
here are my problems:
1) at start it proceed fine but after a while it started to print garbage and also lose some input. eg. abcd@@.- after that I typed g once and it will show abcd@@.-g@@.-
2) I seems to get seg fault after I close the form to load another form or end prog (if I start the receive function by button clicked event).
3) regardless of whether I click on button to start receiving or not, when I end the program, it will bring me to the login in screen of linux. eg ARM login: _
Can someone help me? below is my attached coded. Thanks
form1.h
#ifndef FORM1_H
#define FORM1_H
#include <QWidget>
//#include <qextserialport.h>
#include "serial.h"
#include "form2.h"
#include <QLineEdit>
namespace Ui {
class form1;
}
Q_OBJECT
public:
~form1();
protected:
private slots:
void on_btnLoadf2_clicked();
void on_btn_rec_clicked();
void on_btn_exit_clicked();
private:
Ui::form1 *ui;
Form2 *f2;
serial *port;
};
#endif // FORM1_H
#ifndef FORM1_H
#define FORM1_H
#include <QWidget>
//#include <qextserialport.h>
#include "serial.h"
#include "form2.h"
#include <QLineEdit>
namespace Ui {
class form1;
}
class form1 : public QWidget {
Q_OBJECT
public:
form1(QWidget *parent = 0);
~form1();
protected:
void changeEvent(QEvent *e);
private slots:
void on_btnLoadf2_clicked();
void on_btn_rec_clicked();
void on_btn_exit_clicked();
void closeEvent(QCloseEvent *e);
private:
Ui::form1 *ui;
Form2 *f2;
serial *port;
};
#endif // FORM1_H
To copy to clipboard, switch view to plain text mode
form1.cpp
#include "form1.h"
#include "ui_form1.h"
#include <QString>
#include "form2.h"
#include <iostream>
ui(new Ui::form1)
{
ui->setupUi(this);
port = new serial;
port->init();
}
form1::~form1()
{
delete ui;
}
{
port->close();
}
void form1
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void form1::on_btnLoadf2_clicked()
{
QString str
= "to be pass over to f2";
f2 = new Form2;
f2->show();
this->close();
this->destroy();
}
void form1::on_btn_exit_clicked()
{
this->close();
}
void form1::on_btn_rec_clicked()
{
port->receive((void *) ui->line_serial);
}
#include "form1.h"
#include "ui_form1.h"
#include <QString>
#include "form2.h"
#include <iostream>
form1::form1(QWidget *parent) :
QWidget(parent),
ui(new Ui::form1)
{
ui->setupUi(this);
port = new serial;
port->init();
}
form1::~form1()
{
delete ui;
}
void form1::closeEvent(QCloseEvent *e)
{
port->close();
}
void form1::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void form1::on_btnLoadf2_clicked()
{
QString str = "to be pass over to f2";
f2 = new Form2;
f2->show();
this->close();
this->destroy();
}
void form1::on_btn_exit_clicked()
{
this->close();
}
void form1::on_btn_rec_clicked()
{
port->receive((void *) ui->line_serial);
}
To copy to clipboard, switch view to plain text mode
serial.h
#ifndef SERIAL_H
#define SERIAL_H
#include <qextserialport.h>
class serial
{
public:
serial();
~serial();
void init();
void receive(void *line);
void close();
private:
bool stop;
QextSerialPort *com;
};
#endif // SERIAL_H
#ifndef SERIAL_H
#define SERIAL_H
#include <qextserialport.h>
class serial
{
public:
serial();
~serial();
void init();
void receive(void *line);
void close();
private:
bool stop;
QextSerialPort *com;
};
#endif // SERIAL_H
To copy to clipboard, switch view to plain text mode
serial.cpp
#include "serial.h"
#include <QApplication>
#include <QLineEdit>
serial::serial()
{
}
serial::~serial()
{
}
void serial::init()
{
//set up serial port
com = new QextSerialPort("/dev/ttyS0");
com->setBaudRate(BAUD115200);
com->setParity(PAR_NONE);
com->setDataBits(DATA_8);
com->setStopBits(STOP_1);
com->setFlowControl(FLOW_OFF);
stop = false;
}
void serial::close()
{
stop = true;
delete com;
com = NULL;
}
void serial::receive(void *obj)
{
char data[256];
int nbytes;
while (stop == false) {
nbytes = com->bytesAvailable();
if (nbytes > 0) {
com->read(data,nbytes);
*str = data;
line->setText(line->text().append(*str));
}
}
}
#include "serial.h"
#include <QApplication>
#include <QLineEdit>
serial::serial()
{
}
serial::~serial()
{
}
void serial::init()
{
//set up serial port
com = new QextSerialPort("/dev/ttyS0");
com->setBaudRate(BAUD115200);
com->setParity(PAR_NONE);
com->setDataBits(DATA_8);
com->setStopBits(STOP_1);
com->setFlowControl(FLOW_OFF);
com->open(QIODevice::ReadOnly);
stop = false;
}
void serial::close()
{
stop = true;
delete com;
com = NULL;
}
void serial::receive(void *obj)
{
char data[256];
int nbytes;
QLineEdit *line = (QLineEdit *) obj;
QString* str = new QString;
while (stop == false) {
QApplication::processEvents();
nbytes = com->bytesAvailable();
if (nbytes > 0) {
com->read(data,nbytes);
*str = data;
line->setText(line->text().append(*str));
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks