Skip to content
Browse files

first serial connection working

  • Loading branch information...
1 parent 3b7caa9 commit ee857872fa7fef2da4f820d28797cc321a766325 @bkubicek committed Nov 12, 2011
Showing with 379 additions and 9 deletions.
  1. +17 −3 QTMarlin.pro
  2. +188 −2 mainwindow.cpp
  3. +28 −4 mainwindow.h
  4. +28 −0 tab_eeprom.cpp
  5. +35 −0 tab_eeprom.h
  6. +42 −0 tab_raw.cpp
  7. +41 −0 tab_raw.h
View
20 QTMarlin.pro
@@ -2,14 +2,28 @@
# Automatically generated by qmake (2.01a) Sat Nov 12 13:08:01 2011
######################################################################
+
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += /home/bkubicek/PVModulMesser/qextserialport/src/ /home/bkubicek/PVModulMesser/qwt-5.2/src
+INCLUDEPATH += /home/bkubicek/software/qserialdevice-qserialdevice/src/qserialdeviceenumerator
+INCLUDEPATH += /home/bkubicek/software/qserialdevice-qserialdevice/src/qserialdevice
+
QMAKE_LIBDIR += /home/bkubicek/PVModulMesser/qwt-5.2/lib/ /home/bkubicek/PVModulMesser/qextserialport/src/build/
# Input
-HEADERS += mainwindow.h tab_pid.h
-SOURCES += main.cpp mainwindow.cpp tab_pid.cpp
-LIBS += -lqextserialport -lqwt
+HEADERS += mainwindow.h tab_pid.h tab_raw.h tab_eeprom.h
+SOURCES += main.cpp mainwindow.cpp tab_pid.cpp tab_raw.cpp tab_eeprom.cpp
+#LIBS += -lqextserialport -lqserialdevice -lqwt
+LIBS += -lqserialdevice -lqwt
+QMAKE_LIBDIR +=/home/bkubicek/software/qserialdevice-qserialdevice/src/build/release
+
+
+win32 {
+ LIBS += -lsetupapi -luuid -ladvapi32
+}
+unix:!macx {
+ LIBS += -ludev
+}
View
190 mainwindow.cpp
@@ -35,22 +35,37 @@ using namespace std;
#include <QTreeWidget>
#include <QTabWidget>
#include <QComboBox>
+#include <QTextEdit>
+#include <QLineEdit>
#include "tab_pid.h"
+#include "tab_raw.h"
+#include "tab_eeprom.h"
+//#include "qextserialenumerator.h"
+//#include "qextserialport.h"
-
+#include "serialdeviceenumerator.h"
+#include <abstractserial.h>
MainWindow::MainWindow(QWidget *parent): QWidget(parent)
{
+ //comport = new QextSerialPort( QextSerialPort::Polling);
+ port = new AbstractSerial();
QVBoxLayout *layout = new QVBoxLayout;
QHBoxLayout *comLayout= new QHBoxLayout;
portSelector=new QComboBox(this);
baudSelector=new QComboBox(this);
+
+ baudSelector->addItem("115200");
+ baudSelector->addItem("57600");
+ baudSelector->addItem("230800");
+ baudSelector->addItem("250000");
btConnect= new QPushButton("Connect");;
btDisconnect=new QPushButton("Disconnect",this);
btRescan= new QPushButton("Rescan",this);
comLayout->addWidget(portSelector);
+ comLayout->addWidget(baudSelector);
comLayout->addWidget(btConnect);
comLayout->addWidget(btDisconnect);
comLayout->addWidget(btRescan);
@@ -59,14 +74,185 @@ MainWindow::MainWindow(QWidget *parent): QWidget(parent)
layout->addWidget(tab);
tabPID=new TabPID(tab);
+ tabRaw=new TabRaw(tab);
+ tabEEPROM=new TabEEPROM(tab);
+
+ tab->addTab(tabRaw,"Raw");
tab->addTab(tabPID,"PID");
-
+ tab->addTab(tabEEPROM,"EEPROM");
+
status=new QStatusBar(this);
layout->addWidget(status);
//layout->addWidget(slider);
setLayout(layout);
+ clickedRefresh();
+
+ connect(btConnect, SIGNAL(clicked(bool)), this, SLOT(clickedConnect()));
+ connect(btDisconnect, SIGNAL(clicked(bool)), this, SLOT(clickedDisconnect()));
+ connect(btRescan, SIGNAL(clicked(bool)), this, SLOT(clickedRefresh()));
+
+ connect(port, SIGNAL(readyRead()), this, SLOT(slotRead()));
+ connect(tabRaw->sendText,SIGNAL(returnPressed()),this, SLOT(manualSend()));
}
+void MainWindow::clickedConnect()
+{
+// if(!(bool)comport)
+// delete comport;
+//
+// comport=new QextSerialPort(portSelector->currentText(), QextSerialPort::Polling);
+// QString baud=baudSelector->currentText();
+// if(baud=="57600")
+// comport->setBaudRate(BAUD57600);
+// else if(baud=="115200")
+// comport->setBaudRate(BAUD115200);
+// else
+// cerr<<"Unsuppored baudrate"<<endl;
+//
+//
+// comport->setFlowControl(FLOW_OFF);
+// //comport->setParity(PAR_ODD);
+// comport->setParity(PAR_NONE);
+// comport->setDataBits(DATA_8);
+// comport->setStopBits(STOP_1);
+// if (comport->open(QIODevice::ReadWrite) != true) {
+// cout<<"failed opening comport:"<<portSelector->currentText().toStdString()<<endl;
+// exit(1);
+// }
+//
+
+ port->setDeviceName(portSelector->currentText());
+ if (port->open(AbstractSerial::ReadWrite | AbstractSerial::Unbuffered))
+ {
+ qDebug()<<"opened ok"<<endl;
+ }
+ else
+ {
+ qDebug()<<"failed opening comport:"<<portSelector->currentText()<<endl;
+ //exit(1);
+ return;
+ }
+
+ QString baud=baudSelector->currentText();
+ if(baud=="115200")
+ {
+ if (!port->setBaudRate(AbstractSerial::BaudRate115200))
+ {
+ qDebug() << "Set baud rate " << AbstractSerial::BaudRate115200 << " error.";
+ return ;
+ };
+ }
+
+}
+
+void MainWindow::clickedDisconnect()
+{
+ //comport->close();
+ port->close();
+}
+
+void MainWindow::clickedRefresh()
+{
+// portSelector->clear();
+// QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
+// stringstream ss;
+// for (int i = 0; i < ports.size(); i++) {
+// ss<< "port name:\"" << ports.at(i).portName.toStdString()<<"\""<<endl;
+// ss<< "friendly name:" << ports.at(i).friendName.toStdString()<<endl;
+// ss<< "physical name:" << ports.at(i).physName.toStdString()<<endl;
+// ss<< "enumerator name:" << ports.at(i).enumName.toStdString()<<endl;
+// //qDebug() << "vendor ID:" << QString::number(ports.at(i).vendorID, 16);
+// //qDebug() << "product ID:" << QString::number(ports.at(i).productID, 16);
+// ss<< "==================================="<<endl;
+//
+// portSelector->addItem( ports.at(i).physName);
+//
+// }
+// cout<<ss.str()<<endl;
+
+
+ this->m_sde = SerialDeviceEnumerator::instance();
+ //connect(this->m_sde, SIGNAL(hasChanged(QStringList)), this, SLOT(slotPrintAllDevices(QStringList)));
+ //this->slotPrintAllDevices();
+ QStringList list;
+ list=this->m_sde->devicesAvailable();
+ qDebug() << "\n ===> All devices: " << list;
+ portSelector->clear();
+ foreach (QString s, list) {
+ this->m_sde->setDeviceName(s);
+ qDebug() << "\n <<< info about: " << this->m_sde->name() << " >>>";
+ qDebug() << "-> description : " << this->m_sde->description();
+ qDebug() << "-> driver : " << this->m_sde->driver();
+ qDebug() << "-> friendlyName : " << this->m_sde->friendlyName();
+ qDebug() << "-> hardwareID : " << this->m_sde->hardwareID();
+ qDebug() << "-> locationInfo : " << this->m_sde->locationInfo();
+ qDebug() << "-> manufacturer : " << this->m_sde->manufacturer();
+ qDebug() << "-> productID : " << this->m_sde->productID();
+ qDebug() << "-> service : " << this->m_sde->service();
+ qDebug() << "-> shortName : " << this->m_sde->shortName();
+ qDebug() << "-> subSystem : " << this->m_sde->subSystem();
+ qDebug() << "-> systemPath : " << this->m_sde->systemPath();
+ qDebug() << "-> vendorID : " << this->m_sde->vendorID();
+
+ qDebug() << "-> revision : " << this->m_sde->revision();
+ qDebug() << "-> bus : " << this->m_sde->bus();
+ //
+ qDebug() << "-> is exists : " << this->m_sde->isExists();
+ qDebug() << "-> is busy : " << this->m_sde->isBusy();
+ portSelector->addItem(this->m_sde->shortName());
+ }
+}
+
+
+void MainWindow::slotRead()
+{
+ QByteArray ba = port->readAll();
+ qDebug() << "Readed is : " << ba.size() << " bytes";
+ //qDebug()<<QString( ba);
+ tabRaw->edit->append(ba);
+
+ QStringList lines = QString( ba).split("\n");
+ foreach(QString s, lines)
+ {
+ if(s.startsWith("ok"))
+ {
+ QStringList junks(s.remove(0,3).split(" ",QString::SkipEmptyParts));
+ foreach(QString j, junks)
+ {
+ qDebug()<<j<<endl;
+ QStringList ll=j.split(":",QString::SkipEmptyParts);
+ if(ll.size()==2)
+ {
+ variables[ll[0]]= ll[1].toDouble();
+ qDebug()<<"Variable read:"<<QString(ll[0])<<"="<<variables[ll[0]]<<endl;
+ }
+ }
+
+
+ }
+ }
+}
+
+void MainWindow::manualSend()
+{
+ send(tabRaw->sendText->text()+"\n");
+}
+
+
+void MainWindow::send(const QString &text)
+{
+ if(!port->isOpen())
+ return;
+ QByteArray ba=text.toAscii(); //data to send
+ qint64 bw = 0; //bytes really writed
+
+ /* 5. Fifth - you can now read / write device, or further modify its settings, etc.
+ */
+
+ bw = port->write(ba);
+ qDebug() << "Writen : " << bw << " bytes:"<<QString(ba);
+
+}
View
32 mainwindow.h
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <QList>
+#include <abstractserial.h>
class MyThread;
class QwtPlotCurve;
class QwtPlot;
@@ -15,31 +16,54 @@ class QComboBox;
class QPushButton;
class TabPID;
+class TabRaw;
+class TabEEPROM;
+//class QextSerialPort;
+class SerialDeviceEnumerator;
+class AbstractSerial;
+
+#include <QMap>
+
+
class MainWindow : public QWidget
{
-//Q_OBJECT
+Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
+ void send(const QString &text);
-
+
+ QMap<QString, float> variables;
+
public slots:
- //void setWasRead();
+ void clickedConnect();
+ void clickedDisconnect();
+ void clickedRefresh();
+ void slotRead();
+ void manualSend();
//void quit();
-
+
private:
QStatusBar *status;
QTabWidget *tab;
TabPID *tabPID;
+ TabRaw *tabRaw;
+ TabEEPROM *tabEEPROM;
QComboBox *portSelector;
QComboBox *baudSelector;
QPushButton *btConnect;
QPushButton *btDisconnect;
QPushButton *btRescan;
+
+ //QextSerialPort *comport;
+ SerialDeviceEnumerator *m_sde;
+ AbstractSerial *port;
+
};
View
28 tab_eeprom.cpp
@@ -0,0 +1,28 @@
+#include "tab_eeprom.h"
+
+#include <QPushButton>
+#include <QFont>
+#include <QPushButton>
+#include <QWidget>
+#include <QCheckBox>
+#include <qwt_plot.h>
+#include <qwt_plot_curve.h>
+#include <qwt_plot_grid.h>
+#include <qwt_legend.h>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QThread>
+#include <QStatusBar>
+#include <QTreeWidget>
+#include <QTabWidget>
+
+TabEEPROM::TabEEPROM(QWidget* parent): QWidget(parent)
+{
+ QVBoxLayout *layout = new QVBoxLayout;
+ test=new QPushButton("test",this);
+
+ layout->addWidget(test);
+ //layout->addWidget(slider);
+ setLayout(layout);
+
+}
View
35 tab_eeprom.h
@@ -0,0 +1,35 @@
+#include <QWidget>
+#include <fstream>
+
+#include <stdint.h>
+#include <QList>
+class MyThread;
+class QwtPlotCurve;
+class QwtPlot;
+class QStatusBar;
+class QCheckBox;
+class QTreeWidget;
+class QTreeWidgetItem;
+class QTabWidget;
+class QPushButton;
+
+class TabEEPROM : public QWidget
+{
+Q_OBJECT
+
+public:
+ TabEEPROM(QWidget *parent = 0);
+
+
+
+
+
+public slots:
+ //void setWasRead();
+ //void quit();
+
+
+private:
+ QPushButton *test;
+};
+
View
42 tab_raw.cpp
@@ -0,0 +1,42 @@
+#include "tab_raw.h"
+
+#include <QPushButton>
+#include <QFont>
+#include <QPushButton>
+#include <QWidget>
+#include <QCheckBox>
+#include <qwt_plot.h>
+#include <qwt_plot_curve.h>
+#include <qwt_plot_grid.h>
+#include <qwt_legend.h>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QThread>
+#include <QStatusBar>
+#include <QTreeWidget>
+#include <QTabWidget>
+#include <QTextEdit>
+#include <QLabel>
+#include <QLineEdit>
+
+
+TabRaw::TabRaw(QWidget* parent): QWidget(parent)
+{
+ QVBoxLayout *layout = new QVBoxLayout;
+ edit=new QTextEdit("",this);
+ edit->setReadOnly(true);
+
+ layout->addWidget(edit);
+ //layout->addWidget(slider);
+
+ QHBoxLayout *hlayout = new QHBoxLayout;
+ hlayout->addWidget(new QLabel("Send:",this));
+ sendText= new QLineEdit("",this);
+ hlayout->addWidget(sendText);
+
+ btClear=new QPushButton("clear",this);
+ hlayout->addWidget(btClear);
+ layout->addLayout(hlayout);
+ setLayout(layout);
+
+}
View
41 tab_raw.h
@@ -0,0 +1,41 @@
+#include <QWidget>
+#include <fstream>
+
+#include <stdint.h>
+#include <QList>
+class MyThread;
+class QwtPlotCurve;
+class QwtPlot;
+class QStatusBar;
+class QCheckBox;
+class QTreeWidget;
+class QTreeWidgetItem;
+class QTabWidget;
+class QPushButton;
+
+
+class QTextEdit;
+class QLineEdit;
+
+class TabRaw : public QWidget
+{
+Q_OBJECT
+
+public:
+ TabRaw(QWidget *parent = 0);
+
+
+ QTextEdit *edit;
+ QLineEdit *sendText;
+ QPushButton *btClear;
+
+
+public slots:
+ //void setWasRead();
+ //void quit();
+
+
+private:
+ QPushButton *test;
+};
+

0 comments on commit ee85787

Please sign in to comment.
Something went wrong with that request. Please try again.