Changeset - b12c2ff3d038
[Not reviewed]
default
0 2 0
Hasan Yavuz Ă–ZDERYA - 11 years ago 2015-03-07 16:03:22
hy@ozderya.net
enabled serial port error reporting to stdout
2 files changed with 10 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -29,12 +29,16 @@ MainWindow::MainWindow(QWidget *parent) 
 
                     SELECT<const QString&>::OVERLOAD_OF(&QComboBox::activated),
 
                     this, &MainWindow::selectBaudRate);
 

	
 
    QObject::connect(&(this->serialPort), &QSerialPort::readyRead,
 
                     this, &MainWindow::onDataReady);
 

	
 
	// init port signals
 
	QObject::connect(&(this->serialPort), SIGNAL(error(QSerialPort::SerialPortError)),
 
                     this, SLOT(onPortError(QSerialPort::SerialPortError)));
 

	
 
    loadPortList();
 
    loadBaudRateList();
 
    ui->cbBaudRate->setCurrentIndex(ui->cbBaudRate->findText("9600"));
 

	
 
	// init plot
 
	numOfSamples = 100;
 
@@ -158,12 +162,17 @@ void MainWindow::onPortToggled(bool open
 
void MainWindow::onDataReady()
 
{
 
	QByteArray data = serialPort.readAll();
 
	addData((unsigned char)(data[0]));
 
}
 

	
 
void MainWindow::onPortError(QSerialPort::SerialPortError error)
 
{
 
	qDebug() << "Port error happened: " << serialPort.error();
 
}
 

	
 
void MainWindow::addData(double data)
 
{
 
	// shift data array and place new data at the end
 
	for (int i = 0; i < dataArray.size()-1; i++)
 
	{
 
		dataArray[i] = dataArray[i+1];
mainwindow.h
Show inline comments
 
@@ -35,12 +35,13 @@ private slots:
 
    void togglePort();
 
    void selectPort(QString portName);
 
    void onPortToggled(bool open);
 
    void selectBaudRate(QString baudRate);
 

	
 
    void onDataReady();
 
    void onPortError(QSerialPort::SerialPortError error);
 

	
 
signals:
 
    void portToggled(bool open);
 
};
 

	
 
#endif // MAINWINDOW_H
0 comments (0 inline, 0 general)