在服务器上第一次调试

This commit is contained in:
2021-12-03 12:55:05 +08:00
parent 8d73aba000
commit bebef6bef6
24 changed files with 2040 additions and 8 deletions

View File

@ -28,7 +28,6 @@
"configurationType": "Debug", "configurationType": "Debug",
"cmakeExecutable": "/opt/cmake/bin/cmake", "cmakeExecutable": "/opt/cmake/bin/cmake",
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ], "remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "-- -j4",
"buildCommandArgs": "", "buildCommandArgs": "",
"ctestCommandArgs": "", "ctestCommandArgs": "",
"inheritEnvironments": [ "linux_arm" ], "inheritEnvironments": [ "linux_arm" ],

View File

@ -22,16 +22,18 @@ include_directories("source/LinearShutter")
include_directories("source/OSIF/include") include_directories("source/OSIF/include")
link_directories("source/OSIF/DLib") link_directories("source/OSIF/DLib")
link_directories("/home/pi/SeaBrease/lib")
add_executable( TowerOptoSifAndSpectral add_executable( TowerOptoSifAndSpectral
main.cpp main.cpp
${HDR_LIST} ${HDR_LIST}
${SRC_LIST} ${SRC_LIST}
) )
IF (WIN32)
target_link_libraries(TowerOptoSifAndSpectral SeaBreeze) target_link_libraries(TowerOptoSifAndSpectral SeaBreeze)
ELSE ()
target_link_libraries(TowerOptoSifAndSpectral seabreeze usb stdc++ m)
ENDIF ()
qt5_use_modules(TowerOptoSifAndSpectral ${QT}) qt5_use_modules(TowerOptoSifAndSpectral ${QT})
set_target_properties(TowerOptoSifAndSpectral PROPERTIES AUTOMOC ON) set_target_properties(TowerOptoSifAndSpectral PROPERTIES AUTOMOC ON)

View File

@ -5,7 +5,7 @@ DataFileProcessor::DataFileProcessor()
#ifdef _DEBUG #ifdef _DEBUG
m_qstrFilePath = "E:/WorkSpace/TowerOptoSifAndSpectral/Data"; m_qstrFilePath = "E:/WorkSpace/TowerOptoSifAndSpectral/Data";
#else #else
m_qstrFilePath = /home/data/Data; m_qstrFilePath = "/ home / data / Data";
#endif // DEBUG #endif // DEBUG
} }

Binary file not shown.

View File

@ -2,7 +2,7 @@
#include "VSMD12XControl.h" #include "VSMD12XControl.h"
#include "ZZ_SeiralPort.h" #include "ZZ_SeiralPort.h"
#include <iostream> #include <iostream>
#define sprintf_s snprintf
CVSMD12XControl::CVSMD12XControl() CVSMD12XControl::CVSMD12XControl()
{ {
m_iProtocolType = 0; m_iProtocolType = 0;

View File

@ -63,7 +63,7 @@ void CZZ_SeiralPort_QT::Close()
std::string CZZ_SeiralPort_QT::ReadAll() std::string CZZ_SeiralPort_QT::ReadAll()
{ {
m_pSerialPort->waitForReadyRead(); m_pSerialPort->waitForReadyRead(5000);
qbaRecv.clear(); qbaRecv.clear();
qbaRecv = m_pSerialPort->readAll(); qbaRecv = m_pSerialPort->readAll();
std::string strRet(qbaRecv.constData(), qbaRecv.length()); std::string strRet(qbaRecv.constData(), qbaRecv.length());
@ -99,7 +99,7 @@ int CZZ_SeiralPort_QT::Write(const std::string strSend)
{ {
QByteArray qbaTest(strSend.c_str(),(int)strSend.length()); QByteArray qbaTest(strSend.c_str(),(int)strSend.length());
qint64 qi64Write = m_pSerialPort->write(qbaTest); qint64 qi64Write = m_pSerialPort->write(qbaTest);
m_pSerialPort->waitForBytesWritten(); m_pSerialPort->waitForBytesWritten(5000);
if (qi64Write != qbaTest.size()) if (qi64Write != qbaTest.size())
{ {
qDebug() << "Err:write Failed.Exit Code:1" << qi64Write; qDebug() << "Err:write Failed.Exit Code:1" << qi64Write;

View File

@ -7,6 +7,7 @@
m_qstrDeviceConfigFilePath = "E:/WorkSpace/TowerOptoSifAndSpectral/config/DeviceSettings.ini"; m_qstrDeviceConfigFilePath = "E:/WorkSpace/TowerOptoSifAndSpectral/config/DeviceSettings.ini";
m_qstrJSONConfigFilePath = "E:/WorkSpace/TowerOptoSifAndSpectral/config/config.json"; m_qstrJSONConfigFilePath = "E:/WorkSpace/TowerOptoSifAndSpectral/config/config.json";
#else #else
m_qstrDeviceConfigFilePath = "/home/data/Setting/DeviceSettings.ini";
m_qstrJSONConfigFilePath = ("/home/data/Setting/config.json"); m_qstrJSONConfigFilePath = ("/home/data/Setting/config.json");
#endif // DEBUG #endif // DEBUG

View File

@ -0,0 +1,82 @@
#include "OptoSkyManager.h"
OptoSkyManager::OptoSkyManager(QObject *parent)
: QObject(parent)
{
}
OptoSkyManager::~OptoSkyManager()
{
}
void OptoSkyManager::optall()
{
}
void OptoSkyManager::getdata()
{
}
void OptoSkyManager::readconnect()
{
}
void OptoSkyManager::loadtcp()
{
}
bool OptoSkyManager::readbutdonothing(int size)
{
return true;
}
bool OptoSkyManager::reloadtcp()
{
return true;
}
void OptoSkyManager::ChangeArrEnding(float *data, int lenth)
{
}
void OptoSkyManager::conecet()
{
}
void OptoSkyManager::sendMessage()
{
}
void OptoSkyManager::onReciveData()
{
}
void OptoSkyManager::sendgotdata()
{
}
void OptoSkyManager::ComFromUI(QString commom)
{
}
void OptoSkyManager::ondisconnect()
{
}
void OptoSkyManager::ReadError(QAbstractSocket::SocketError)
{
}

View File

@ -0,0 +1,50 @@
#pragma once
#include <QObject>
#include "QtEndian"
#include "QTimer"
#include "QTcpSocket"
class OptoSkyManager : public QObject
{
Q_OBJECT
public:
OptoSkyManager(QObject *parent);
~OptoSkyManager();
void optall();
void getdata();
void readconnect();
QString actionmod;
QTimer *timer;
int waittime;
int temp1, temp2;
void loadtcp();
bool isreadtogotdata;
bool readbutdonothing(int size);
bool reloadtcp();
float darkarry[2151];
int flatwite;
int flatdark;
QString processstr;
QString IP_Address;
int SampleAverage;
int WhiteReferenceAverage;
int DarkCurrentAverage;
private:
void ChangeArrEnding(float *data, int lenth);
public slots:
void conecet();
void sendMessage();
void onReciveData();
void sendgotdata();
void ComFromUI(QString commom);
/* void gotdata();*/
void ondisconnect();
void ReadError(QAbstractSocket::SocketError);
signals:
void Senddatatoui(QString datatype, QByteArray data);
void UpdataProcessBar(QString str, int val);
};

View File

@ -0,0 +1,202 @@
#include "OptoSkyType.h"
#include <QSerialPort>
#include <QSerialPortInfo>
#include "QTime"
#include "logout.h"
QSerialPort *optoskyserial = nullptr;
bool IsOptoskyinit = false;
void OptoSky::SetPortName(QString comname, qint32 bandrate)
{
QSerialPortInfo info;
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
int i = 0;
foreach(info, infos) {
if (info.portName() == comname) break;
i++;
}
if (i != infos.size())
{
if (optoskyserial == nullptr)
{
optoskyserial = new QSerialPort;
}
optoskyserial->close();
optoskyserial->setPort(info);
optoskyserial->open(QIODevice::ReadWrite);
qint32 b = bandrate;
optoskyserial->setBaudRate(b);
}
else
{
IsOptoskyinit = false;
return;
}
IsOptoskyinit = true;
}
void OptoSky::closeport()
{
if (optoskyserial!=nullptr)
{
delete optoskyserial;
optoskyserial = nullptr;
}
}
void OptoSky::SendComment(QByteArray Comment)
{
unsigned short lenth = Comment.size() + 3;
QByteArray header;
header.resize(4);
header[0] = 0xaa;
header[1] = 0x55;
header[2] = lenth / 256;
header[3] = lenth % 256;
header.append(Comment);
int sum = 0;
for (int i = 0; i < lenth-1; i++)
{
sum = sum +header[i+2];
}
header.append(sum % 256);
if (IsOptoskyinit)
{
optoskyserial->readAll();
optoskyserial->write(header);
optoskyserial->waitForBytesWritten(200);
}
//char *a = header.data();
//int c=sizeof(header);
}
bool OptoSky::GetReturn(char id, QByteArray &data)
{
QByteArray b;
b.append(id);
return GetReturn(b, data);
}
bool OptoSky::GetReturn(QByteArray &data)
{
data.clear();
data = optoskyserial->readAll();
QTime time;
time.start();
lable1:
while (data.size() < 5)
{
optoskyserial->waitForReadyRead(50);
QByteArray tempbuf = optoskyserial->readAll();
data.append(tempbuf);
if (time.elapsed() > 50000)
{
logout::out("long time no data retrun ");
return false;
}
}
if ((unsigned char)data[0] != 0xaa || (unsigned char)data[1] != 0x55)
{
data.remove(0, 1);
goto lable1;
}
int datalenth = data[2] * 256 + data[3] + 2;
while (data.size() < datalenth)
{
optoskyserial->waitForReadyRead(50);
data.append(optoskyserial->readAll());
if (time.elapsed() > 50000)
{
logout::out("long time no data retrun " );
return false;
}
}
if (data.size() > datalenth)
{
data.remove(datalenth - 1, data.size() - datalenth);
}
int checkleth = datalenth - 3;
unsigned int checknum = 0;
for (size_t i = 0; i < checkleth; i++)
{
checknum = checknum + data.at(i + 2);
}
checknum = checknum % 256;
if (checknum != (unsigned char)data[data.size() - 1])
{
logout::out("checkerro " );
data.clear();
return false;
}
return true;
}
bool OptoSky::GetReturn(QByteArray id, QByteArray &data)
{
if (!GetReturn(data))
{
return false;
}
if (data[4]!=id[0])
{
logout::out("retrun is not correct with ComId:" + QString::number(id[0], 16));
return false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>򷵻ش<F2B7B5BB><D8B4><EFBFBD>
}
RemoveHeaderandEnd(data);
return true;
}
void OptoSky::SendComment(char comid, QByteArray Data)
{
QByteArray tem;
tem.append(comid);
tem.append(Data);
SendComment(tem);
}
void OptoSky::SendComment(char com)
{
QByteArray temp;
temp.append(com);
SendComment(temp);
}
bool OptoSky::isSensorInit()
{
return IsOptoskyinit;
}
void OptoSky::RemoveHeaderandEnd(QByteArray &buf)
{
if (buf.size() < 6)
{
return;
}
buf.remove(0, 5);
buf.remove(buf.size() - 1, 1);
}
void OptoSky::SendComment(QByteArray Comment, QByteArray Data)
{
Comment.append(Data);
SendComment(Comment);
}

View File

@ -0,0 +1,77 @@
#pragma once
/******************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD> : OptoSkyType.h
* <20><><EFBFBD><EFBFBD> :
* <20><><EFBFBD><EFBFBD> :
* <20><><EFBFBD><EFBFBD> : xin
* <20><><EFBFBD><EFBFBD> : renlixin@iris-rs.cn
* <20><><EFBFBD><EFBFBD> : 2021-2-22
********************************************************
* *
* _ooOoo_ *
* o8888888o *
* 88" . "88 *
* (| -_- |) *
* O\ = /O *
* ____/`---'\____ *
* .' \\| |// `. *
* / \\||| : |||// \ *
* / _||||| -:- |||||- \ *
* | | \\\ - /// | | *
* | \_| ''\---/'' | | *
* \ .-\__ `-` ___/-. / *
* ___`. .' /--.--\ `. . __ *
* ."" '< `.___\_<|>_/___.' >'"". *
* | | : `- \`.;`\ _ /`;.`/ - ` : | | *
* \ \ `-. \_ __\ /__ _/ .-` / / *
* ======`-.____`-.___\_____/___.-`____.-'====== *
* `=---=' *
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
* <20><><EFBFBD><EFBFBD><E6B1A3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
* *
********************************************************/
#include "QByteArray"
#include"QString"
#define GET_MODEBOARD_TEMP 0x01
#define GET_PN_NUMBER 0x03
#define GET_SN_NUMBER 0x04
#define GET_MANUFACTURE_DATA 0x06
#define GET_MANUFACTOR_INFO 0x09
#define GET_PIXEL_LENGTH 0x0a
#define GET_TEC_TEMP 0x13
#define SET_TEC_TEMP 0x12
#define GET_OPTICFLAT_TEMP 0x35
#define GET_CIRCUIT_BOARD_TEMP 0x36
#define SET_INTEGRAL_TIME 0x14
#define GET_INTEGRAL_TIME 0x41
#define GET_MAX_INTEGRAL_TIME 0x42
#define GET_MIN_INTEGRAL_TIME 0x43
#define ASYNCHRONOUS_COLLECT_DARK 0x23
#define ASYNCHRONOUS_START_COLLECTION 0x16
#define ASYNCHRONOUS_READ_DATA 0x17
#define SET_AVERAGE_NUMBER 0x28
#define SYNCHRONIZATION_GET_DATA 0x1e
#define SYNCHRONIZATION_GET_DARK 0x2f
#define EXTERNAL_TRIGGER_ENABLE 0x1f
#define SET_XENON_LAMP_DELAY_TIME 0x24
#define GET_WAVELENGTH_CALIBRATION_COFF 0x55
#define GET_STAT_OF_LAMPOUT 0x60
#define SET_GPIO 0x61
namespace OptoSky
{
void SetPortName(QString comname, qint32 bandrate=115200);
void closeport();
void SendComment(QByteArray Comment);
void SendComment(char comid);
void SendComment(QByteArray Comment, QByteArray Data);
bool GetReturn(QByteArray id, QByteArray &data);
bool GetReturn(char id, QByteArray &data);
bool GetReturn(QByteArray &data);
void SendComment(char comid, QByteArray Data);
bool isSensorInit();
void RemoveHeaderandEnd(QByteArray &buf);
}

Binary file not shown.

View File

@ -0,0 +1,14 @@
#include "SensorBase.h"
SensorBase::SensorBase()
{
SensorInfo.isSensorInit = false;
}
SensorBase::~SensorBase()
{
}

View File

@ -0,0 +1,132 @@
#pragma once
#include <QObject>
/******************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD> : SensorBase.cpp
* <20><><EFBFBD><EFBFBD> : <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD> :
* <20><><EFBFBD><EFBFBD> : xin
* <20><><EFBFBD><EFBFBD> : renlixin@iris-rs.cn
* <20><><EFBFBD><EFBFBD> : 2021-1-15
********************************************************
* *
* _ooOoo_ *
* o8888888o *
* 88" . "88 *
* (| -_- |) *
* O\ = /O *
* ____/`---'\____ *
* .' \\| |// `. *
* / \\||| : |||// \ *
* / _||||| -:- |||||- \ *
* | | \\\ - /// | | *
* | \_| ''\---/'' | | *
* \ .-\__ `-` ___/-. / *
* ___`. .' /--.--\ `. . __ *
* ."" '< `.___\_<|>_/___.' >'"". *
* | | : `- \`.;`\ _ /`;.`/ - ` : | | *
* \ \ `-. \_ __\ /__ _/ .-` / / *
* ======`-.____`-.___\_____/___.-`____.-'====== *
* `=---=' *
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
* <20><><EFBFBD><EFBFBD><E6B1A3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
* *
********************************************************/
///һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>delete
enum emDataType
{
DNVALUE=1,
REFVALUE=2,
DARKNESS=3
};
struct STROnePlot
{
long BandNum;
float *Plot;
bool isInit;
float temp;
float shutter;
QStringList wavelenthlist;
long maxDNvalue;
bool hasDarkCorrect;
emDataType DataType;
STROnePlot() {
BandNum = 0;
isInit = false;
hasDarkCorrect = false;
Plot = nullptr;
DataType = DNVALUE;
}
~STROnePlot() {
if (!isInit)
{
delete[] Plot;
isInit = false;
}
}
};
struct STRSensorInfo
{
QString SensorName;
long maxValue;
long BandNum;
QString WavelenthStr;
QStringList wavelenthlist;
//double *wavelenth;
bool isSensorInit;
QString serialnumber;
};
class SensorBase : public QObject
{
Q_OBJECT
public:
SensorBase();
virtual ~SensorBase();
//************************************
// Method: <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// FullName: SensorBase::initSensor
// Access: virtual public
// Returns: void
// Qualifier:
//************************************
virtual bool initSensor(int id=0)=0;
//************************************
// Method: Settingshuttertime <20><><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ʱ<EFBFBD><CAB1>
// FullName: SensorBase::Settingshuttertime
// Access: virtual public
// Returns: void
// Qualifier:
// Parameter: int msc
//************************************
virtual void Settingshuttertime(float msc)=0;
//************************************
// Method: SettingTemprature <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// FullName: SensorBase::SettingTemprature
// Access: virtual public
// Returns: void
// Qualifier:
// Parameter: float temp
//************************************
virtual void SettingTemprature(float temp)=0;
virtual float GettingTempratrue() = 0;
virtual STRSensorInfo GetSensorInfo()=0;
virtual void SettingShutterOpen(bool isopen)=0;
virtual void SettingSwitchShutter(bool isright)=0;
virtual void GetOnePlot(STROnePlot &OnePlot,bool Dark=false)=0;
virtual void CloseSensor()=0;
virtual void GetOneDark(STROnePlot &darkplot) = 0;
QString SensorType;
int Sensorid;
STRSensorInfo SensorInfo;
STROnePlot DarkNess;
};

View File

@ -0,0 +1,238 @@
#include "SensorMannager.h"
#include "SensorQExPRO.h"
#include"qthread"
#include "logout.h"
#include "QDateTime"
#include "QLocale"
#include"SensorOptoSky.h"
int maxtime = 30000;
SensorMannager::SensorMannager(QObject *parent )
: QObject(parent)
{
Numberofscan = 5;
//Sensor = new SensorQExPRO(QEPRO_QE);
Sensor = new SensorOptoSky(ATP6500,"COM12");
Sensor->initSensor();
}
SensorMannager::~SensorMannager()
{
delete Sensor;
logout::out("<EFBFBD>˳<EFBFBD>",1);
}
void SensorMannager::opensensor()
{
Sensor->initSensor();
}
void SensorMannager::CloseSensor()
{
Sensor->CloseSensor();
}
long SensorMannager::SensorOpt(int persent)
{
long maxvalue = Sensor->SensorInfo.maxValue*1.0*persent / 100;
STROnePlot plot;
long maxvaluenow = 0;
float shutternow = 10;
if (Sensor->SensorType=="USB2000PLUS")
{
// shutternow = 1;
}
Sensor->Settingshuttertime(shutternow);
Sensor->GetOnePlot(plot);
if (!plot.isInit)
{
return -1;
}
maxvaluenow = Getmaxvalue(plot.Plot,4, plot.BandNum-4);
logout::out("<EFBFBD>Զ<EFBFBD><EFBFBD>ع<EFBFBD>Ϊ: " + QString::number(shutternow) + " <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ֵΪ" + QString::number(maxvaluenow),1);
//QThread::msleep(1000);
int numberoftry = 0;
while (maxvaluenow<maxvalue*0.95 ||maxvaluenow>maxvalue)
{
if (maxvaluenow > maxvalue)
{
shutternow = shutternow *0.9;
}
else
{
shutternow = maxvalue * 0.98 / (maxvaluenow * 1.0)*shutternow + 1;
}
if (shutternow>maxtime)
{
shutternow = maxtime;
}
//QThread::msleep(100);
Sensor->Settingshuttertime(shutternow);
Sensor->GetOnePlot(plot);
if (plot.isInit)
{
maxvaluenow = Getmaxvalue(plot.Plot, 4, plot.BandNum - 4);
}
numberoftry++;
logout::out("<EFBFBD>Զ<EFBFBD><EFBFBD>ع<EFBFBD>Ϊ: " + QString::number(shutternow) + " <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ֵΪ"+QString::number(maxvaluenow),1);
if (numberoftry>200)
{
logout::out("<EFBFBD>عⳢ<EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ع<EFBFBD>ʧ<EFBFBD><CAA7>",3);
return -1;
}
if (shutternow == maxtime)
{
logout::out("<EFBFBD>ع<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>",3);
return -1*maxtime;
}
}
logout::out("<EFBFBD>ع<EFBFBD><EFBFBD>ɹ<EFBFBD> <20>ع<EFBFBD>ʱ<EFBFBD><CAB1>Ϊ: "+QString::number(shutternow)+" <20><><EFBFBD><EFBFBD>",1);
return shutternow;
}
long SensorMannager::Getmaxvalue(float *arr, int start, int lenth)
{
long val = -1;
for (size_t i = start; i < lenth; i++)
{
if (val <= arr[i])
{
val = arr[i];
}
}
return val;
}
void SensorMannager::SetnumbertoGot(int nscan)
{
Numberofscan = nscan;
}
void SensorMannager::GetSifData(QString outfilepath, bool isskyfirs /*= true*/)
{
Sensor->SettingShutterOpen(true);//ȷ<><C8B7>shutter<65><72><EFBFBD><EFBFBD>
QThread::msleep(50);
Sensor->SettingSwitchShutter(true);//<2F>л<EFBFBD>Ϊsky
logout::out("Switch <20>л<EFBFBD><D0BB><EFBFBD>SKY",1);
QThread::msleep(50);
//////////////////////////<2F>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>////////////////////////////////////////////////
float skyshutter=SensorOpt();
for (size_t i = 0; i < 3; i++)
{
if (skyshutter!=-1)
{
break;
}
skyshutter = SensorOpt();
}
/////////////////////////////////////////////
if (skyshutter==-1)//opt<70><74><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>δ-1 ˵<><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",3);
return;
}
skyshutter = abs(skyshutter);
Sensor->SettingSwitchShutter(false);//<2F>л<EFBFBD>ΪVEG
logout::out("Switch <20>л<EFBFBD><D0BB><EFBFBD>VEG",1);
QThread::msleep(50);
//////////////////////////veg////////////////////////////////////////////////
float vegshutter = SensorOpt();
for (size_t i = 0; i < 3; i++)
{
if (vegshutter ==-1 )
{
break;
}
vegshutter = SensorOpt();
}
if (vegshutter == -1)
{
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",3);
return;
}
vegshutter = abs(vegshutter);
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
//////////////////////////<2F>򿪴<EFBFBD><F2BFAAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>////////////////////////////////////////////////
FILE *fp = fopen(outfilepath.toStdString().c_str(), "w");
if (fp==NULL)
{
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>" + outfilepath + "ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>", 3);
return;
}
//fprintf(fp, "%s<><73>
STROnePlot oneplot;
float tempp = Sensor->GettingTempratrue();
WriteTitletoCSV(fp, Sensor->SensorInfo.SensorName,Numberofscan, tempp, Sensor->SensorInfo.WavelenthStr, skyshutter, vegshutter);
logout::setoutlevel(10);
Sensor->SettingSwitchShutter(true);//<2F>л<EFBFBD><D0BB><EFBFBD>sky
Sensor->Settingshuttertime(skyshutter);
for (size_t i = 0; i < Numberofscan; i++)
{
logout::out("<EFBFBD><EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>"+QString::number(i+1)+"<EFBFBD><EFBFBD>Sky <20><><EFBFBD><EFBFBD>");
Sensor->GetOnePlot(oneplot,true);
writeonedatatoCSV(fp, oneplot);
}
Sensor->SettingSwitchShutter(false);//<2F>л<EFBFBD>ΪVEG
Sensor->Settingshuttertime(vegshutter);
for (size_t i = 0; i < Numberofscan; i++)
{
logout::out("<EFBFBD><EFBFBD>ʼ<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>" + QString::number(i+1) + "<EFBFBD><EFBFBD>Veg <20><><EFBFBD><EFBFBD>");
Sensor->GetOnePlot(oneplot,true);
writeonedatatoCSV(fp, oneplot);
}
fflush(fp);
fclose(fp);
logout::out("<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",1);
logout::setoutlevel();
}
void SensorMannager::writeonedatatoCSV(FILE *fp, STROnePlot plot)
{
//.fprintf(fp, "%s,%s,%s\n", xvaluetoWrite.at(i).toStdString().c_str()
size_t lenth = plot.BandNum;
size_t i;
for (i = 0; i < lenth-1; i++)
{
fprintf(fp, "%s,", QString::number(plot.Plot[i], 'f', 1).toStdString().c_str());
}
fprintf(fp, "%s\n", QString::number(plot.Plot[i], 'f', 1).toStdString().c_str());
}
void SensorMannager::WriteTitletoCSV(FILE *fp, QString sensname, int NmberofScan, float temp, QString wavestring, float skyshutter, float vegshutter)
{
if (fp == NULL)
{
return;
}
QDateTime datetime = QDateTime::currentDateTime();
QLocale locale = QLocale::English;
QString datestr = locale.toString(datetime, "ddd MMM dd hh:mm:ss yyyy");
fprintf(fp, "observation date and time: %s\n", datestr.toStdString().c_str());
fprintf(fp, "numberofscan: %s\n", QString::number(Numberofscan).toStdString().c_str());
fprintf(fp, "spectrometer: %s\n", sensname.toStdString().c_str());
fprintf(fp, "ambient temperature: %s\n", QString::number(temp,'f',2).toStdString().c_str());
fprintf(fp, "%s\n", wavestring.toStdString().c_str());
fprintf(fp, "integration time 1: %s\n", QString::number(skyshutter, 'f', 2).toStdString().c_str());
fprintf(fp, "integration time 2: %s\n", QString::number(vegshutter, 'f', 2).toStdString().c_str());
}

View File

@ -0,0 +1,78 @@
#pragma once
/******************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD> : SensorMannager.h
* <20><><EFBFBD><EFBFBD> :
* <20><><EFBFBD><EFBFBD> :
* <20><><EFBFBD><EFBFBD> : xin
* <20><><EFBFBD><EFBFBD> : renlixin@iris-rs.cn
* <20><><EFBFBD><EFBFBD> : 2021-2-22
********************************************************
* *
* _ooOoo_ *
* o8888888o *
* 88" . "88 *
* (| -_- |) *
* O\ = /O *
* ____/`---'\____ *
* .' \\| |// `. *
* / \\||| : |||// \ *
* / _||||| -:- |||||- \ *
* | | \\\ - /// | | *
* | \_| ''\---/'' | | *
* \ .-\__ `-` ___/-. / *
* ___`. .' /--.--\ `. . __ *
* ."" '< `.___\_<|>_/___.' >'"". *
* | | : `- \`.;`\ _ /`;.`/ - ` : | | *
* \ \ `-. \_ __\ /__ _/ .-` / / *
* ======`-.____`-.___\_____/___.-`____.-'====== *
* `=---=' *
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
* <20><><EFBFBD><EFBFBD><E6B1A3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
* *
********************************************************/
#include <QObject>
#include "SensorBase.h"
enum SensorType
{
QESENSOR = 1,
};
class SensorMannager : public QObject
{
Q_OBJECT
public:
SensorMannager(QObject *parent=0 );
~SensorMannager();
SensorBase *Sensor;
//************************************
// Method: SensorOpt <20>Զ<EFBFBD><D4B6>Ż<EFBFBD> <20><><EFBFBD><EFBFBD>persentΪĬ<CEAA><C4AC><EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF> 0<><30>100 Ĭ<><C4AC><EFBFBD><EFBFBD>100
// FullName: SensorMannager::SensorOpt
// Access: public
// Returns: void
// Qualifier:
// Parameter: int persent
//************************************
void opensensor();
void CloseSensor();
long SensorOpt(int persent=100);
long Getmaxvalue(float *arr, int start, int lenth);
void SetnumbertoGot(int nscan);
void GetSifData(QString outfilepath,bool isskyfirs = true);
private:
int Numberofscan;
void writeonedatatoCSV(FILE *fp, STROnePlot plot);
void WriteTitletoCSV(FILE *fp,QString sensname, int NmberofScan, float temp, QString wavestring, float skyshutter, float vegshutter);
};

View File

@ -0,0 +1,306 @@
#include "SensorOptoSky.h"
#include "OptoSkyType.h"
#include "logout.h"
#include "QtEndian"
using namespace OptoSky;
SensorOptoSky::SensorOptoSky(OPTOSENSORTYPE type, QString comname, qint32 bandrate)
{
sensortype = type;
SensorType = "opt";
SensorInfo.SensorName = "opotsky";
COMname = comname;
BandRate = bandrate;
shutter.resize(2);
//SendComment(comi);
}
SensorOptoSky::SensorOptoSky(OPTOSENSORTYPE type, QString comname)
{
sensortype = type;
SensorType = "opt";
SensorInfo.SensorName = "opotsky";
COMname = comname;
BandRate = 115200;
shutter.resize(2);
}
bool SensorOptoSky::initSensor(int id /*= 0*/)
{
OptoSky::SetPortName(COMname, BandRate);
if (!OptoSky::isSensorInit())
{
return false;
}
SensorInfo = GetSensorInfo();
float a = GettingTempratrue();
//SendComment()
return true;
}
void SensorOptoSky::Settingshuttertime(float msc)
{
if (!OptoSky::isSensorInit())
{
return;
}
shuttertime = (int)msc;
shutter[0] = (int)msc / 256;
shutter[1] = (int)msc % 256;
QByteArray temp;
SendComment(SET_INTEGRAL_TIME,shutter);
GetReturn(SET_INTEGRAL_TIME,temp);
}
void SensorOptoSky::SettingTemprature(float temp)
{
QByteArray buf;
buf.resize(2);
if (temp<0)
{
buf[0] = 0xff;
}
else
{
buf[1] = 0x00;
}
buf[1] = (int)abs(temp);
SendComment(SET_TEC_TEMP, buf);
GetReturn(SET_TEC_TEMP, buf);
}
float SensorOptoSky::GettingTempratrue()
{
if (!OptoSky::isSensorInit())
{
return 0;
}
QByteArray buf;
SendComment(GET_TEC_TEMP);
GetReturn(GET_TEC_TEMP, buf);
QString str;
str.append(buf);
float ret = str.toFloat();
return ret;
}
STRSensorInfo SensorOptoSky::GetSensorInfo()
{
STRSensorInfo setem;
if (!OptoSky::isSensorInit())
{
return setem;
}
STRSensorInfo se;
QByteArray buf;
SendComment(GET_PN_NUMBER);
GetReturn(GET_PN_NUMBER, buf);
QString str;
str.append(buf);
se.SensorName = str;
logout::out("<EFBFBD><EFBFBD>ͺ<EFBFBD>Ϊ<EFBFBD><EFBFBD>" + str);
SendComment(GET_SN_NUMBER);
GetReturn(GET_SN_NUMBER, buf);
str.clear();
str.append(buf);
logout::out("<EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>Ϊ<EFBFBD><EFBFBD>" + str);
SendComment(GET_PIXEL_LENGTH);
GetReturn(GET_PIXEL_LENGTH, buf);
se.BandNum = buf[0] * 256 + buf[1];
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
Settingshuttertime(6);
SendComment(SYNCHRONIZATION_GET_DATA);
GetReturn(SYNCHRONIZATION_GET_DATA, buf);
se.BandNum = (buf.size() - 1)/2;
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
getwavelenthlist(se);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>޷<EFBFBD><DEB7><EFBFBD>ȡ <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>δ<EFBFBD><CEB4>ȡ
//////////////////////////ģ<><C4A3><EFBFBD>ָ<EFBFBD>////////////////////////////////////////////////
QByteArray bbb;
bbb.resize(2);
bbb[0] = 0x00;
bbb[1] = 0x01;
SendComment(SET_AVERAGE_NUMBER, bbb);
GetReturn(SET_AVERAGE_NUMBER, bbb);
se.maxValue = 65535;
return se;
}
void SensorOptoSky::SettingShutterOpen(bool isopen)
{
}
void SensorOptoSky::SettingSwitchShutter(bool isright)
{
}
void SensorOptoSky::GetOnePlot(STROnePlot &OnePlot, bool Dark)
{
OnePlot.temp = GettingTempratrue();
SendComment(SYNCHRONIZATION_GET_DATA,shutter);
OnePlot.shutter = shuttertime;
QByteArray buf;
if (!GetReturn(SYNCHRONIZATION_GET_DATA, buf))
{
OnePlot.isInit = false;
return;
}
if ((unsigned char )buf[0]==0x00)
{
//OnePlot.isInit = true;
}
else
{
OnePlot.isInit = false;
}
int bandsumnwo = SensorInfo.BandNum;
unsigned short *arr = new unsigned short[bandsumnwo];
memcpy(arr, buf.data() + 1, bandsumnwo*2);
if (!OnePlot.isInit)
{
OnePlot.Plot = new float[bandsumnwo];
OnePlot.isInit = true;
}
for (size_t i = 0; i < bandsumnwo; i++)
{
OnePlot.Plot[i] = qToBigEndian(arr[i]);
}
delete[] arr;
OnePlot.BandNum = bandsumnwo;
OnePlot.maxDNvalue = SensorInfo.maxValue;
OnePlot.wavelenthlist = SensorInfo.wavelenthlist;
if (Dark)
{
if (DarkNess.isInit)
{
if (DarkNess.shutter != shuttertime)
{
GetOneDark(DarkNess);
}
}
else
{
GetOneDark(DarkNess);
}
for (size_t i = 0; i < bandsumnwo; i++)
{
OnePlot.Plot[i] = OnePlot.Plot[i] - DarkNess.Plot[i];
}
}
}
void SensorOptoSky::CloseSensor()
{
closeport();
}
void SensorOptoSky::GetOneDark(STROnePlot &darkplot)
{
STROnePlot &OnePlot = darkplot;
OnePlot.temp = GettingTempratrue();
OnePlot.shutter = shuttertime;
SendComment(SYNCHRONIZATION_GET_DARK, shutter);
QByteArray buf;
if (!GetReturn(SYNCHRONIZATION_GET_DARK, buf))
{
OnePlot.isInit = false;
return;
}
if ((unsigned char)buf[0] == 0x00)
{
//OnePlot.isInit = true;
}
else
{
OnePlot.isInit = false;
}
int bandsumnwo = SensorInfo.BandNum;
unsigned short *arr = new unsigned short[bandsumnwo];
memcpy(arr, buf.data() + 1, bandsumnwo * 2);
if (!OnePlot.isInit)
{
OnePlot.Plot = new float[bandsumnwo];
OnePlot.isInit = true;
}
for (size_t i = 0; i < bandsumnwo; i++)
{
OnePlot.Plot[i] = qToBigEndian(arr[i]);
}
delete[] arr;
OnePlot.BandNum = bandsumnwo;
OnePlot.maxDNvalue = SensorInfo.maxValue;
OnePlot.wavelenthlist = SensorInfo.wavelenthlist;
OnePlot.DataType = DARKNESS;
}
SensorOptoSky::~SensorOptoSky()
{
CloseSensor();
}
void SensorOptoSky::RemoveHeaderandEnd(QByteArray &buf)
{
if (buf.size()<6)
{
return;
}
buf.remove(0, 5);
buf.remove(buf.size() - 1,1);
}
void SensorOptoSky::getwavelenthlist(STRSensorInfo &se)
{
if (!OptoSky::isSensorInit())
{
return ;
}
QByteArray bufin;
bufin.resize(2);
bufin[0] = 0x00;
bufin[1] = 0x01;
QByteArray buf;
SendComment(GET_WAVELENGTH_CALIBRATION_COFF,bufin);
GetReturn(GET_WAVELENGTH_CALIBRATION_COFF, buf);
float a[4];
memcpy(a, buf.data() + 16, 4 * 4);
int bandsss = se.BandNum;
QStringList strlist;
QString str="";
int i = 0;
for ( i = 0; i <bandsss-1 ; i++)
{
float wavelenth = a[0] * i*i*i + a[1] * i*i + a[2] * i + a[3];
strlist.append(QString::number(wavelenth, 'f', 2) );
str = str + QString::number(wavelenth, 'f', 2) + ",";
}
float wavelenth = a[0] * i*i*i + a[1] * i*i + a[2] * i + a[3];
str = str + QString::number(wavelenth, 'f', 2);
strlist.append(QString::number(wavelenth, 'f', 2));
se.wavelenthlist = strlist;
se.WavelenthStr = str;
}

View File

@ -0,0 +1,81 @@
#pragma once
#pragma execution_character_set("utf-8")
/******************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD> : SensorOptoSky.h
* <20><><EFBFBD><EFBFBD> :
* <20><><EFBFBD><EFBFBD> :
* <20><><EFBFBD><EFBFBD> : xin
* <20><><EFBFBD><EFBFBD> : renlixin@iris-rs.cn
* <20><><EFBFBD><EFBFBD> : 2021-2-22
********************************************************
* *
* _ooOoo_ *
* o8888888o *
* 88" . "88 *
* (| -_- |) *
* O\ = /O *
* ____/`---'\____ *
* .' \\| |// `. *
* / \\||| : |||// \ *
* / _||||| -:- |||||- \ *
* | | \\\ - /// | | *
* | \_| ''\---/'' | | *
* \ .-\__ `-` ___/-. / *
* ___`. .' /--.--\ `. . __ *
* ."" '< `.___\_<|>_/___.' >'"". *
* | | : `- \`.;`\ _ /`;.`/ - ` : | | *
* \ \ `-. \_ __\ /__ _/ .-` / / *
* ======`-.____`-.___\_____/___.-`____.-'====== *
* `=---=' *
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
* <20><><EFBFBD><EFBFBD><E6B1A3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
* *
********************************************************/
#include <SensorBase.h>
enum OPTOSENSORTYPE
{
ATP6500 = 1
};
class SensorOptoSky : public SensorBase
{
Q_OBJECT
public:
SensorOptoSky(OPTOSENSORTYPE type, QString comname);
SensorOptoSky(OPTOSENSORTYPE type, QString comname, qint32 bandrate);
bool initSensor(int id = 0);
void Settingshuttertime(float msc) ;
//************************************
// Method: SettingTemprature <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// FullName: SensorBase::SettingTemprature
// Access: virtual public
// Returns: void
// Qualifier:
// Parameter: float temp
//************************************
void SettingTemprature(float temp);
float GettingTempratrue() ;
STRSensorInfo GetSensorInfo();
void SettingShutterOpen(bool isopen);
void SettingSwitchShutter(bool isright);
void GetOnePlot(STROnePlot &OnePlot, bool Dark=false) ;
void CloseSensor() ;
void GetOneDark(STROnePlot &darkplot);
OPTOSENSORTYPE sensortype;
QString COMname;
qint32 BandRate;
~SensorOptoSky();
private:
void RemoveHeaderandEnd(QByteArray &buf);
void getwavelenthlist( STRSensorInfo &se);
QByteArray shutter;
int shuttertime;
};

View File

@ -0,0 +1,327 @@
#include "SensorQExPRO.h"
#include "QDebug"
#include "api/seabreezeapi/SeaBreezeAPI.h"
#include "logout.h"
#include "QMetaEnum"
#include "QThread"
SensorQExPRO::SensorQExPRO(EMQEType qetype)
{
QEType = qetype;
if (qetype==QEPRO_QE)
{
}
else if(qetype == USB2000PLUS_QE)
{
}
else
{
OutputMod = nullptr;
Shuteroffcom = nullptr;
Shuteroncom = nullptr;
}
}
SensorQExPRO::~SensorQExPRO()
{
if (SensorInfo.isSensorInit)
{
sbapi_shutdown();
}
}
bool SensorQExPRO::initSensor(int id)
{
//sbapi_shutdown();
sbapi_initialize();
sbapi_probe_devices();
int number_of_QE = sbapi_get_number_of_device_ids();
logout::out("<EFBFBD>ҵ<EFBFBD> " + QString::number(number_of_QE) + "<EFBFBD><EFBFBD><EFBFBD>",2);
if (number_of_QE <= id)
{
return false;
}
Device_ids=new long[number_of_QE]();
sbapi_get_device_ids(Device_ids, number_of_QE);
logout::out("<EFBFBD>豸idΪ<EFBFBD><EFBFBD>" + QString::number(Device_ids[id]),2);
DeviceId = Device_ids[id];
char namearr[100];
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
FLAG= sbapi_get_device_type(DeviceId, &ERR, namearr, 99);
if (FLAG!=0)
{
QString sensorname = QString(namearr);
QEType = getEMUbyQstring(sensorname);
SensorType = sensorname;
SensorInfo.SensorName = sensorname;
logout::out("<EFBFBD><EFBFBD>ͺţ<EFBFBD>" + sensorname,2);
}
Sensorid = DeviceId;
//<2F><><EFBFBD><EFBFBD><EFBFBD>
FLAG= sbapi_open_device(DeviceId, &ERR);
logout::out("<EFBFBD><EFBFBD>򿪣<EFBFBD>" + QString(sbapi_get_error_string(ERR)),2);
if (FLAG!=0)
{
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7> <20><><EFBFBD><EFBFBD>false
return false;
}
SensorInfo.isSensorInit = true;
int maxf=sbapi_get_number_of_shutter_features(DeviceId, &ERR);;
long fff;
// sbapi_get_shutter_features(DeviceId, &ERR, &fff,maxf);
// sbapi_shutter_set_shutter_open(DeviceId, fff,&ERR, 0);
// logout::out("<22><EFBFBD>򿪣<EFBFBD>" + QString(sbapi_get_error_string(ERR)));
// qDebug() << "hello";
SensorInfo=GetSensorInfo();
//Ϊ<>¶ȶ<C2B6><C8B6><EFBFBD><EFBFBD>õ<EFBFBD>
Numberoftempratrue= sbapi_get_number_of_thermo_electric_features(DeviceId, &ERR);
TemPratrueId=new long[Numberoftempratrue]();
Numberoftempratrue=sbapi_get_thermo_electric_features(DeviceId, &ERR, TemPratrueId, Numberoftempratrue);
sbapi_tec_set_enable(DeviceId, TemPratrueId[0], &ERR, 1);
return true;
}
void SensorQExPRO::Settingshuttertime(float msc)
{
if (!SensorInfo.isSensorInit)
{
return;
}
shuttertime = msc;
sbapi_spectrometer_set_integration_time_micros(DeviceId, SpecMetersId[0], &ERR, msc*1000);
//logout::out("<22><><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD>䣺" + QString(sbapi_get_error_string(ERR)),2);
}
void SensorQExPRO::SettingTemprature(float temp)
{
sbapi_tec_set_temperature_setpoint_degrees_C(DeviceId, TemPratrueId[0], &ERR,temp);
QThread::msleep(100);
}
STRSensorInfo SensorQExPRO::GetSensorInfo()
{
STRSensorInfo sensorinof;
//return sensorinof;
if (!SensorInfo.isSensorInit)
{
return sensorinof;
}
int ERR=0;
sensorinof.isSensorInit = true;
sensorinof.BandNum= sbapi_get_number_of_spectrometer_features(DeviceId, &ERR);
SpecMetersId = new long[sensorinof.BandNum]();
int numm= sbapi_get_spectrometer_features(DeviceId, &ERR, SpecMetersId, sensorinof.BandNum);
sensorinof.BandNum = sbapi_spectrometer_get_formatted_spectrum_length(DeviceId, SpecMetersId[0], &ERR);
double *wavelenth = new double[sensorinof.BandNum]();
sbapi_spectrometer_get_wavelengths(DeviceId, SpecMetersId[0], &ERR,wavelenth, sensorinof.BandNum);
sensorinof.wavelenthlist.clear();
sensorinof.WavelenthStr = "";
int i = 0;
for (i = 0; i < sensorinof.BandNum-1; i++)
{
sensorinof.WavelenthStr = sensorinof.WavelenthStr + QString::number(wavelenth[i], 'f', 4)+",";
sensorinof.wavelenthlist.append(QString::number(wavelenth[i], 'f', 4));
}
sensorinof.WavelenthStr = sensorinof.WavelenthStr + QString::number(wavelenth[i], 'f', 4);
sensorinof.wavelenthlist.append(QString::number(wavelenth[i], 'f', 4));
sensorinof.maxValue = sbapi_spectrometer_get_maximum_intensity(DeviceId, SpecMetersId[0], &ERR);
char namearr[100];
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
FLAG = sbapi_get_device_type(DeviceId, &ERR, namearr, 99);
if (FLAG != 0)
{
QString sensorname = QString(namearr);
QEType = getEMUbyQstring(sensorname);
SensorType = sensorname;
sensorinof.SensorName = sensorname;
logout::out("<EFBFBD><EFBFBD>ͺţ<EFBFBD>" + sensorname, 2);
}
return sensorinof;
}
void SensorQExPRO::SettingShutterOpen(bool isopen)
{
//<2F><>ݮ<EFBFBD><DDAE> 4<><34><EFBFBD><EFBFBD>
system("gpio mode 4 output");
if (isopen)
{
system("gpio write 4 1");
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Shutter gpio",2);
}
else
{
system("gpio write 4 0");
logout::out("<EFBFBD>ر<EFBFBD> Shutter gpio",2);
}
if (QEType==QEPRO_QE)
{
SetQEProShutter(isopen);
}
QThread::msleep(100);
}
void SensorQExPRO::SettingSwitchShutter(bool isright)
{
system("gpio mode 5 output");
if (isright)
{
system("gpio write 5 1");
logout::out("<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD>SKY",2);
}
else
{
system("gpio write 5 0");
logout::out("<EFBFBD>л<EFBFBD><EFBFBD><EFBFBD>VEG",2);
}
}
void SensorQExPRO::GetOnePlot(STROnePlot &OnePlot, bool Dark)
{
if (!SensorInfo.isSensorInit)
{
return;
}
if (!OnePlot.isInit || OnePlot.BandNum != SensorInfo.BandNum)
{
if (OnePlot.isInit)
{
delete[] OnePlot.Plot;
}
OnePlot.Plot = new float[SensorInfo.BandNum];
OnePlot.BandNum = SensorInfo.BandNum;
}
if (!SensorInfo.isSensorInit)
{
return;
}
double *tempvalue = new double[SensorInfo.BandNum];
OnePlot.shutter = shuttertime;
sbapi_spectrometer_get_formatted_spectrum(DeviceId,SpecMetersId[0], &ERR, tempvalue, SensorInfo.BandNum);
logout::out("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>" + QString(sbapi_get_error_string(ERR)),5);
if (QEType != USB2000PLUS_QE)
{
OnePlot.temp = GettingTempratrue();
logout::out("<EFBFBD><EFBFBD>ȡ<EFBFBD>ȣ<EFBFBD>" + QString(sbapi_get_error_string(ERR)) + " <20><EFBFBD>Ϊ<EFBFBD><CEAA>" + QString::number(OnePlot.temp, 'f', 2) + "<EFBFBD><EFBFBD>",2);
}
for (size_t i = 0; i < SensorInfo.BandNum; i++)
{
OnePlot.Plot[i] = tempvalue[i];
}
OnePlot.isInit = true;
delete[] tempvalue;
}
float SensorQExPRO::GettingTempratrue()
{
if (!SensorInfo.isSensorInit)
{
return -1000;
}
float temperature = (float)sbapi_tec_read_temperature_degrees_C(DeviceId, TemPratrueId[0], &ERR);
logout::out("<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>"+QString::number(temperature,'f',2),2);
return temperature;
}
void SensorQExPRO::CloseSensor()
{
if (SensorInfo.isSensorInit)
{
sbapi_shutdown();
SensorInfo.isSensorInit = false;
}
}
void SensorQExPRO::GetOneDark(STROnePlot &darkplot)
{
}
EMQEType SensorQExPRO::getEMUbyQstring(QString str)
{
if (str=="USB2000PLUS")
{
return USB2000PLUS_QE;
}
if (str == "QE65PRO")
{
return QE65PRO_QE;
}
if (str == "QE-PRO")
{
return QEPRO_QE;
}
if (str == "QE65000")
{
return QE65000_QE;
}
return NONQE;
}
void SensorQExPRO::SetQEProShutter( bool isopen)
{
unsigned char GPIO4output[64] = { 0xc1, 0xc0, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00,
0x10, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc5, 0xc4, 0xc3, 0xc2
};
unsigned char GPIO4on[64] = { 0xc1, 0xc0, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00,
0x10, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc5, 0xc4, 0xc3, 0xc2
};
unsigned char GPIO4_off[64] = { 0xc1, 0xc0, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00,
0x10, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc5, 0xc4, 0xc3, 0xc2
};
long FNid;
int FN = sbapi_get_number_of_raw_usb_bus_access_features(DeviceId, &ERR);
FN = sbapi_get_raw_usb_bus_access_features(DeviceId, &ERR, &FNid, FN);
QThread::msleep(100);
int lenth = sbapi_raw_usb_bus_access_write(DeviceId, FNid, &ERR, GPIO4output, 64, 0x01);
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>shutter Ϊgpio",2);
if (isopen)
{
lenth = sbapi_raw_usb_bus_access_write(DeviceId, FNid, &ERR, GPIO4on, 64, 0x01);
logout::out("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>Shutter",2);
}
else
{
lenth = sbapi_raw_usb_bus_access_write(DeviceId, FNid, &ERR, GPIO4_off, 64, 0x01);
logout::out("<EFBFBD>ر<EFBFBD><EFBFBD>ڲ<EFBFBD>Shutter",2);
}
}

View File

@ -0,0 +1,63 @@
#pragma once
#pragma execution_character_set("utf-8")
#include "SensorBase.h"
enum EMQEType
{
QEPRO_QE=1,
QE65PRO_QE=2,
USB2000PLUS_QE =3,
QE65000_QE = 4,
NONQE=-1
};
class SensorQExPRO : public SensorBase
{
Q_OBJECT
public:
SensorQExPRO(EMQEType qetype);
~SensorQExPRO();
bool initSensor(int id=0);
void Settingshuttertime(float msc);
//************************************
// Method: SettingTemprature <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// FullName: SensorBase::SettingTemprature
// Access: virtual public
// Returns: void
// Qualifier:
// Parameter: float temp
//************************************
void SettingTemprature(float temp);
STRSensorInfo GetSensorInfo() ;
void SettingShutterOpen(bool isopen);
//************************************
// Method: SettingSwitchShutter skyΪright
// FullName: SensorQExPRO::SettingSwitchShutter
// Access: public
// Returns: void
// Qualifier:
// Parameter: bool isright skyΪright
//************************************
void SettingSwitchShutter(bool isright);
void GetOnePlot(STROnePlot &OnePlot, bool Dark=false);
float GettingTempratrue();
void CloseSensor();
void GetOneDark(STROnePlot &darkplot);
EMQEType QEType;
private:
long *Device_ids;
long DeviceId;
int ERR = 0;
int FLAG = 0;
unsigned char *OutputMod, *Shuteroncom, *Shuteroffcom;
long Numberoftempratrue;
long *TemPratrueId;
long *SpecMetersId;
EMQEType getEMUbyQstring(QString str);
void SetQEProShutter(bool isopen);
float shuttertime;
;
};

View File

@ -0,0 +1,301 @@
#ifndef _TCPSERVER_H_
#define _TCPSERVER_H_
//
// Return Header values.
//
#define H_NO_ERROR (100)
#define H_COLLECT_ERROR (200)
#define H_COLLECT_NOT_LOADED (300)
#define H_INIT_ERROR (400)
#define H_FLASH_ERROR (500)
#define H_RESET_ERROR (600)
#define H_INTERPOLATE_ERROR (700)
#define H_OPTIMIZE_ERROR (800)
#define H_INSTRUMENT_CONTROL_ERROR (900)
//
// Return error codes.
//
#define NO_ERROR_ (0)
#define NOT_READY (-1)
#define NO_INDEX_MARKS (-2)
#define TOO_MANY_ZEROS (-3)
#define SCANSIZE_ERROR (-4)
// -5 unused
#define COMMAND_ERROR (-6)
#define INI_FULL (-7)
#define MISSING_PARAMETER (-8)
// -9 unused - now -20, -21, -22
#define VNIR_TIMEOUT (-10)
#define SWIR_TIMEOUT (-11)
#define VNIR_NOT_READY (-12)
#define SWIR1_NOT_READY (-13)
#define SWIR2_NOT_READY (-14)
#define VNIR_OPT_ERROR (-15)
#define SWIR1_OPT_ERROR (-16)
#define SWIR2_OPT_ERROR (-17)
#define ABORT_ERROR (-18)
#define PARAM_ERROR (-19)
#define VNIR_INTERP_ERROR (-20)
#define SWIR1_INTERP_ERROR (-21)
#define SWIR2_INTERP_ERROR (-22)
//
//
//
#define MAX_PARAMETERS (200)
//
// Detector Index Value
//
#define SWIR1 (0)
#define SWIR2 (1)
#define VNIR (2)
//
// Instrument Type values
//
#define V_INSTRUMENT_TYPE (1) // VNIR Only
#define DUAL_VNIR_INSTRUMENT_TYPE (2) // Dual VNIR
#define S1_INSTRUMENT_TYPE (4) // SWIR1 Only
#define VS1_INSTRUMENT_TYPE (5) // VNIR and SWIR1
#define S2_INSTRUMENT_TYPE (8) // SWIR2 ONly
#define VS2_INSTRUMENT_TYPE (9) // VNIR and SWIR2
#define S1S2_INSTRUMENT_TYPE (12) // SWIR1 and SWIR2
#define FR_INSTRUMENT_TYPE (13) // VNIR and SWIR1 and SWIR2
//
// Instrument Control values
//
#define IC_IT (0)
#define IC_GAIN (1)
#define IC_OFFSET (2)
#define IC_SHUTTER (3)
#define IC_TRIGGER (4)
//
// Union used to swap word to make double value
//
union dv
{
double d;
unsigned long l[sizeof(double) / sizeof(long)];
unsigned char c[sizeof(double)];
};
//
// Vnir Header section
//
struct Vnir_Header
{
int IT;
int scans;
int max_channel;
int min_channel;
int saturation;
int shutter;
int drift;
int dark_subtracted;
int reserved[8];
};
//
// Swir Header section
//
struct Swir_Header
{
int tec_status;
int tec_current;
int max_channel;
int min_channel;
int saturation;
int A_Scans;
int B_Scans;
int dark_current;
int gain;
int offset;
int scansize1;
int scansize2;
int dark_subtracted;
int reserved[3];
};
//
// return Spectrum Header
//
struct SpectrumHeader
{
int Header;
int errbyte;
int sample_count;
int trigger;
int voltage;
int current;
int temperature;
int motor_current;
int instrument_hours;
int instrument_minutes;
int instrument_type;
int AB;
int reserved[4];
Vnir_Header v_header;
Swir_Header s1_header;
Swir_Header s2_header;
};
//
// Acquire structure to return for Full Range Spectrometers
//
struct FRSpecStruct
{
SpectrumHeader FRHeader;
union
{
float f;
int i;
}SpecBuffer[2151];
};
//
// Acquire structure to return for Vnir Spectrometers
//
struct VSpecStruct
{
SpectrumHeader VHeader;
union
{
float f;
int i;
}SpecBuffer[701];
};
//
// Acquire structure to return for Swir1 Swir2 Spectrometers
//
struct S1S2SpecStruct
{
SpectrumHeader S1S2Header;
union
{
float f;
int i;
}SpecBuffer[1502];
};
//
// Acquire structure to return for Swir1 Spectrometers
//
struct S1SpecStruct
{
SpectrumHeader S1SpectrumHeader;
union
{
float f;
int i;
}SpecBuffer[801];
};
//
// Acquire structure to return for Swir2 Spectrometers
//
struct S2SpecStruct
{
SpectrumHeader S2Header;
union
{
float f;
int i;
}SpecBuffer[701];
};
//
// Acquire structure to return for Vnir/Swir1 Spectrometers
//
struct VS1SpecStruct
{
SpectrumHeader VS1Header;
union
{
float f;
int i;
}SpecBuffer[1502];
};
//
// Acquire structure to return for Vnir/Swir2 Spectrometers
//
struct VS2SpecStruct
{
SpectrumHeader VS2Header;
union
{
float f;
int i;
}SpecBuffer[1402];
};
//
// Ini struct for the flash
//
struct InitStruct
{
int Header; //header type used in TCP transfer.
int errbyte; //error code
char name[MAX_PARAMETERS][30]; //space for 200 entries with 30 character names
double value[MAX_PARAMETERS]; //corresponding data values for the 200 entries
int count; //The number of used entries
int verify; //the checksum
};
//
// Version structure for V Command
//
struct VersionStruct
{
int Header; //header type used in TCP transfer.
int errbyte; //error code
char version[30]; //30 character version string
double value; //version value
int type; // Type of instrument 1-Vnir, 4-Swir1, 5-Vnir/Swir1
}; // 8-Siwr2, 9-Vnir/Swir2
// 12-Swir1/Swir2, 13-Vnir/Swir1/Swir2
//
// Optimize structure for OPT command
//
struct OptimizeStruct
{
int Header; //header type used in TCP transfer.
int errbyte; //error code
int itime; //optimized integration time
int gain[2]; //optimized gain for 2 SWIRs
int offset[2]; //optimized offset for 2 SWIRs
};
//
// Param structure for INIT command
//
struct ParamStruct
{
int Header; //header type used in TCP transfer.
int errbyte; //error code
char name[30]; //30 character name
double value; //corresponding data values
int count; //number of entries used
};
//
// Instrument Control Structure for IC command
//
struct InstrumentControlStruct
{
int Header; //header type used in TCP transfer.
int errbyte; //error code
int detector; //detector value - IC_IT,IC_GAIN,IC_OFFSET,IC_SHUTTER
int cmdType; //detector command
int value; //command value
};
//
// Header Struct for Restore Command
//
struct HeaderStruct
{
int Header; // Header value used in TCP transfer
int errbyte; // error code
};
struct FRInterpSpecStruct
{
SpectrumHeader FRSpectrumHeader; //256 bytes (64 words)
//int arr[761];
float SpecBuffer[2151];
};
#endif

View File

@ -0,0 +1,63 @@
#include "logout.h"
#include "QDebug"
#include "QTextCodec"
QString colorcode = "\033[";
int outputlevel = 4;
logout::logout(QObject *parent)
: QObject(parent)
{
}
logout::~logout()
{
}
void logout::out(QString str,int level)
{
if (level>outputlevel)
{
return;
}
QTextCodec *codec = QTextCodec::codecForName("GBK");//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int colorint;
switch (level)
{
case 0:
{
break;
}
case 1:
{
qDebug() << "\033[32m";//<2F><>ɫ
break;
}
case 2:
{
qDebug() << "\033[35m";//<2F><>ɫ
break;
}
case 3:
{
qDebug() << "\033[31m";//<2F><>ɫ
break;
}
default:
{
break;
}
}
//str=codec->toUnicode(str.toStdString().c_str());
qDebug() <<str;
qDebug() << "\033[0m";
}
void logout::setoutlevel(int level /*= 4*/)
{
outputlevel = level;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <QObject>
class logout : public QObject
{
Q_OBJECT
public:
logout(QObject *parent);
~logout();
static void out(QString str, int level=0);
static void setoutlevel(int level = 4);
};