将框架搭好
This commit is contained in:
59
qtserialport.cpp
Normal file
59
qtserialport.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "qtserialport.h"
|
||||
|
||||
int QtSerialport::OpenSerialPort(string portName)
|
||||
{
|
||||
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
|
||||
|
||||
//std::cout<<"number of availablePorts:"<<infos.size()<<std::endl;
|
||||
|
||||
//如果在构造函数中创建m_serial就会出现错误:
|
||||
//QObject: Cannot create children for a parent that is in a different thread.
|
||||
//(Parent is QSerialPort(0x2e31b20), parent's thread is QThread(0x2e2f130), current thread is QThread(0x2e31110)
|
||||
m_serial = new QSerialPort();
|
||||
|
||||
if(m_serial->isOpen())//如果串口已经打开了 先给他关闭了
|
||||
{
|
||||
m_serial->clear();
|
||||
m_serial->close();
|
||||
}
|
||||
|
||||
m_serial->setPortName(QString::fromStdString(portName));
|
||||
m_serial->open(QIODevice::ReadWrite);
|
||||
|
||||
|
||||
bool x=SetBaudrate(9600);
|
||||
if(x)
|
||||
{
|
||||
std::cout<<"波特率被成功设置为:"<<m_serial->baudRate()<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"波特率设置失败!"<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int QtSerialport::CloseSerialPort()
|
||||
{
|
||||
m_serial->close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QtSerialport::SetBaudrate(int baudrate)
|
||||
{
|
||||
bool x=m_serial->setBaudRate(baudrate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QtSerialport::SendData(const char chrMessage[], const unsigned short usLen)
|
||||
{
|
||||
//QIODevice::write(const char *data, qint64 maxSize)
|
||||
m_serial->write(chrMessage, usLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QtSerialport::ReadData()
|
||||
{
|
||||
return 0;
|
||||
}
|
31
qtserialport.h
Normal file
31
qtserialport.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef QTSERIALPORT_H
|
||||
#define QTSERIALPORT_H
|
||||
|
||||
#include "serialportbase.h"
|
||||
|
||||
#include <QtSerialPort/QSerialPort>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
|
||||
|
||||
class QtSerialport :public SerialPortBase
|
||||
{
|
||||
// Q_OBJECT
|
||||
|
||||
public:
|
||||
// QtSerialport();
|
||||
// ~QtSerialport();
|
||||
|
||||
|
||||
int OpenSerialPort(string portName);
|
||||
int CloseSerialPort();
|
||||
int SetBaudrate(int baudrate);
|
||||
int SendData(const char chrMessage[], const unsigned short usLen);
|
||||
int ReadData();
|
||||
|
||||
protected:
|
||||
private:
|
||||
QSerialPort * m_serial;
|
||||
};
|
||||
|
||||
|
||||
#endif // QTSERIALPORT_H
|
34
qtserialport_copy.h
Normal file
34
qtserialport_copy.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef QTSERIALPORT_H
|
||||
#define QTSERIALPORT_H
|
||||
|
||||
#include "serialportbase.h"
|
||||
|
||||
#include <QtSerialPort/QSerialPort>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
|
||||
|
||||
class QtSerialport :public SerialPortBase
|
||||
{
|
||||
// Q_OBJECT
|
||||
|
||||
public:
|
||||
QtSerialport(double * nonlinearityCoeffs, int numberOfCoeffs);
|
||||
~QtSerialport();
|
||||
|
||||
|
||||
int OpenSerialPort(string portName);
|
||||
int CloseSerialPort();
|
||||
int SetBaudrate(int baudrate);
|
||||
int SendData(const char chrMessage[], const unsigned short usLen);
|
||||
int ReadData();
|
||||
|
||||
protected:
|
||||
private:
|
||||
QSerialPort * m_serial;
|
||||
|
||||
QString m_qPortName;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // QTSERIALPORT_H
|
3
question.txt
Normal file
3
question.txt
Normal file
@ -0,0 +1,3 @@
|
||||
wit_c_sdk问题
|
||||
1、WitWriteReg WitReadReg是读寄存器,为啥代码中用的还是p_WitSerialWriteFunc?
|
||||
|
35
register.h
Normal file
35
register.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef REGISTER_H
|
||||
#define REGISTER_H
|
||||
|
||||
#define SAVE 0x00
|
||||
#define CALSW 0x01
|
||||
#define RSW 0x02
|
||||
#define RRATE 0x03
|
||||
#define BAUD 0x04
|
||||
#define AXOFFSET 0x05
|
||||
#define AYOFFSET 0x06
|
||||
#define AZOFFSET 0x07
|
||||
#define GXOFFSET 0x08
|
||||
#define GYOFFSET 0x09
|
||||
#define GZOFFSET 0x0a
|
||||
#define HXOFFSET 0x0b
|
||||
#define HYOFFSET 0x0c
|
||||
#define HZOFFSET 0x0d
|
||||
#define D0MODE 0x0e
|
||||
#define D1MODE 0x0f
|
||||
#define D2MODE 0x10
|
||||
#define D3MODE 0x11
|
||||
#define D0PWMH 0x12
|
||||
#define D1PWMH 0x13
|
||||
#define D2PWMH 0x14
|
||||
#define D3PWMH 0x15
|
||||
#define D0PWMT 0x16
|
||||
#define D1PWMT 0x17
|
||||
#define D2PWMT 0x18
|
||||
#define D3PWMT 0x19
|
||||
#define IICADDR 0x1a
|
||||
#define LEDOFF 0x1b
|
||||
#define MAGRANGX 0x1c
|
||||
|
||||
|
||||
#endif // REGISTER_H
|
24
serialportbase.h
Normal file
24
serialportbase.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef SERIALPORTBASE_H
|
||||
#define SERIALPORTBASE_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SerialPortBase
|
||||
{
|
||||
|
||||
public:
|
||||
// SerialPortBase();
|
||||
// ~SerialPortBase();
|
||||
|
||||
virtual int OpenSerialPort(string portName) = 0;
|
||||
virtual int CloseSerialPort() = 0;
|
||||
virtual int SetBaudrate(int baudrate) = 0;
|
||||
virtual int SendData(const char chrMessage[], const unsigned short usLen) = 0;
|
||||
virtual int ReadData() = 0;
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // SERIALPORTBASE_H
|
39
witmotionDll.pro
Normal file
39
witmotionDll.pro
Normal file
@ -0,0 +1,39 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2022-05-25T15:16:09
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
TARGET = witmotionDll
|
||||
TEMPLATE = lib
|
||||
|
||||
QT += serialport
|
||||
|
||||
DEFINES += WITMOTIONDLL_LIBRARY
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
witmotiondll.cpp \
|
||||
qtserialport.cpp
|
||||
|
||||
HEADERS += \
|
||||
witmotiondll.h \
|
||||
witmotiondll_global.h \
|
||||
serialportbase.h \
|
||||
qtserialport.h \
|
||||
register.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
INSTALLS += target
|
||||
}
|
42
witmotiondll.cpp
Normal file
42
witmotiondll.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "witmotiondll.h"
|
||||
|
||||
|
||||
WitmotionDll::WitmotionDll(SerialPortBase * serialPort)
|
||||
{
|
||||
m_SerialPort = serialPort;
|
||||
}
|
||||
|
||||
int WitmotionDll::algorithm(int algorithm)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WitmotionDll::installationDirection(int direction)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WitmotionDll::instructStart()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WitmotionDll::magneticCalibration()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WitmotionDll::heightCalibration()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WitmotionDll::zAxisAngleCalibration()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WitmotionDll::setAngleReference()
|
||||
{
|
||||
return 0;
|
||||
}
|
32
witmotiondll.h
Normal file
32
witmotiondll.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef WITMOTIONDLL_H
|
||||
#define WITMOTIONDLL_H
|
||||
|
||||
#include "witmotiondll_global.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
#include "serialportbase.h"
|
||||
|
||||
class WITMOTIONDLLSHARED_EXPORT WitmotionDll
|
||||
{
|
||||
|
||||
public:
|
||||
WitmotionDll(SerialPortBase * serialPort);
|
||||
|
||||
int algorithm(int algorithm);
|
||||
int installationDirection(int direction);
|
||||
int instructStart();//文档中的通讯协议没有相关的设置?????????????
|
||||
|
||||
|
||||
int magneticCalibration();
|
||||
int heightCalibration();
|
||||
int zAxisAngleCalibration();
|
||||
int setAngleReference();
|
||||
|
||||
private:
|
||||
SerialPortBase * m_SerialPort;
|
||||
|
||||
};
|
||||
|
||||
#endif // WITMOTIONDLL_H
|
12
witmotiondll_global.h
Normal file
12
witmotiondll_global.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef WITMOTIONDLL_GLOBAL_H
|
||||
#define WITMOTIONDLL_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(WITMOTIONDLL_LIBRARY)
|
||||
# define WITMOTIONDLLSHARED_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define WITMOTIONDLLSHARED_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // WITMOTIONDLL_GLOBAL_H
|
Reference in New Issue
Block a user