mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-10-19 19:49:42 +08:00
(1)将atp光谱仪的控制类更新到卓哥最新版,解决连接atp的问题;
(2)将读取OceanOptics的非线性校正文件 集成到定标程序中;
This commit is contained in:
@ -9,7 +9,7 @@ ZZ_ATPControl_Serial_Qt::ZZ_ATPControl_Serial_Qt(QObject* parent /*= nullptr*/)
|
||||
//emit SignalInit_Self();
|
||||
}
|
||||
|
||||
ZZ_ATPControl_Serial_Qt::~ZZ_ATPControl_Serial_Qt()
|
||||
ZZ_ATPControl_Serial_Qt::~ZZ_ATPControl_Serial_Qt()//
|
||||
{
|
||||
if (m_pSerialPort != NULL)
|
||||
{
|
||||
@ -72,7 +72,7 @@ int ZZ_ATPControl_Serial_Qt::Initialize(bool bIsUSBMode, std::string ucPortNumbe
|
||||
|
||||
GetDeviceInfo(m_diDeviceInfo);
|
||||
GetExposureTime_Init();
|
||||
|
||||
SetAvgTimes(1);
|
||||
|
||||
std::string::size_type szPostion = m_diDeviceInfo.strSN.find(strDeviceName);
|
||||
if (szPostion == std::string::npos)
|
||||
@ -196,15 +196,15 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceAttribute(DeviceAttribute &Attr)
|
||||
}
|
||||
m_daDeviceAttr.iMaxIntegrationTimeInMS = (ZZ_U8)qbRecv[1] + (ZZ_U8)qbRecv[0] * 256;
|
||||
|
||||
|
||||
///
|
||||
int iTempExpTime = 0;
|
||||
GetExposureTime(iTempExpTime);
|
||||
|
||||
iRes = SetExposureTime(10);
|
||||
iRes = SetExposureTime(m_daDeviceAttr.iMinIntegrationTimeInMS);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:GetDeviceAttribute Failed,Call SetExposureTime error.Exit Code:2";
|
||||
return 2;
|
||||
//return 2;
|
||||
}
|
||||
iRes = SingleShot(m_daDeviceAttr.iPixels);
|
||||
if (iRes != 0)
|
||||
@ -214,8 +214,7 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceAttribute(DeviceAttribute &Attr)
|
||||
}
|
||||
|
||||
SetExposureTime(iTempExpTime);
|
||||
|
||||
|
||||
///
|
||||
qbSend.clear();
|
||||
qbRecv.clear();
|
||||
qbSend.append(GET_WAVELENGTH_CALIBRATION_COEF);
|
||||
@ -257,6 +256,36 @@ int ZZ_ATPControl_Serial_Qt::SetDeviceTemperature(float fTemperature)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_ATPControl_Serial_Qt::SetAvgTimes(int iTimes /*= 1*/)
|
||||
{
|
||||
QByteArray qbSend, qbRecv;
|
||||
qbSend.clear();
|
||||
qbRecv.clear();
|
||||
qbSend.append(SET_AVERAGE_NUMBER);
|
||||
qbSend.resize(3);
|
||||
qbSend[1] = 0x00;
|
||||
qbSend[2] = 0x01;
|
||||
int iRes = SendCommand(qbSend);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:SetAvgTimes Failed.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
iRes = RecvData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:SetAvgTimes Failed.Exit Code:2";
|
||||
return 2;
|
||||
}
|
||||
iRes = ParseData(qbRecv);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:SetAvgTimes Failed.Exit Code:3";
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZZ_ATPControl_Serial_Qt::GetExposureTime_Init()
|
||||
{
|
||||
QByteArray qbSend, qbRecv;
|
||||
@ -326,7 +355,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData(QByteArray &qbData)
|
||||
int iCounter = 0;
|
||||
while (qbData.size() < 4)
|
||||
{
|
||||
m_pSerialPort->waitForReadyRead(1000);
|
||||
m_pSerialPort->waitForReadyRead(5000);
|
||||
QByteArray qbTemp = m_pSerialPort->readAll();
|
||||
qbData.append(qbTemp);
|
||||
|
||||
@ -335,7 +364,6 @@ int ZZ_ATPControl_Serial_Qt::RecvData(QByteArray &qbData)
|
||||
qDebug() << "Err:RecvData Failed,Not Enough Data.Exit Code:1" << qbData.size();
|
||||
return 1;
|
||||
}
|
||||
|
||||
iCounter++;
|
||||
}
|
||||
|
||||
@ -397,7 +425,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData_ShortLag(QByteArray &qbData)
|
||||
|
||||
if (iCounter > 6)
|
||||
{
|
||||
qDebug() << "Err:RecvData Failed,Not Enough Data.Exit Code:1" << qbData.size();
|
||||
qDebug() << "Err:RecvData_ShortLag Failed,Not Enough Data.Exit Code:1" << qbData.size();
|
||||
return 1;
|
||||
}
|
||||
iCounter++;
|
||||
@ -405,7 +433,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData_ShortLag(QByteArray &qbData)
|
||||
|
||||
if ((ZZ_U8)qbData[0] != (ZZ_U8)0xaa || (ZZ_U8)qbData[1] != (ZZ_U8)0x55)
|
||||
{
|
||||
qDebug() << "Err:RecvData Failed,Wrong Header.Exit Code:2" << qbData.size();
|
||||
qDebug() << "Err:RecvData_ShortLag Failed,Wrong Header.Exit Code:2" << qbData.size();
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -418,7 +446,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData_ShortLag(QByteArray &qbData)
|
||||
|
||||
if (iCounter > 6)
|
||||
{
|
||||
qDebug() << "Err:RecvData Failed,Incomplete Data.Exit Code:3" << qbData.size();
|
||||
qDebug() << "Err:RecvData_ShortLag Failed,Incomplete Data.Exit Code:3" << qbData.size();
|
||||
return 3;
|
||||
}
|
||||
iCounter++;
|
||||
@ -438,7 +466,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData_ShortLag(QByteArray &qbData)
|
||||
ZZ_U8 ucTemp = qbData[qbData.size() - 1];
|
||||
if ((ZZ_U8)usCheckSum != ucTemp)
|
||||
{
|
||||
qDebug() << "Err:RecvData Failed,Incorrect Check Sum.Exit Code:4" << "Total Recv:" << qbData.size() << "Check Sum:" << usCheckSum << "Not Equal To" << ucTemp;
|
||||
qDebug() << "Err:RecvData_ShortLag Failed,Incorrect Check Sum.Exit Code:4" << "Total Recv:" << qbData.size() << "Check Sum:" << usCheckSum << "Not Equal To" << ucTemp;
|
||||
//qbData.clear();
|
||||
//return 4;
|
||||
return 0;
|
||||
@ -467,16 +495,9 @@ int ZZ_ATPControl_Serial_Qt::Init_Self()
|
||||
|
||||
int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fMaxScaleFactor, float &fPredictedExposureTime)
|
||||
{
|
||||
int m_iThreadID=0;
|
||||
// qDebug() << "--------------------------Starting PerformAutoExposure" << " Thread ID:" << m_iThreadID;
|
||||
using namespace ZZ_MATH;
|
||||
// float fPredictedExposureTime;
|
||||
int iDeviceDepth = 65535;
|
||||
|
||||
|
||||
|
||||
// qDebug() << "MAX---Min" << fMaxScaleFactor << "---" << fMinScaleFactor << " Thread ID:" << m_iThreadID;
|
||||
|
||||
bool bFlagIsOverTrying = false;
|
||||
bool bFlagIsLowerMinExposureTime = false;
|
||||
bool bFlagIsOverMaxExposureTime = false;
|
||||
@ -486,16 +507,15 @@ int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fM
|
||||
bool bIsValueOverflow = false;
|
||||
bool bIsLastValueOverflow = false;
|
||||
|
||||
int iExposureTime = 0;
|
||||
float fExposureTime = 0;
|
||||
float fTempExposureTime = 0;
|
||||
double fLastExposureTime = 0.1;
|
||||
int iRepeatCount = 0;
|
||||
|
||||
//int iRes = m_pFSCtrl->SetExposureTime(1000);//need change to load from files
|
||||
int iRes = 0;
|
||||
int iRes = SetExposureTime(2000);//need change to load from files
|
||||
if (iRes != 0)
|
||||
{
|
||||
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1" << " Thread ID:" << m_iThreadID;
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -509,49 +529,42 @@ int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fM
|
||||
bFlagIsOverTrying = true;
|
||||
break;
|
||||
}
|
||||
//m_pFSCtrl->SetExposureTime(5000);
|
||||
GetExposureTime(iExposureTime);
|
||||
// qDebug() << "Current ExpTime:" << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||
//m_pFSCtrl->SetExposureTime(2500);
|
||||
//fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS;
|
||||
fTempExposureTime = iExposureTime;
|
||||
|
||||
fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS;
|
||||
fTempExposureTime = fExposureTime;
|
||||
|
||||
iRes = SingleShot(dfTemp);
|
||||
//iRes = m_pFSCtrl->SingleShot(dfTemp);
|
||||
if (iRes != 0)
|
||||
{
|
||||
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2" << " Thread ID:" << m_iThreadID;
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2";
|
||||
return 2;
|
||||
}
|
||||
|
||||
HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels);
|
||||
|
||||
double dSum = 0;
|
||||
int iCount = m_daDeviceAttr.iPixels / 200;
|
||||
int iCount = m_daDeviceAttr.iPixels / 100;
|
||||
for (int i = 0; i < iCount; i++)
|
||||
{
|
||||
dSum += dfTemp.lData[i];
|
||||
}
|
||||
double dTemp = dSum / iCount;
|
||||
|
||||
// qDebug() << "Avg " << dTemp << " Thread ID:" << m_iThreadID;
|
||||
|
||||
if (dTemp >= iDeviceDepth * 0.99)
|
||||
{
|
||||
bIsValueOverflow = true;
|
||||
if (!bIsLastValueOverflow)
|
||||
{
|
||||
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
iExposureTime = iExposureTime / 2;
|
||||
fExposureTime = fExposureTime / 2;
|
||||
}
|
||||
}
|
||||
|
||||
else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor)
|
||||
{
|
||||
// qDebug() << "trace bFlagIsAutoExposureOK =1 " << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||
bFlagIsAutoExposureOK = 1;
|
||||
}
|
||||
else if (dTemp > iDeviceDepth * fMaxScaleFactor)
|
||||
@ -559,11 +572,11 @@ int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fM
|
||||
bIsValueOverflow = true;
|
||||
if (!bIsLastValueOverflow)
|
||||
{
|
||||
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
iExposureTime = iExposureTime * 3 / 4;
|
||||
fExposureTime = fExposureTime * 3 / 4;
|
||||
}
|
||||
}
|
||||
else if (dTemp < iDeviceDepth * fMinScaleFactor)
|
||||
@ -571,15 +584,15 @@ int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fM
|
||||
bIsValueOverflow = false;
|
||||
if (bIsLastValueOverflow)
|
||||
{
|
||||
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
double dFactor;
|
||||
dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor);
|
||||
iExposureTime = (float)(iExposureTime / dFactor);
|
||||
fExposureTime = (float)(fExposureTime / dFactor);
|
||||
}
|
||||
if (/*fExposureTime > 100 || */iExposureTime < 10)
|
||||
if (/*fExposureTime > 100 || */fExposureTime < 10)
|
||||
{
|
||||
bFlagIsAutoExposureOK = false;
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
@ -589,41 +602,29 @@ int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fM
|
||||
bIsLastValueOverflow = bIsValueOverflow;
|
||||
fLastExposureTime = fTempExposureTime;
|
||||
|
||||
if (iExposureTime > 65000)
|
||||
if (fExposureTime > 13000)
|
||||
{
|
||||
bFlagIsAutoExposureOK = false;
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
float fPredictedExposureTime = 65000;
|
||||
iRes = SetExposureTime(65000);
|
||||
fPredictedExposureTime = 13000;
|
||||
iRes = SetExposureTime(13000);
|
||||
if (iRes != 0)
|
||||
{
|
||||
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3" << " Thread ID:" << m_iThreadID;
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3";
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
//qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to 30sec";
|
||||
// qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to " << m_daDeviceAttr.iMaxIntegrationTimeInMS << "MS" << " Thread ID:" << m_iThreadID;
|
||||
}
|
||||
bFlagIsOverMaxExposureTime = true;
|
||||
break;
|
||||
}
|
||||
|
||||
iRes = SetExposureTime((int)iExposureTime);
|
||||
iRes = SetExposureTime((int)fExposureTime);
|
||||
if (iRes != 0)
|
||||
{
|
||||
// qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4" << " Thread ID:" << m_iThreadID;
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4";
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Success:PerformAutoExposure. Value" << iExposureTime << " Thread ID:" << m_iThreadID;
|
||||
}
|
||||
}
|
||||
fPredictedExposureTime = iExposureTime;
|
||||
// qDebug() << "--------------------------Stop PerformAutoExposure" << " Thread ID:" << m_iThreadID;
|
||||
//emit SignalAcqFinished(m_iThreadID, 1);
|
||||
|
||||
fPredictedExposureTime = fExposureTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -717,9 +718,8 @@ int ZZ_ATPControl_Serial_Qt::SingleShot(DataFrame &dfData)
|
||||
qbSend.resize(3);
|
||||
// qbSend[1] = 0x00;
|
||||
// qbSend[2] = 0x01;
|
||||
int iTemp=m_iExposureTime;
|
||||
qbSend[1] = iTemp >> 8;;
|
||||
qbSend[2] = iTemp & 0xFF;
|
||||
qbSend[1] = m_iExposureTime >> 8;;
|
||||
qbSend[2] = m_iExposureTime & 0xFF;
|
||||
int iRes = SendCommand(qbSend);
|
||||
if (iRes != 0)
|
||||
{
|
||||
@ -762,11 +762,9 @@ int ZZ_ATPControl_Serial_Qt::SingleShot(DataFrame &dfData)
|
||||
// dfData.lData[i] = usData[i];
|
||||
// }
|
||||
}
|
||||
float fTemp;
|
||||
GetDeviceTemperature(fTemp);
|
||||
|
||||
dfData.usExposureTimeInMS = m_iExposureTime;
|
||||
dfData.fTemperature = fTemp;
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user