##// END OF EJS Templates
Sync
kaveh -
r2:0537883b23fe default
parent child
Show More
@@ -0,0 +1,54
1 #include "ucomport.h"
2
3 UComPort::UComPort()
4 {
5 this->p_portMutex = new QMutex();
6 this->p_opened = false;
7 }
8
9 QString UComPort::portName()
10 {
11 QMutexLocker locker(this->p_portMutex);
12 return p_PortName;
13 }
14
15 int UComPort::speed()
16 {
17 QMutexLocker locker(this->p_portMutex);
18 return p_speed;
19 }
20
21 void UComPort::setPortName(const QString &name)
22 {
23 QMutexLocker locker(this->p_portMutex);
24 this->p_PortName = name;
25 }
26
27 void UComPort::setSpeed(int speed)
28 {
29 QMutexLocker locker(this->p_portMutex);
30 this->p_speed = speed;
31 }
32
33 bool UComPort::open()
34 {
35 QMutexLocker locker(this->p_portMutex);
36 if(p_opened)
37 {
38 rs232close(this->p_port);
39 this->p_opened = false;
40 }
41 this->p_port = rs232open((char*)p_PortName.toStdString().c_str());
42 if(this->p_port!=badPortValue)
43 {
44 rs232setup(this->p_port,8,this->p_speed,rs232parityNo,rs232OneStop);
45 p_opened = true;
46 }
47 }
48
49 bool UComPort::open(const QString &name, int speed)
50 {
51 setPortName(name);
52 setSpeed(speed);
53 return open();
54 }
@@ -0,0 +1,29
1 #ifndef UCOMPORT_H
2 #define UCOMPORT_H
3
4 #include <QObject>
5 #include <RS232.h>
6 #include <QMutex>
7 #include <QMutexLocker>
8
9 class UComPort
10 {
11 public:
12 explicit UComPort();
13 QString portName();
14 int speed();
15 virtual void setPortName(const QString& name);
16 virtual void setSpeed(int speed);
17 bool open();
18 bool open(const QString& name);
19 bool open(const QString& name,int speed);
20 private:
21 rs232port_t p_port;
22 QString p_PortName;
23 int p_speed;
24 QMutex* p_portMutex;
25 bool p_opened;
26
27 };
28
29 #endif // UCOMPORT_H
@@ -0,0 +1,31
1 #include "uprobeprotocol.h"
2
3 UProbeProtocol::UProbeProtocol(QObject *parent) :
4 QThread(parent),UComPort()
5 {
6 moveToThread((QThread*)this);
7 }
8
9 UProbeProtocol::~UProbeProtocol()
10 {
11 this->requestInterruption();
12 while(isRunning());
13 }
14
15 void UProbeProtocol::run()
16 {
17 while(!this->isInterruptionRequested())
18 {
19
20 }
21 }
22
23 void UProbeProtocol::setPortName(const QString &name)
24 {
25 UComPort::setPortName(name);
26 }
27
28 void UProbeProtocol::setSpeed(int speed)
29 {
30 UComPort::setSpeed(speed);
31 }
@@ -0,0 +1,27
1 #ifndef UPROBEPROTOCOL_H
2 #define UPROBEPROTOCOL_H
3
4 #include <QObject>
5 #include <QThread>
6 #include <QMutex>
7 #include <QSemaphore>
8 #include <ucomport.h>
9
10 class UProbeProtocol : public QThread , public UComPort
11 {
12 Q_OBJECT
13 public:
14 explicit UProbeProtocol(QObject *parent = 0);
15 ~UProbeProtocol();
16 void run();
17
18 signals:
19
20 public slots:
21 void setPortName(const QString& name);
22 void setSpeed(int speed);
23
24 private:
25 };
26
27 #endif // UPROBEPROTOCOL_H
@@ -14,9 +14,23 TEMPLATE = app
14
14
15 SOURCES += main.cpp\
15 SOURCES += main.cpp\
16 mainwindow.cpp \
16 mainwindow.cpp \
17 src/uprobe.cpp
17 src/uprobe.cpp \
18 src/uprobeprotocol.cpp \
19 src/ucomport.cpp
20
21 ########## LPP Serial Port stuff ######################
22 win32:SOURCES += src/lppserial/src/RS232_win.c
23 unix:SOURCES += src/lppserial/src/RS232_unix.c
24 debug:DEFINES+=RS232_debug
25 #######################################################
26
27 INCLUDEPATH += src \
28 src/lppserial/src
18
29
19 HEADERS += mainwindow.h \
30 HEADERS += mainwindow.h \
20 src/uprobe.h
31 src/uprobe.h \
32 src/lppserial/src/RS232.h \
33 src/uprobeprotocol.h \
34 src/ucomport.h
21
35
22 FORMS += mainwindow.ui
36 FORMS += mainwindow.ui
@@ -3,4 +3,15
3 UProbe::UProbe(QObject *parent) :
3 UProbe::UProbe(QObject *parent) :
4 QObject(parent)
4 QObject(parent)
5 {
5 {
6
6 }
7 }
8
9 bool UProbe::setPortName(const QString &name)
10 {
11
12 }
13
14 bool UProbe::setPortSpeed(int speed)
15 {
16
17 }
@@ -2,6 +2,7
2 #define UPROBE_H
2 #define UPROBE_H
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <uprobeprotocol.h>
5
6
6 class UProbe : public QObject
7 class UProbe : public QObject
7 {
8 {
@@ -10,8 +11,15 public:
10 explicit UProbe(QObject *parent = 0);
11 explicit UProbe(QObject *parent = 0);
11
12
12 signals:
13 signals:
14 void updateChannelCount(int count);
15 void sendWaveFormData(int channel,float* data,int count);
13
16
14 public slots:
17 public slots:
18 bool setPortName(const QString& name);
19 bool setPortSpeed(int speed);
20
21 private:
22 UProbeProtocol p_proto;
15
23
16 };
24 };
17
25
General Comments 0
You need to be logged in to leave comments. Login now