From 32ae01d7107ef4f50edb702a2a8f0e5ffaa5754c Mon Sep 17 00:00:00 2001 From: tangchao <735056338@qq.com> Date: Sun, 29 May 2022 23:24:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=A1=86=E6=9E=B6=E6=90=AD=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qtserialport.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++ qtserialport.h | 31 +++++++++++++++++++++++ qtserialport_copy.h | 34 +++++++++++++++++++++++++ question.txt | 3 +++ register.h | 35 +++++++++++++++++++++++++ serialportbase.h | 24 ++++++++++++++++++ witmotionDll.pro | 39 ++++++++++++++++++++++++++++ witmotiondll.cpp | 42 ++++++++++++++++++++++++++++++ witmotiondll.h | 32 +++++++++++++++++++++++ witmotiondll_global.h | 12 +++++++++ 10 files changed, 311 insertions(+) create mode 100644 qtserialport.cpp create mode 100644 qtserialport.h create mode 100644 qtserialport_copy.h create mode 100644 question.txt create mode 100644 register.h create mode 100644 serialportbase.h create mode 100644 witmotionDll.pro create mode 100644 witmotiondll.cpp create mode 100644 witmotiondll.h create mode 100644 witmotiondll_global.h diff --git a/qtserialport.cpp b/qtserialport.cpp new file mode 100644 index 0000000..eac8f11 --- /dev/null +++ b/qtserialport.cpp @@ -0,0 +1,59 @@ +#include "qtserialport.h" + +int QtSerialport::OpenSerialPort(string portName) +{ + QList infos = QSerialPortInfo::availablePorts(); + + //std::cout<<"number of availablePorts:"<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<<"波特率被成功设置为:"<baudRate()<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; +} diff --git a/qtserialport.h b/qtserialport.h new file mode 100644 index 0000000..49d946f --- /dev/null +++ b/qtserialport.h @@ -0,0 +1,31 @@ +#ifndef QTSERIALPORT_H +#define QTSERIALPORT_H + +#include "serialportbase.h" + +#include +#include + + +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 diff --git a/qtserialport_copy.h b/qtserialport_copy.h new file mode 100644 index 0000000..2be93b3 --- /dev/null +++ b/qtserialport_copy.h @@ -0,0 +1,34 @@ +#ifndef QTSERIALPORT_H +#define QTSERIALPORT_H + +#include "serialportbase.h" + +#include +#include + + +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 diff --git a/question.txt b/question.txt new file mode 100644 index 0000000..7ae293a --- /dev/null +++ b/question.txt @@ -0,0 +1,3 @@ +wit_c_sdk问题 +1、WitWriteReg WitReadReg是读寄存器,为啥代码中用的还是p_WitSerialWriteFunc? + diff --git a/register.h b/register.h new file mode 100644 index 0000000..c1b1d2b --- /dev/null +++ b/register.h @@ -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 diff --git a/serialportbase.h b/serialportbase.h new file mode 100644 index 0000000..cd3ec67 --- /dev/null +++ b/serialportbase.h @@ -0,0 +1,24 @@ +#ifndef SERIALPORTBASE_H +#define SERIALPORTBASE_H + +#include + +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 diff --git a/witmotionDll.pro b/witmotionDll.pro new file mode 100644 index 0000000..e506e26 --- /dev/null +++ b/witmotionDll.pro @@ -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 +} diff --git a/witmotiondll.cpp b/witmotiondll.cpp new file mode 100644 index 0000000..8d0bb4c --- /dev/null +++ b/witmotiondll.cpp @@ -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; +} diff --git a/witmotiondll.h b/witmotiondll.h new file mode 100644 index 0000000..fa905a6 --- /dev/null +++ b/witmotiondll.h @@ -0,0 +1,32 @@ +#ifndef WITMOTIONDLL_H +#define WITMOTIONDLL_H + +#include "witmotiondll_global.h" + +#include +#include + +#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 diff --git a/witmotiondll_global.h b/witmotiondll_global.h new file mode 100644 index 0000000..8177b25 --- /dev/null +++ b/witmotiondll_global.h @@ -0,0 +1,12 @@ +#ifndef WITMOTIONDLL_GLOBAL_H +#define WITMOTIONDLL_GLOBAL_H + +#include + +#if defined(WITMOTIONDLL_LIBRARY) +# define WITMOTIONDLLSHARED_EXPORT Q_DECL_EXPORT +#else +# define WITMOTIONDLLSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // WITMOTIONDLL_GLOBAL_H