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