Modified the way that the serial port is opened to hopefully be more cross platform.
This commit is contained in:
+9
-2
@@ -43,7 +43,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->canFramesView->setColumnWidth(4, 40);
|
||||
ui->canFramesView->setColumnWidth(5, 300);
|
||||
|
||||
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
|
||||
ports = QSerialPortInfo::availablePorts();
|
||||
|
||||
for (int i = 0; i < ports.count(); i++)
|
||||
{
|
||||
@@ -592,7 +592,14 @@ void MainWindow::handleSaveFile()
|
||||
|
||||
void MainWindow::connButtonPress()
|
||||
{
|
||||
emit sendSerialPort(ui->cbSerialPorts->currentText());
|
||||
for (int x = 0; x < ports.count(); x++)
|
||||
{
|
||||
if (ports.at(x).portName() == ui->cbSerialPorts->currentText())
|
||||
{
|
||||
emit sendSerialPort(ports[x]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showGraphingWindow()
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSerialPort>
|
||||
#include <QSerialPortInfo>
|
||||
#include "canframemodel.h"
|
||||
#include "can_structs.h"
|
||||
#include "graphingwindow.h"
|
||||
@@ -37,13 +38,14 @@ public slots:
|
||||
void gotFrame(CANFrame *frame);
|
||||
|
||||
signals:
|
||||
void sendSerialPort(QString portName);
|
||||
void sendSerialPort(QSerialPortInfo &port);
|
||||
void updateBaudRates(int, int);
|
||||
void sendCANFrame(const CANFrame *, int);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
CANFrameModel *model;
|
||||
QList<QSerialPortInfo> ports;
|
||||
QThread serialWorkerThread;
|
||||
QByteArray inputBuffer;
|
||||
GraphingWindow *graphingWindow;
|
||||
|
||||
+19
-18
@@ -16,26 +16,27 @@ SerialWorker::~SerialWorker()
|
||||
if (serial != NULL) delete serial;
|
||||
}
|
||||
|
||||
void SerialWorker::setSerialPort(QString portName)
|
||||
void SerialWorker::setSerialPort(QSerialPortInfo &port)
|
||||
{
|
||||
if (serial == NULL) serial = new QSerialPort(this);
|
||||
if (!(serial == NULL))
|
||||
{
|
||||
if (serial->isOpen())
|
||||
{
|
||||
serial->close();
|
||||
}
|
||||
delete serial;
|
||||
}
|
||||
|
||||
if (serial->isOpen())
|
||||
{
|
||||
serial->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Serial port name is " << portName;
|
||||
serial->setPortName(portName);
|
||||
serial->open(QIODevice::ReadWrite);
|
||||
QByteArray output;
|
||||
output.append(0xE7);
|
||||
output.append(0xE7);
|
||||
serial->write(output);
|
||||
///isConnected = true;
|
||||
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
|
||||
}
|
||||
serial = new QSerialPort(port);
|
||||
|
||||
qDebug() << "Serial port name is " << port.portName();
|
||||
serial->open(QIODevice::ReadWrite);
|
||||
QByteArray output;
|
||||
output.append(0xE7);
|
||||
output.append(0xE7);
|
||||
serial->write(output);
|
||||
///isConnected = true;
|
||||
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
|
||||
}
|
||||
|
||||
void SerialWorker::readSerialData()
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QSerialPort>
|
||||
#include <QSerialPortInfo>
|
||||
#include "can_structs.h"
|
||||
|
||||
enum STATE //keep this enum synchronized with the Arduino firmware project
|
||||
@@ -33,7 +34,7 @@ private slots: //we receive things in slots
|
||||
void readSerialData();
|
||||
|
||||
public slots:
|
||||
void setSerialPort(QString);
|
||||
void setSerialPort(QSerialPortInfo&);
|
||||
void sendFrame(const CANFrame *, int);
|
||||
void updateBaudRates(int, int);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user