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:
@ -47,6 +47,9 @@ void logout(QString str);
|
||||
void createDirectory(QString fullPath);
|
||||
bool isFileExist(QString fullFileName);
|
||||
|
||||
int getNonlinearityCoeffs2(long deviceID, double * coeffs);
|
||||
int getNonlinearityCoeffs1(double * coeffs);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
@ -88,16 +91,17 @@ int main(int argc, char *argv[])
|
||||
switch (query.deviceType)
|
||||
{
|
||||
case OPTOSKY:
|
||||
m_FiberSpectrometer = new ATPFiberImager(false,query.serialPort.toStdString(),"ocean_optics");
|
||||
m_FiberSpectrometer = new ATPFiberImager(false,query.serialPort.toStdString(),"OPTOSKY");
|
||||
break;
|
||||
case OceanOptics:
|
||||
m_FiberSpectrometer = new OceanOpticsFiberImager();
|
||||
m_FiberSpectrometer = new OceanOpticsFiberImager();//
|
||||
break;
|
||||
case UnknownDevice:
|
||||
parser.showHelp();
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
|
||||
//<2F><><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD>
|
||||
QString message;
|
||||
QString SN;
|
||||
@ -106,66 +110,115 @@ int main(int argc, char *argv[])
|
||||
logout("<br><b style=\"color:red\">Connectting the fiber spectrometer!</b>");
|
||||
m_FiberSpectrometer->connectFiberSpectrometer(SN, pixelCount, wavelengthInfo);
|
||||
|
||||
//<2F>Զ<EFBFBD><D4B6>ع<EFBFBD>
|
||||
logout("<br><b style=\"color:red\">AutoExpose!</b>");
|
||||
m_FiberSpectrometer->autoExpose();
|
||||
|
||||
int iExposureTime;
|
||||
m_FiberSpectrometer->getExposureTime(iExposureTime);
|
||||
|
||||
message="<br><b style=\"color:red\">ExposureTime: " + QString::number(iExposureTime) + "</b>";
|
||||
logout(message);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>sleep<65><70><EFBFBD>ȴ<EFBFBD><C8B4>رտ<D8B1><D5BF><EFBFBD>
|
||||
message="<br><b style=\"color:red\">Please close the lamp in " + QString::number(query.sleepTimeinSecond) + "s!</b>";
|
||||
logout(message);
|
||||
QThread::sleep(query.sleepTimeinSecond);
|
||||
|
||||
//<2F>ɼ<EFBFBD><C9BC><EFBFBD>֡
|
||||
logout("<br><b style=\"color:red\">Record dark frame!</b>");
|
||||
m_FiberSpectrometer->recordDark(query.calFileOutputDirectory);
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>sleep<EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
message="<br><b style=\"color:red\">Please open the lamp in " + QString::number(query.sleepTimeinSecond) + "s!</b>";
|
||||
logout(message);
|
||||
QThread::sleep(query.sleepTimeinSecond);
|
||||
|
||||
//<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
logout("<br><b style=\"color:red\">Record integrating sphere frame!</b>");
|
||||
m_FiberSpectrometer->recordTarget(query.averageTimes, query.calFileOutputDirectory);
|
||||
|
||||
//<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
logout("<br><b style=\"color:red\">readAndResample_StandardLightFile!</b>");
|
||||
// //<2F>Զ<EFBFBD><EFBFBD>ع<EFBFBD>
|
||||
// logout("<br><b style=\"color:red\">AutoExpose!</b>");
|
||||
// m_FiberSpectrometer->autoExpose();
|
||||
//
|
||||
// int iExposureTime;
|
||||
// m_FiberSpectrometer->getExposureTime(iExposureTime);
|
||||
//
|
||||
// message="<br><b style=\"color:red\">ExposureTime: " + QString::number(iExposureTime) + "</b>";
|
||||
// logout(message);
|
||||
//
|
||||
// //<2F><><EFBFBD><EFBFBD>sleep<65><70><EFBFBD>ȴ<EFBFBD><C8B4>رտ<D8B1><D5BF><EFBFBD>
|
||||
// message="<br><b style=\"color:red\">Please close the lamp in " + QString::number(query.sleepTimeinSecond) + "s!</b>";
|
||||
// logout(message);
|
||||
// QThread::sleep(query.sleepTimeinSecond);
|
||||
//
|
||||
// //<2F>ɼ<EFBFBD><C9BC><EFBFBD>֡
|
||||
// logout("<br><b style=\"color:red\">Record dark frame!</b>");
|
||||
// m_FiberSpectrometer->recordDark(query.calFileOutputDirectory);
|
||||
//
|
||||
//
|
||||
// //<2F><><EFBFBD><EFBFBD>sleep<65><70><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><F2BFAABF><EFBFBD>
|
||||
// message="<br><b style=\"color:red\">Please open the lamp in " + QString::number(query.sleepTimeinSecond) + "s!</b>";
|
||||
// logout(message);
|
||||
// QThread::sleep(query.sleepTimeinSecond);
|
||||
//
|
||||
// //<2F>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// logout("<br><b style=\"color:red\">Record integrating sphere frame!</b>");
|
||||
// m_FiberSpectrometer->recordTarget(query.averageTimes, query.calFileOutputDirectory);
|
||||
//
|
||||
// //<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
// logout("<br><b style=\"color:red\">readAndResample_StandardLightFile!</b>");
|
||||
DeviceAttribute deviceAttribute;
|
||||
DeviceInfo deviceInfo;
|
||||
m_FiberSpectrometer->getDeviceAttribute(deviceAttribute);
|
||||
m_FiberSpectrometer->getDeviceInfo(deviceInfo);
|
||||
//
|
||||
// CalibrationAlgorithm * m_CalibrationAlgorithm = new CalibrationAlgorithm();
|
||||
// m_CalibrationAlgorithm->readAndResample_StandardLightFile(query.standardLightFilePath,query.integratingSphereDetectorValue, deviceAttribute, deviceInfo);
|
||||
//
|
||||
// //<2F><><EFBFBD>ɷ<EFBFBD><C9B7>䶨<EFBFBD><E4B6A8><EFBFBD>ļ<EFBFBD>
|
||||
// if (query.calFileOutputName.isEmpty())//query->calFileOutputName==""
|
||||
// {
|
||||
// QDateTime curDateTime = QDateTime::currentDateTime();
|
||||
// QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
|
||||
// QString calFileName = QDir::cleanPath(query.calFileOutputDirectory + QDir::separator() + currentTime + "_" + QString::fromStdString(deviceInfo.strSN) + ".dat");
|
||||
//
|
||||
// query.calFileOutputName=calFileName;
|
||||
// }
|
||||
// logout("<br><b style=\"color:red\">Produce calibration file!</b>");
|
||||
// m_CalibrationAlgorithm->produceCalfile(query.calFileOutputName, deviceAttribute, m_FiberSpectrometer->m_IntegratingSphereData, m_FiberSpectrometer->m_DarkData);
|
||||
//
|
||||
// //<2F><><EFBFBD>Ʒ<EFBFBD><C6B7>䶨<EFBFBD><E4B6A8><EFBFBD>ļ<EFBFBD>
|
||||
// QDateTime curDateTime = QDateTime::currentDateTime();
|
||||
// QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
|
||||
// QString destName = QDir::cleanPath(query.calFileOutputDirectory + QDir::separator() + currentTime + "_" + QString::fromStdString(deviceInfo.strSN) + "_" +QString::number(query.position) + ".cal");
|
||||
// copyFileToPath(query.calFileOutputName,destName,true);
|
||||
|
||||
CalibrationAlgorithm * m_CalibrationAlgorithm = new CalibrationAlgorithm();
|
||||
m_CalibrationAlgorithm->readAndResample_StandardLightFile(query.standardLightFilePath,query.integratingSphereDetectorValue, deviceAttribute, deviceInfo);
|
||||
|
||||
//<2F><><EFBFBD>ɷ<EFBFBD><C9B7>䶨<EFBFBD><E4B6A8><EFBFBD>ļ<EFBFBD>
|
||||
if (query.calFileOutputName.isEmpty())//query->calFileOutputName==""
|
||||
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD>isOcean<61><6E>
|
||||
auto * p_C = dynamic_cast<OceanOpticsFiberImager *>(m_FiberSpectrometer);
|
||||
bool isOcean = false;//
|
||||
if (p_C != nullptr)
|
||||
{
|
||||
QDateTime curDateTime = QDateTime::currentDateTime();
|
||||
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
|
||||
QString calFileName = QDir::cleanPath(query.calFileOutputDirectory + QDir::separator() + currentTime + "_" + QString::fromStdString(deviceInfo.strSN) + ".dat");
|
||||
// cout << "Match!!" << endl;
|
||||
isOcean=true;
|
||||
|
||||
query.calFileOutputName=calFileName;
|
||||
// coeffsFrame tmp;
|
||||
// m_FiberSpectrometer->getNonlinearityCoeffs(tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "not OceanOpticsFiberImager!!" << endl;
|
||||
}
|
||||
logout("<br><b style=\"color:red\">Produce calibration file!</b>");
|
||||
m_CalibrationAlgorithm->produceCalfile(query.calFileOutputName, deviceAttribute, m_FiberSpectrometer->m_IntegratingSphereData, m_FiberSpectrometer->m_DarkData);
|
||||
|
||||
//<2F><><EFBFBD>Ʒ<EFBFBD><C6B7>䶨<EFBFBD><E4B6A8><EFBFBD>ļ<EFBFBD>
|
||||
QDateTime curDateTime = QDateTime::currentDateTime();
|
||||
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
|
||||
QString destName = QDir::cleanPath(query.calFileOutputDirectory + QDir::separator() + currentTime + "_" + QString::fromStdString(deviceInfo.strSN) + "_" +QString::number(query.position) + ".cal");
|
||||
copyFileToPath(query.calFileOutputName,destName,true);
|
||||
|
||||
//<2F>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_FiberSpectrometer->disconnectFiberSpectrometer();
|
||||
//return a.exec();
|
||||
|
||||
//ʹ<><CAB9>sbapi<70><69>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (isOcean)
|
||||
{
|
||||
double * coeffs = new double[100];
|
||||
int numberOfCoeffs = getNonlinearityCoeffs1(coeffs);
|
||||
|
||||
QDateTime curDateTime = QDateTime::currentDateTime();
|
||||
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
|
||||
QString nonlinearityCoeffsName = QDir::cleanPath(query.calFileOutputDirectory + QDir::separator() + currentTime + "_" + QString::fromStdString(deviceInfo.strSN) + ".nonLinear");
|
||||
|
||||
// for (int i = 0; i < numberOfCoeffs; ++i)
|
||||
// {
|
||||
// printf("\n");
|
||||
//
|
||||
// printf("nonlinearityCoeffs(<28><>%d<><64>): %1.2e\n",i , coeffs[i]);
|
||||
//
|
||||
// printf("\n");
|
||||
// }
|
||||
|
||||
std::ofstream outfile(nonlinearityCoeffsName.toStdString().c_str());
|
||||
|
||||
for (int i = 0; i < numberOfCoeffs; i++)
|
||||
{
|
||||
outfile << coeffs[i] << std::endl;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
free(coeffs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CommandLineParseResult parseCommandLine2(QCommandLineParser &parser, TcQuery *query, QString *errorMessage)
|
||||
@ -485,3 +538,149 @@ bool isFileExist(QString fullFileName)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int getNonlinearityCoeffs1(double * coeffs)
|
||||
{
|
||||
int number_of_devices;
|
||||
long *device_ids;
|
||||
int i;
|
||||
int test_index;
|
||||
int flag;
|
||||
int error = 0;
|
||||
char nameBuffer[80];
|
||||
|
||||
|
||||
/* Give the driver a chance to initialize itself */
|
||||
sbapi_initialize();
|
||||
|
||||
// printf("Probing for devices...\n"); fflush(stdout);
|
||||
sbapi_probe_devices();
|
||||
|
||||
//#define RS232_TEST
|
||||
#ifdef RS232_TEST
|
||||
printf("Adding an STS at 9600 baud...\n");
|
||||
/* Uncomment for Linux */
|
||||
//sbapi_add_RS232_device_location("STS", "/dev/ttyS0", 9600);
|
||||
//sbapi_add_RS232_device_location("STS", "/dev/ttyUSB0", 9600);
|
||||
|
||||
/* Uncomment for Windows */
|
||||
//sbapi_add_RS232_device_location("STS", "COM1", 9600);
|
||||
|
||||
/* Uncomment for e.g. USB-RS232 adapter under OSX */
|
||||
//sbapi_add_RS232_device_location("STS", "/dev/tty.KeySerial1", 9600);
|
||||
//sbapi_add_RS232_device_location("STS", "/dev/tty.usbserial", 9600);
|
||||
#endif
|
||||
|
||||
/* This shows how to add network devices (note that most use TCP/IP) */
|
||||
//sbapi_add_TCPIPv4_device_location("Jaz", "192.168.1.150", 7654);
|
||||
//sbapi_add_TCPIPv4_device_location("Blaze", "192.168.1.151", 57357);
|
||||
|
||||
// printf("Getting device count...\n"); fflush(stdout);
|
||||
number_of_devices = sbapi_get_number_of_device_ids();
|
||||
|
||||
// printf("Device count is %d\n", number_of_devices);
|
||||
if(0 == number_of_devices) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// printf("Getting device IDs...\n");
|
||||
device_ids = (long *)calloc(number_of_devices, sizeof(long));
|
||||
number_of_devices = sbapi_get_device_ids(device_ids, number_of_devices);
|
||||
// printf("Got %d device ID%s.\n", number_of_devices, number_of_devices == 1 ? "" : "s");
|
||||
|
||||
int number;
|
||||
for(i = 0; i < number_of_devices; i++) {
|
||||
// printf("%d: Device 0x%02lX:\n", i, device_ids[i]);
|
||||
// printf("\tGetting device type...\n");
|
||||
flag = sbapi_get_device_type(device_ids[i], &error, nameBuffer, 79);
|
||||
// printf("\t\tResult is (%d) [%s]\n", flag, sbapi_get_error_string(error));
|
||||
if(flag > 0) {
|
||||
// printf("\tDevice type: [%s]\n", nameBuffer);
|
||||
}
|
||||
|
||||
/* Open the device */
|
||||
// printf("\tAttempting to open:\n");
|
||||
flag = sbapi_open_device(device_ids[i], &error);
|
||||
// printf("\t\tResult is (%d) [%s]\n", flag, sbapi_get_error_string(error));
|
||||
|
||||
// jump to the next iteration if there was a problem
|
||||
if(flag != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
number = getNonlinearityCoeffs2(device_ids[i],coeffs);
|
||||
|
||||
/* Close the device */
|
||||
// printf("\tAttempting to close:\n");
|
||||
sbapi_close_device(device_ids[i], &error);
|
||||
// printf("\t\tResult is (%d) [%s]\n", flag, sbapi_get_error_string(error));
|
||||
}
|
||||
free(device_ids);
|
||||
|
||||
// printf("Finished testing.\n");
|
||||
|
||||
/* Clean up memory allocated by the driver */
|
||||
sbapi_shutdown();
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ϵ<EFBFBD><CFB5><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>
|
||||
int getNonlinearityCoeffs2(long deviceID, double * coeffs)
|
||||
{
|
||||
int error = 0;
|
||||
int number_of_nonlinearity_coeff_features;
|
||||
long *nonlinearity_coeff_feature_ids = 0;
|
||||
double buffer[10];
|
||||
int i;
|
||||
int length = 0;
|
||||
|
||||
// printf("\n\tTesting nonlinearity coefficient features:\n");
|
||||
|
||||
// printf("\t\tGetting number of nonlinearity coefficient features:\n");
|
||||
number_of_nonlinearity_coeff_features =
|
||||
sbapi_get_number_of_nonlinearity_coeffs_features(deviceID, &error);
|
||||
// printf("\t\t\tResult is %d [%s]\n", number_of_nonlinearity_coeff_features,
|
||||
// sbapi_get_error_string(error));
|
||||
|
||||
if(0 == number_of_nonlinearity_coeff_features) {
|
||||
printf("\tNo nonlinearity coefficient capabilities found.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
nonlinearity_coeff_feature_ids =
|
||||
(long *)calloc(number_of_nonlinearity_coeff_features, sizeof(long));
|
||||
// printf("\t\tGetting nonlinearity coefficient feature IDs...\n");
|
||||
number_of_nonlinearity_coeff_features = sbapi_get_nonlinearity_coeffs_features(
|
||||
deviceID, &error, nonlinearity_coeff_feature_ids,
|
||||
number_of_nonlinearity_coeff_features);
|
||||
// printf("\t\t\tResult is %d [%s]\n", number_of_nonlinearity_coeff_features,
|
||||
// sbapi_get_error_string(error));
|
||||
|
||||
for(i = 0; i < number_of_nonlinearity_coeff_features; i++)
|
||||
{
|
||||
// printf("\t\t%d: Testing device 0x%02lX, nonlinearity coeffs 0x%02lX\n",
|
||||
// i, deviceID, nonlinearity_coeff_feature_ids[i]);
|
||||
|
||||
// printf("\t\t\tAttempting to get nonlinearity coefficients...\n");
|
||||
memset(coeffs, (int)0, 20);//----------------------------------------------------------------------------
|
||||
length = sbapi_nonlinearity_coeffs_get(deviceID,
|
||||
nonlinearity_coeff_feature_ids[i], &error, coeffs, 20);
|
||||
// printf("\t\t\t\tResult is %d [%s]\n", length, sbapi_get_error_string(error));
|
||||
|
||||
if(0 == error && length > 0) {
|
||||
// printf("\t\t\t\tFirst calibration term: %1.2e\n", coeffs[0]);
|
||||
}
|
||||
|
||||
// printf("\t\t%d: Finished testing device 0x%02lX, nonlinearity coeffs 0x%02lX\n",
|
||||
// i, deviceID, nonlinearity_coeff_feature_ids[i]);
|
||||
}
|
||||
free(nonlinearity_coeff_feature_ids);
|
||||
|
||||
|
||||
|
||||
// printf("\tFinished testing nonlinearity coefficient capabilities.\n");
|
||||
|
||||
return length;
|
||||
}
|
Reference in New Issue
Block a user