实现了任工需要设置的所有参数

This commit is contained in:
tangchao
2022-05-31 22:44:39 +08:00
parent 32ae01d710
commit 5a040caf18
8 changed files with 849 additions and 143 deletions

View File

@ -1,59 +0,0 @@
#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;
}

View File

@ -1,31 +0,0 @@
#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

View File

@ -1,34 +0,0 @@
#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

View File

@ -30,6 +30,163 @@
#define IICADDR 0x1a #define IICADDR 0x1a
#define LEDOFF 0x1b #define LEDOFF 0x1b
#define MAGRANGX 0x1c #define MAGRANGX 0x1c
#define MAGRANGY 0x1d
#define MAGRANGZ 0x1e
#define BANDWIDTH 0x1f
#define GYRORANGE 0x20
#define ACCRANGE 0x21
#define SLEEP 0x22
#define ORIENT 0x23
#define AXIS6 0x24
#define FILTK 0x25
#define GPSBAUD 0x26
#define READADDR 0x27
#define BWSCALE 0x28
#define MOVETHR 0x28
#define MOVESTA 0x29
#define ACCFILT 0x2A
#define GYROFILT 0x2b
#define MAGFILT 0x2c
#define POWONSEND 0x2d
#define VERSION 0x2e
#define KEY 0x69
#define TIMEZONE 0x6B
/* KEY */
#define KEY_UNLOCK 0xB588
/* SAVE */
#define SAVE_PARAM 0x00
#define SAVE_SWRST 0xFF
/* algorithm */
enum ALGROITHM_ENUM {
ALGROITHM9 = 0,
ALGROITHM6 = 1
};
/* ORIENT */
enum ORIENT_ENUM {
ORIENT_HORIZONTAL = 0,
ORIENT_VERTICAL
};
/* ORIENT */
enum POWONSEND_ENUM {
CLOSE = 0,
OPEN
};
/* CALSW */
enum CAL_ENUM {
EXIT = 0,
GYROACC,
MAGNETIC,
ALTITUDE,
ALANGLEZ
};
#define EXITCAL 0x00
#define CALGYROACC 0x01
#define CALMAG 0x02
#define CALALTITUDE 0x03
#define CALANGLEZ 0x04
/* time zone */
enum TIMEZONE_ENUM {
UTC_N12 = 0,
UTC_N11,
UTC_N10,
UTC_N9,
UTC_N8,
UTC_N7,
UTC_N6,
UTC_N5,
UTC_N4,
UTC_N3,
UTC_N2,
UTC_N1,
UTC,
UTC_P1,
UTC_P2,
UTC_P3,
UTC_P4,
UTC_P5,
UTC_P6,
UTC_P7,
UTC_P8,//default
UTC_P9,
UTC_P10,
UTC_P11,
UTC_P12
};
/* RETURN CONTENT */
#define SetBit(VAR, Place) (VAR |= (1 << Place))
#define ClrBit(VAR, Place) (VAR &= ((1 << Place) ^ 255))
enum RETURN_CONTENT_ENUM {
TIME = 0,
ACCELERATION,
ANGULAR_VELOCITY,
EULER_ANGLE,
MAGNETIC_FIELD,
PORT_STATUS,
ATMOSPHERIC_PRESSURE_ALTITUDE,
LATITUDE_LONGITUDE,
GROUND_VELOCITY,
QUATERNION,//四元数
SATELLITE_ACCURACY
};
/* BAUD */
enum BAUD_ENUM {
WIT_BAUD_2400 = 0,
WIT_BAUD_4800,
WIT_BAUD_9600,//default
WIT_BAUD_19200,
WIT_BAUD_38400,
WIT_BAUD_57600,
WIT_BAUD_115200,
WIT_BAUD_230400,
WIT_BAUD_460800,
WIT_BAUD_921600
};
/**RRATE*****/
enum RRATE_ENUM {
RRATE_01HZ = 1,
RRATE_05HZ,
RRATE_1HZ,
RRATE_2HZ,
RRATE_5HZ,
RRATE_10HZ,//default
RRATE_20HZ,
RRATE_50HZ,
RRATE_100HZ,
RRATE_NONE,//保留
RRATE_200HZ,
RRATE_ONCE
};
/* 端口模式 */
enum MODEL_D0_D2_D3_ENUM {
AIN = 0,//default
DIN,
DOH,
DOL,
PWM
};
enum MODEL_D1_ENUM {
AIN_D1 = 0,//default
DIN_D1,
DOH_D1,
DOL_D1,
PWM_D1,
CLR_D1
};
#endif // REGISTER_H #endif // REGISTER_H

View File

@ -12,10 +12,11 @@ public:
// SerialPortBase(); // SerialPortBase();
// ~SerialPortBase(); // ~SerialPortBase();
virtual int OpenSerialPort(string portName) = 0; virtual int OpenSerialPort(string portName, int baudrate) = 0;
virtual int CloseSerialPort() = 0; virtual int CloseSerialPort() = 0;
virtual int SetBaudrate(int baudrate) = 0; virtual int SetBaudrate(int baudrate) = 0;
virtual int SendData(const char chrMessage[], const unsigned short usLen) = 0; virtual int SendData1(const char *data, const unsigned int len) = 0;
virtual int SendData(const char chrSendBuffer[],const unsigned short usLen) = 0;
virtual int ReadData() = 0; virtual int ReadData() = 0;
protected: protected:
private: private:

View File

@ -7,8 +7,6 @@
TARGET = witmotionDll TARGET = witmotionDll
TEMPLATE = lib TEMPLATE = lib
QT += serialport
DEFINES += WITMOTIONDLL_LIBRARY DEFINES += WITMOTIONDLL_LIBRARY
# The following define makes your compiler emit warnings if you use # The following define makes your compiler emit warnings if you use
@ -23,14 +21,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
witmotiondll.cpp \ witmotiondll.cpp
qtserialport.cpp
HEADERS += \ HEADERS += \
witmotiondll.h \ witmotiondll.h \
witmotiondll_global.h \ witmotiondll_global.h \
serialportbase.h \ serialportbase.h \
qtserialport.h \
register.h register.h
unix { unix {

View File

@ -1,42 +1,674 @@
#include "witmotiondll.h" #include "witmotiondll.h"
WitmotionDll::WitmotionDll(SerialPortBase * serialPort) WitmotionDll::WitmotionDll(SerialPortBase * serialPort)
{ {
m_SerialPort = serialPort; m_SerialPort = serialPort;
} }
int WitmotionDll::algorithm(int algorithm) int WitmotionDll::unlockInstruction()
{ {
using std::this_thread::sleep_for;
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=KEY & 0xFF;
unBuffer[3]=KEY_UNLOCK & 0xff;
unBuffer[4]=KEY_UNLOCK >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
std::cout<<"WitmotionDll::unlockInstruction: "<< num <<std::endl;
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
return 0; return 0;
} }
int WitmotionDll::installationDirection(int direction) int WitmotionDll::saveInstruction()
{ {
using std::this_thread::sleep_for;
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=SAVE & 0xFF;
unBuffer[3]=SAVE_PARAM & 0xff;
unBuffer[4]=SAVE_PARAM >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
std::cout<<"WitmotionDll::saveInstruction: "<< num <<std::endl;
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
return 0; return 0;
} }
int WitmotionDll::instructStart() int WitmotionDll::algorithm(ALGROITHM_ENUM algorithm)
{ {
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
switch (algorithm)
{
case ALGROITHM6:
{
unBuffer[2]=AXIS6 & 0xFF;
unBuffer[3]=ALGROITHM6 & 0xff;
unBuffer[4]=ALGROITHM6 >> 8;
break;
}
case ALGROITHM9:
{
unBuffer[2]=AXIS6 & 0xFF;
unBuffer[3]=ALGROITHM9 & 0xff;
unBuffer[4]=ALGROITHM9 >> 8;
break;
}
default:
break;
}
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::installationOrientation(ORIENT_ENUM orient)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=ORIENT & 0xFF;
unBuffer[3]=orient & 0xff;
unBuffer[4]=orient >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
std::cout<<"WitmotionDll::installationDirection: "<< num <<std::endl;
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::instructStart(POWONSEND_ENUM command)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=POWONSEND & 0xFF;
unBuffer[3]=command & 0xff;
unBuffer[4]=command >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
std::cout<<"WitmotionDll::installationDirection: "<< num <<std::endl;
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::exitCalibration()
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=CALSW & 0xFF;
unBuffer[3]=EXITCAL & 0xff;
unBuffer[4]=EXITCAL >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0; return 0;
} }
int WitmotionDll::magneticCalibration() int WitmotionDll::magneticCalibration()
{ {
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=CALSW & 0xFF;
unBuffer[3]=CALMAG & 0xff;
unBuffer[4]=CALMAG >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0; return 0;
} }
int WitmotionDll::heightCalibration() int WitmotionDll::setHeightToZero()
{ {
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=CALSW & 0xFF;
unBuffer[3]=CALALTITUDE & 0xff;
unBuffer[4]=CALALTITUDE >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0; return 0;
} }
int WitmotionDll::zAxisAngleCalibration() int WitmotionDll::setZAxisAngleToZero()
{ {
//需要读取参数确保处于算法ALGROITHM6下
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=CALSW & 0xFF;
unBuffer[3]=CALANGLEZ & 0xff;
unBuffer[4]=CALANGLEZ >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0; return 0;
} }
int WitmotionDll::setAngleReference() int WitmotionDll::setAngleReference()
{ {
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=CALSW & 0xFF;
unBuffer[3]=0x08;
unBuffer[4]=0x00;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
void WitmotionDll::recordData()
{
m_SerialPort->ReadData();
}
int WitmotionDll::setTimeZone(TIMEZONE_ENUM timeZone)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=TIMEZONE & 0xFF;
unBuffer[3]=timeZone & 0xff;
unBuffer[4]=timeZone >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
std::cout<<"WitmotionDll::installationDirection: "<< num <<std::endl;
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::latitudeLongitude()
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=RSW & 0xFF;
//设置回传内容
uint8_t RSWL = 0;
uint8_t RSWH = 0;
SetBit(RSWL, LATITUDE_LONGITUDE);
unBuffer[3] = RSWL;
unBuffer[4] = RSWH;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
exitCalibration();
return 0;
}
int WitmotionDll::eulerAngle()
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=RSW & 0xFF;
//设置回传内容
uint8_t RSWL = 0;
uint8_t RSWH = 0;
SetBit(RSWL, EULER_ANGLE);
unBuffer[3] = RSWL;
unBuffer[4] = RSWH;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
exitCalibration();
return 0;
}
int WitmotionDll::setContent(RETURN_CONTENT_ENUM content)
{
return 0;
}
int WitmotionDll::clearContent(RETURN_CONTENT_ENUM content)
{
return 0;
}
int WitmotionDll::SetBaudrate(BAUD_ENUM baudrate)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=BAUD & 0xFF;
unBuffer[3]=baudrate & 0xff;
unBuffer[4]=baudrate >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::SetReturnRate(RRATE_ENUM returnRate)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=RRATE & 0xFF;
unBuffer[3]=returnRate & 0xff;
unBuffer[4]=returnRate >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::SetDeviceAddress(int deviceAddress)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=IICADDR & 0xFF;
unBuffer[3]=deviceAddress & 0xff;
unBuffer[4]=deviceAddress >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD0Model(MODEL_D0_D2_D3_ENUM model)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D0MODE & 0xFF;
unBuffer[3]=model & 0xff;
unBuffer[4]=model >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD1Model(MODEL_D1_ENUM model)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D1MODE & 0xFF;
unBuffer[3]=model & 0xff;
unBuffer[4]=model >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD2Model(MODEL_D0_D2_D3_ENUM model)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D2MODE & 0xFF;
unBuffer[3]=model & 0xff;
unBuffer[4]=model >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD3Model(MODEL_D0_D2_D3_ENUM model)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D3MODE & 0xFF;
unBuffer[3]=model & 0xff;
unBuffer[4]=model >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD0HighLevelPulseWidth(int PWMH)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D0PWMH & 0xFF;
unBuffer[3]=PWMH & 0xff;
unBuffer[4]=PWMH >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD1HighLevelPulseWidth(int PWMH)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D1PWMH & 0xFF;
unBuffer[3]=PWMH & 0xff;
unBuffer[4]=PWMH >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD2HighLevelPulseWidth(int PWMH)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D2PWMH & 0xFF;
unBuffer[3]=PWMH & 0xff;
unBuffer[4]=PWMH >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD3HighLevelPulseWidth(int PWMH)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D3PWMH & 0xFF;
unBuffer[3]=PWMH & 0xff;
unBuffer[4]=PWMH >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD0Period(int period)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D0PWMT & 0xFF;
unBuffer[3]=period & 0xff;
unBuffer[4]=period >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD1Period(int period)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D1PWMT & 0xFF;
unBuffer[3]=period & 0xff;
unBuffer[4]=period >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD2Period(int period)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D2PWMT & 0xFF;
unBuffer[3]=period & 0xff;
unBuffer[4]=period >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0;
}
int WitmotionDll::setD3Period(int period)
{
using std::this_thread::sleep_for;
unlockInstruction();
uint8_t unBuffer[8];
unBuffer[0]=0xFF;
unBuffer[1]=0xAA;
unBuffer[2]=D3PWMT & 0xFF;
unBuffer[3]=period & 0xff;
unBuffer[4]=period >> 8;
int num = m_SerialPort->SendData1((char *)unBuffer,5);
sleep_for(std::chrono::milliseconds(TIME_TO_SLEEP));
saveInstruction();
return 0; return 0;
} }

View File

@ -5,8 +5,10 @@
#include <iostream> #include <iostream>
#include <string.h> #include <string.h>
#include <thread>
#include "serialportbase.h" #include "serialportbase.h"
#include "register.h"
class WITMOTIONDLLSHARED_EXPORT WitmotionDll class WITMOTIONDLLSHARED_EXPORT WitmotionDll
{ {
@ -14,18 +16,60 @@ class WITMOTIONDLLSHARED_EXPORT WitmotionDll
public: public:
WitmotionDll(SerialPortBase * serialPort); WitmotionDll(SerialPortBase * serialPort);
int algorithm(int algorithm); int unlockInstruction();
int installationDirection(int direction); int saveInstruction();
int instructStart();//文档中的通讯协议没有相关的设置?????????????
void recordData();
//系统
int algorithm(ALGROITHM_ENUM algorithm);
int installationOrientation(ORIENT_ENUM orient);
int instructStart(POWONSEND_ENUM command);//是否上电输出数据
//校准:完成后,需要退出校准模式( 调用exitCalibration
int exitCalibration();//退出校准模式
int magneticCalibration(); int magneticCalibration();
int heightCalibration(); int setHeightToZero();//需要JY901B带有高度数据输出的模块才能进行高度校准此为相对高度短时间内有效
int zAxisAngleCalibration(); int setZAxisAngleToZero();//Z轴角度归零只在切换成 6 轴算法下才能成功置零;
int setAngleReference(); int setAngleReference();//问的技术支持,文档没有,不建议使用,设置后只能在静态下运动,即原点旋转单轴,其他方式旋转出来会有比较大的误差
//范围
int setTimeZone(TIMEZONE_ENUM timeZone);
//设置回传内容:操作位??????????????????????
int latitudeLongitude();
int eulerAngle();
int setContent(RETURN_CONTENT_ENUM content);
int clearContent(RETURN_CONTENT_ENUM content);
//通讯
int SetBaudrate(BAUD_ENUM baudrate);
int SetReturnRate(RRATE_ENUM returnRate);
int SetDeviceAddress(int deviceAddress);//1只用于IIC协议串口不用2设置、保存后重新上电生效3最大为0x7f(124)
//接口
int setD0Model(MODEL_D0_D2_D3_ENUM model);
int setD1Model(MODEL_D1_ENUM model);
int setD2Model(MODEL_D0_D2_D3_ENUM model);
int setD3Model(MODEL_D0_D2_D3_ENUM model);
int setD0HighLevelPulseWidth(int PWMH);
int setD1HighLevelPulseWidth(int PWMH);
int setD2HighLevelPulseWidth(int PWMH);
int setD3HighLevelPulseWidth(int PWMH);
int setD0Period(int period);
int setD1Period(int period);
int setD2Period(int period);
int setD3Period(int period);
private: private:
SerialPortBase * m_SerialPort; SerialPortBase * m_SerialPort;
int TIME_TO_SLEEP = 500;//毫秒
}; };