修改了函数执行失败后返回值
This commit is contained in:
@ -3,10 +3,14 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
//void hello() {
|
||||
// std::cout << "Hello, World!" << std::endl;
|
||||
//}
|
||||
OceanOptics_lib::OceanOptics_lib()
|
||||
{
|
||||
m_iSpectralmeterHandle=-100;
|
||||
}
|
||||
OceanOptics_lib::~OceanOptics_lib()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//ʹ<><CAB9>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>#include "api/SeaBreezeWrapper.h"
|
||||
int OceanOptics_lib::Initialize(bool bIsUSBMode,ZZ_U8 ucPortNumber,std::string strDeviceName)
|
||||
@ -21,7 +25,7 @@ int OceanOptics_lib::Initialize(bool bIsUSBMode,ZZ_U8 ucPortNumber,std::string s
|
||||
{
|
||||
printf("\nOpening spectrometer %d.\n", i);
|
||||
flag = seabreeze_open_spectrometer(i, &error);
|
||||
printf("...Result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
printf("Open spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
if(0 == flag)
|
||||
{
|
||||
device_count++;
|
||||
@ -34,18 +38,78 @@ int OceanOptics_lib::Initialize(bool bIsUSBMode,ZZ_U8 ucPortNumber,std::string s
|
||||
printf("\nfind!!!!!!!!!!!!\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\nClosing spectrometer %d.\n", i);
|
||||
flag = seabreeze_close_spectrometer(i, &error);
|
||||
printf("Close spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
}
|
||||
}
|
||||
|
||||
// for(i = 0; i < device_count; i++)
|
||||
// {
|
||||
// printf("\nGetting device %d name.\n", i);
|
||||
// seabreeze_get_model(i, &error, type, sizeof(type));
|
||||
// printf("...Result is (%s) [%s]\n", type, get_error_string(error));
|
||||
//
|
||||
// GetSerialNumber(i);
|
||||
// }
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
//<2F><><EFBFBD>ó<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
long minimum_time;
|
||||
|
||||
minimum_time = seabreeze_get_min_integration_time_microsec(m_iSpectralmeterHandle, &error);
|
||||
printf("...Minimum is %ld microseconds, result is [%s]\n", minimum_time, get_error_string(error));
|
||||
if(minimum_time < 0) {
|
||||
/* If there was an error, reset to a time that is supported widely. */
|
||||
minimum_time = 15000;
|
||||
return 1;
|
||||
}
|
||||
|
||||
SetExposureTime(minimum_time/1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//ʹ<><CAB9>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>#include "api/SeaBreezeWrapper.h"
|
||||
int OceanOptics_lib::Initialize()
|
||||
{
|
||||
int flag;
|
||||
int error;
|
||||
char type[16];
|
||||
int device_count = 0;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < SEABREEZE_MAX_DEVICES; i++)
|
||||
{
|
||||
printf("\nOpening spectrometer %d.\n", i);
|
||||
flag = seabreeze_open_spectrometer(i, &error);
|
||||
printf("Open spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
if(0 == flag)
|
||||
{
|
||||
m_iSpectralmeterHandle = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD>ó<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
long minimum_time;
|
||||
|
||||
minimum_time = seabreeze_get_min_integration_time_microsec(m_iSpectralmeterHandle, &error);
|
||||
printf("...Minimum is %ld microseconds, result is [%s]\n", minimum_time, get_error_string(error));
|
||||
if(minimum_time < 0) {
|
||||
/* If there was an error, reset to a time that is supported widely. */
|
||||
minimum_time = 15000;
|
||||
}
|
||||
|
||||
SetExposureTime(minimum_time/1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -134,12 +198,18 @@ void OceanOptics_lib::Close()
|
||||
int error;
|
||||
|
||||
flag = seabreeze_close_spectrometer(m_iSpectralmeterHandle, &error);
|
||||
printf("...Result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
printf("Close spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲɼ<DDB2>
|
||||
int OceanOptics_lib::SingleShot(DataFrame &dfData)
|
||||
{
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int error;
|
||||
int flag;
|
||||
int spec_length;
|
||||
@ -147,14 +217,15 @@ int OceanOptics_lib::SingleShot(DataFrame &dfData)
|
||||
|
||||
printf("\n\nGetting formatted spectrum length.\n");
|
||||
spec_length = seabreeze_get_formatted_spectrum_length(m_iSpectralmeterHandle, &error);
|
||||
printf("...Result is (%d) [%s]\n", spec_length, get_error_string(error));
|
||||
printf("Get formatted spectrum_length result is (%d) [%s]\n", spec_length, get_error_string(error));
|
||||
|
||||
if(spec_length > 0) {
|
||||
if(spec_length > 0)
|
||||
{
|
||||
spectrum = (double *)calloc((size_t)spec_length, sizeof(double));
|
||||
|
||||
printf("\nGetting a formatted spectrum.\n");
|
||||
flag = seabreeze_get_formatted_spectrum(m_iSpectralmeterHandle, &error, spectrum, spec_length);
|
||||
printf("...Result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
printf("Get formatted spectrum result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
printf("\tPixel value 20 is %1.2f\n", spectrum[20]);
|
||||
|
||||
for(int tmp = 0; tmp<spec_length; tmp++)
|
||||
@ -173,82 +244,113 @@ int OceanOptics_lib::SingleShot(DataFrame &dfData)
|
||||
free(spectrum);
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
int OceanOptics_lib::SetExposureTime(int iExposureTimeInMS)
|
||||
{
|
||||
int flag;
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int error;
|
||||
|
||||
seabreeze_set_integration_time_microsec(m_iSpectralmeterHandle, &error, iExposureTimeInMS);
|
||||
printf("...Result is [%s]\n", get_error_string(error));
|
||||
seabreeze_set_integration_time_microsec(m_iSpectralmeterHandle, &error, iExposureTimeInMS*1000);
|
||||
printf("Set integration time result is [%s]\n", get_error_string(error));
|
||||
|
||||
return 1;
|
||||
m_iExposureTime = iExposureTimeInMS;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><>ȡ<EFBFBD>ع<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int OceanOptics_lib::GetExposureTime(int &iExposureTimeInMS)
|
||||
{
|
||||
long minimum_time;
|
||||
int error;
|
||||
|
||||
minimum_time = seabreeze_get_min_integration_time_microsec(m_iSpectralmeterHandle, &error);
|
||||
printf("...Minimum is %ld microseconds, result is [%s]\n", minimum_time, get_error_string(error));
|
||||
if(minimum_time < 0) {
|
||||
/* If there was an error, reset to a time that is supported widely. */
|
||||
minimum_time = 15000;
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
iExposureTimeInMS = minimum_time;
|
||||
iExposureTimeInMS = m_iExposureTime;
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>¶<EFBFBD>
|
||||
int OceanOptics_lib::SetDeviceTemperature(float fTemperature)
|
||||
{
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int error;
|
||||
|
||||
printf("\nSetting TEC temperature to -5C\n");
|
||||
seabreeze_set_tec_temperature(m_iSpectralmeterHandle, &error, fTemperature);
|
||||
printf("...Result is [%s]\n", get_error_string(error));
|
||||
printf("Set tec temperature result is [%s]\n", get_error_string(error));
|
||||
|
||||
printf("\nSetting TEC enable to true\n");
|
||||
seabreeze_set_tec_enable(m_iSpectralmeterHandle, &error, 1);
|
||||
printf("...Result is [%s]\n", get_error_string(error));
|
||||
printf("Set tec enable result is [%s]\n", get_error_string(error));
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><>ȡ<EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>
|
||||
int OceanOptics_lib::GetDeviceTemperature(float &fTemperature)
|
||||
{
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
double temp;
|
||||
int error;
|
||||
|
||||
// usleep(1000000);
|
||||
printf("\nGetting TEC temperature\n");
|
||||
temp = seabreeze_read_tec_temperature(m_iSpectralmeterHandle, &error);
|
||||
printf("...Result is %1.2f C [%s]\n", temp, get_error_string(error));
|
||||
printf("Read tec temperature result is %1.2f C [%s]\n", temp, get_error_string(error));
|
||||
|
||||
fTemperature = temp;
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>Ϣ
|
||||
int OceanOptics_lib::GetDeviceInfo(DeviceInfo &Info)
|
||||
{
|
||||
string sn = GetSerialNumber(m_iSpectralmeterHandle);
|
||||
Info.strSN = sn;
|
||||
return 1;
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
string deviceType = GetDeviceType(m_iSpectralmeterHandle);
|
||||
string SN = GetSerialNumber(m_iSpectralmeterHandle);
|
||||
|
||||
Info.strPN = deviceType;
|
||||
Info.strSN = SN;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int OceanOptics_lib::GetDeviceAttribute(DeviceAttribute &Attr)
|
||||
{
|
||||
if(m_iSpectralmeterHandle==-100)
|
||||
{
|
||||
printf("\nNo!!!!!!!!!!!!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int error;
|
||||
int flag;
|
||||
int spec_length;
|
||||
@ -256,7 +358,7 @@ int OceanOptics_lib::GetDeviceAttribute(DeviceAttribute &Attr)
|
||||
|
||||
printf("\n\nGetting formatted spectrum length.\n");
|
||||
spec_length = seabreeze_get_formatted_spectrum_length(m_iSpectralmeterHandle, &error);
|
||||
printf("...Result is (%d) [%s]\n", spec_length, get_error_string(error));
|
||||
printf("Get formatted spectrum length result is (%d) [%s]\n", spec_length, get_error_string(error));
|
||||
|
||||
Attr.iPixels = spec_length;
|
||||
Attr.iMinIntegrationTimeInMS = 0;
|
||||
@ -267,7 +369,7 @@ int OceanOptics_lib::GetDeviceAttribute(DeviceAttribute &Attr)
|
||||
|
||||
printf("\nGetting wavelengths.\n");
|
||||
flag = seabreeze_get_wavelengths(m_iSpectralmeterHandle, &error, wls, spec_length);
|
||||
printf("...Result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
printf("Get wavelengths result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
printf("\tPixel 20 is wavelength %1.2f nm\n", wls[20]);
|
||||
|
||||
for(int tmp = 0; tmp<spec_length; tmp++)
|
||||
@ -278,9 +380,22 @@ int OceanOptics_lib::GetDeviceAttribute(DeviceAttribute &Attr)
|
||||
free(wls);
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool OceanOptics_lib::isSuccess(char* resultStr)
|
||||
{
|
||||
if(strstr(resultStr, "Success") == NULL)//<2F><>a<EFBFBD>в<EFBFBD><D0B2><EFBFBD>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>
|
||||
{
|
||||
cout << "not found\n";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return true;
|
||||
}
|
||||
else//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>
|
||||
{
|
||||
cout <<"found\n"; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const char* OceanOptics_lib::get_error_string(int error)
|
||||
{
|
||||
static char buffer[32];
|
||||
@ -288,6 +403,20 @@ const char* OceanOptics_lib::get_error_string(int error)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
string OceanOptics_lib::GetDeviceType(int index)
|
||||
{
|
||||
char type[16];
|
||||
int error;
|
||||
|
||||
seabreeze_get_model(index, &error, type, sizeof(type));
|
||||
printf("...Result is (%s) [%s]\n", type, get_error_string(error));
|
||||
type[15] = '\0';
|
||||
|
||||
string deviceType = type;
|
||||
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
string OceanOptics_lib::GetSerialNumber(int index)
|
||||
{
|
||||
static char serial_number[32];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>static<69><63><EFBFBD>˱<EFBFBD><CBB1><EFBFBD><EFBFBD>ᶨ<EFBFBD><E1B6A8><EFBFBD><EFBFBD>stack<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<D8BA><F3A3ACBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -296,7 +425,7 @@ string OceanOptics_lib::GetSerialNumber(int index)
|
||||
|
||||
printf("\n\nGetting serial number.\n");
|
||||
flag = seabreeze_get_serial_number(index, &error, serial_number, 32);
|
||||
printf("...Result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
printf("Get serial number result is (%d) [%s]\n", flag, get_error_string(error));
|
||||
serial_number[31] = '\0';
|
||||
if(flag > 0) {
|
||||
printf("\tSerial number: [%s]\n", serial_number);
|
||||
|
Reference in New Issue
Block a user