2021-11-25 18:50:24 +08:00
# include "library.h"
# include <iostream>
2021-11-26 18:25:26 +08:00
# include <cstring>
2021-11-25 18:50:24 +08:00
2021-12-03 17:33:42 +08:00
OceanOptics_lib : : OceanOptics_lib ( )
{
m_iSpectralmeterHandle = - 100 ;
}
2021-12-06 09:26:32 +08:00
2021-12-03 17:33:42 +08:00
OceanOptics_lib : : ~ OceanOptics_lib ( )
{
2021-11-25 18:50:24 +08:00
2021-12-03 17:33:42 +08:00
}
2021-11-25 18:50:24 +08:00
2021-11-26 18:25:26 +08:00
//ʹ <> <CAB9> ͷ<EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD> #include "api/SeaBreezeWrapper.h"
2021-11-25 18:50:24 +08:00
int OceanOptics_lib : : Initialize ( bool bIsUSBMode , ZZ_U8 ucPortNumber , std : : string strDeviceName )
{
int flag ;
2021-11-26 18:25:26 +08:00
int error ;
char type [ 16 ] ;
int device_count = 0 ;
int i ;
2021-11-25 18:50:24 +08:00
2021-11-26 18:25:26 +08:00
for ( i = 0 ; i < SEABREEZE_MAX_DEVICES ; i + + )
{
2021-12-06 09:26:32 +08:00
// printf("\nOpening spectrometer %d.\n", i);
2021-11-26 18:25:26 +08:00
flag = seabreeze_open_spectrometer ( i , & error ) ;
2021-12-06 09:26:32 +08:00
// printf("Open spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
2021-11-26 18:25:26 +08:00
if ( 0 = = flag )
{
device_count + + ;
}
2021-12-06 09:26:32 +08:00
else
{
continue ;
}
2021-11-26 18:25:26 +08:00
string sn = GetSerialNumber ( i ) ;
2021-11-25 18:50:24 +08:00
2021-11-26 18:25:26 +08:00
if ( strcmp ( sn . c_str ( ) , strDeviceName . c_str ( ) ) = = 0 )
{
m_iSpectralmeterHandle = i ;
2021-12-06 09:26:32 +08:00
// printf("\nfind!!!!!!!!!!!!\n");
2021-11-26 18:25:26 +08:00
break ;
}
2021-12-03 17:33:42 +08:00
else
{
2021-12-06 09:26:32 +08:00
// printf("\nClosing spectrometer %d.\n", i);
2021-12-03 17:33:42 +08:00
flag = seabreeze_close_spectrometer ( i , & error ) ;
2021-12-06 09:26:32 +08:00
// printf("Close spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
2021-12-03 17:33:42 +08:00
}
2021-11-25 18:50:24 +08:00
}
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
2021-12-06 09:26:32 +08:00
// printf("\nNo!!!!!!!!!!!!\n");
2021-12-03 17:33:42 +08:00
return 1 ;
}
2021-12-06 09:26:32 +08:00
seabreeze_set_trigger_mode ( m_iSpectralmeterHandle , & error , 0 ) ;
2021-12-06 17:55:51 +08:00
long test = seabreeze_get_buffer_capacity_minimum ( m_iSpectralmeterHandle , & error ) ;
seabreeze_set_buffer_capacity ( m_iSpectralmeterHandle , & error , test ) ;
// printf("seabreeze_set_trigger_mode: Result is [%s]\n", get_error_string(error));
2021-12-06 09:26:32 +08:00
2021-12-03 17:33:42 +08:00
2021-11-25 18:50:24 +08:00
2021-12-03 17:33:42 +08:00
//<2F> <> <EFBFBD> ó<EFBFBD> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> ʱ<EFBFBD> <CAB1>
long minimum_time ;
minimum_time = seabreeze_get_min_integration_time_microsec ( m_iSpectralmeterHandle , & error ) ;
2021-12-06 09:26:32 +08:00
//printf("...Minimum is %ld microseconds, result is [%s]\n", minimum_time, get_error_string(error));
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
// printf("\n-------------------û<> ɹ<EFBFBD> <C9B9> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> \n");
return 1 ;
}
2021-12-03 17:33:42 +08:00
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 + + )
{
2022-03-21 16:43:39 +08:00
// printf("\nOpening spectrometer %d.\n", i);
2021-12-03 17:33:42 +08:00
flag = seabreeze_open_spectrometer ( i , & error ) ;
2021-12-06 09:26:32 +08:00
//printf("Open spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
2021-12-03 17:33:42 +08:00
if ( 0 = = flag )
{
m_iSpectralmeterHandle = i ;
break ;
}
2021-12-06 09:26:32 +08:00
else
{
continue ;
}
2021-12-03 17:33:42 +08:00
}
if ( m_iSpectralmeterHandle = = - 100 )
{
2022-03-21 16:43:39 +08:00
printf ( " \n No Device found!!!!!!!!!!!! \n " ) ;
2021-12-03 17:33:42 +08:00
return 1 ;
}
2021-12-06 09:26:32 +08:00
seabreeze_set_trigger_mode ( m_iSpectralmeterHandle , & error , 0 ) ;
seabreeze_set_trigger_mode ( m_iSpectralmeterHandle , & error , 0 ) ;
seabreeze_set_trigger_mode ( m_iSpectralmeterHandle , & error , 0 ) ;
2021-12-06 17:55:51 +08:00
long test = seabreeze_get_buffer_capacity_minimum ( m_iSpectralmeterHandle , & error ) ;
2022-03-21 16:43:39 +08:00
// printf("seabreeze_get_buffer_capacity_minimum: Result is [%s]\n", get_error_string(error));
2021-12-06 17:55:51 +08:00
seabreeze_set_buffer_capacity ( m_iSpectralmeterHandle , & error , test ) ;
2022-03-21 16:43:39 +08:00
// printf("seabreeze_set_buffer_capacity: Result is [%s]\n", get_error_string(error));
2021-12-06 17:55:51 +08:00
// printf("seabreeze_set_trigger_mode: Result is [%s]\n", get_error_string(error));
2021-12-06 09:26:32 +08:00
2021-12-03 17:33:42 +08:00
//<2F> <> <EFBFBD> ó<EFBFBD> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> ʱ<EFBFBD> <CAB1>
long minimum_time ;
minimum_time = seabreeze_get_min_integration_time_microsec ( m_iSpectralmeterHandle , & error ) ;
2021-12-06 09:26:32 +08:00
//printf("...Minimum is %ld microseconds, result is [%s]\n", minimum_time, get_error_string(error));
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
// printf("\n-------------------û<> ɹ<EFBFBD> <C9B9> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> \n");
return 1 ;
}
2021-12-03 17:33:42 +08:00
if ( minimum_time < 0 ) {
/* If there was an error, reset to a time that is supported widely. */
minimum_time = 15000 ;
2021-12-06 09:26:32 +08:00
return 1 ;
2021-12-03 17:33:42 +08:00
}
SetExposureTime ( minimum_time / 1000 ) ;
return 0 ;
2021-11-26 18:25:26 +08:00
}
2021-11-25 18:50:24 +08:00
2021-11-26 18:25:26 +08:00
//ʹ <> <CAB9> ͷ<EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD> #include "api/seabreezeapi/SeaBreezeAPI.h"
//int OceanOptics_lib::Initialize(bool bIsUSBMode,ZZ_U8 ucPortNumber,std::string strDeviceName)
//{
// int number_of_devices;
// long *device_ids;
// int i;
// int flag;
// int error = 0;
// char nameBuffer[80];
// char *serialNumber;
2021-11-25 18:50:24 +08:00
//
//
2021-11-26 18:25:26 +08:00
//// /* Give the driver a chance to initialize itself */
//// sbapi_initialize();
//
// printf("Probing for devices...\n"); fflush(stdout);
// sbapi_probe_devices();
//
// printf("Getting device count...\n"); fflush(stdout);
// number_of_devices = sbapi_get_number_of_device_ids();
// std::cout<<"Device count is "<< number_of_devices <<std::endl;
// 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"); fflush(stdout);
//
2021-11-25 18:50:24 +08:00
//
2021-11-26 18:25:26 +08:00
// 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);
2021-11-25 18:50:24 +08:00
// }
//
2021-11-26 18:25:26 +08:00
// serialNumber = GetSerialNumber(device_ids[i]);
// serialNumber = GetSerialNumber(device_ids[i]);
//
// printf("\tSerial number tc: [%s]\n", serialNumber);
//
//// /* 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;
//// }
////
//// // log deviations
//// unsupportedFeatureCount=0;
//// testFailureCount=0;
////
//// /* Test the device */
//// for(test_index = 0; test_index < __test_function_count; test_index++) {
//// /* Invoke each of the test functions against this device */
//// __test_functions[test_index](device_ids[i], &unsupportedFeatureCount, &testFailureCount);
//// }
////
//// /* 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));
//// printf("%d: Device 0x%02lX: \n\tNumber of unsupported features = %d\n\tNumber of test failures = %d\n", i, device_ids[i], unsupportedFeatureCount, testFailureCount);
// }
//
// flag = sbapi_get_device_type(device_ids[i], &error, nameBuffer, 79);
//
// return 1;
//}
//<2F> ر<EFBFBD> <D8B1> 豸
void OceanOptics_lib : : Close ( )
{
int flag ;
int error ;
flag = seabreeze_close_spectrometer ( m_iSpectralmeterHandle , & error ) ;
2021-12-06 09:26:32 +08:00
// printf("Close spectrometer result is (%d) [%s]\n", flag, get_error_string(error));
2021-11-26 18:25:26 +08:00
}
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ݲɼ<DDB2>
int OceanOptics_lib : : SingleShot ( DataFrame & dfData )
{
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
printf ( " \n No!!!!!!!!!!!! \n " ) ;
return 1 ;
}
2021-11-26 18:25:26 +08:00
int error ;
int flag ;
int spec_length ;
double * spectrum = 0 ;
2021-12-06 09:26:32 +08:00
bool ret ;
2021-11-26 18:25:26 +08:00
2021-12-06 09:26:32 +08:00
// printf("\n\nGetting formatted spectrum length.\n");
2021-11-26 18:25:26 +08:00
spec_length = seabreeze_get_formatted_spectrum_length ( m_iSpectralmeterHandle , & error ) ;
2021-12-06 09:26:32 +08:00
//printf("Get formatted spectrum_length result is (%d) [%s]\n", spec_length, get_error_string(error));
ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-11-26 18:25:26 +08:00
2021-12-03 17:33:42 +08:00
if ( spec_length > 0 )
{
2021-11-26 18:25:26 +08:00
spectrum = ( double * ) calloc ( ( size_t ) spec_length , sizeof ( double ) ) ;
2021-12-06 17:55:51 +08:00
seabreeze_clear_buffer ( m_iSpectralmeterHandle , & error ) ;
auto startTime = std : : chrono : : high_resolution_clock : : now ( ) ;
2021-11-26 18:25:26 +08:00
flag = seabreeze_get_formatted_spectrum ( m_iSpectralmeterHandle , & error , spectrum , spec_length ) ;
2021-12-06 17:55:51 +08:00
auto endTime = std : : chrono : : high_resolution_clock : : now ( ) ;
std : : chrono : : duration < double , std : : milli > fp_ms = endTime - startTime ;
std : : cout < < " <EFBFBD> ɼ<EFBFBD> <EFBFBD> <EFBFBD> ʱΪ<EFBFBD> <EFBFBD> " < < fp_ms . count ( ) / 1000 < < " s. " < < std : : endl ;
2021-12-06 09:26:32 +08:00
// printf("Get formatted spectrum result is (%d) [%s]\n", flag, get_error_string(error));
// printf("\tPixel value 20 is %1.2f\n", spectrum[20]);
ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-11-26 18:25:26 +08:00
for ( int tmp = 0 ; tmp < spec_length ; tmp + + )
{
dfData . usData [ tmp ] = spectrum [ tmp ] ;
}
int exposureTimeInMS ;
GetExposureTime ( exposureTimeInMS ) ;
dfData . usExposureTimeInMS = exposureTimeInMS ;
float temperature ;
GetDeviceTemperature ( temperature ) ;
dfData . fTemperature = temperature ;
free ( spectrum ) ;
2021-11-25 18:50:24 +08:00
}
2021-12-03 17:33:42 +08:00
return 0 ;
2021-11-26 18:25:26 +08:00
}
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ع<EFBFBD> ʱ<EFBFBD> <CAB1>
int OceanOptics_lib : : SetExposureTime ( int iExposureTimeInMS )
{
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
2021-12-06 09:26:32 +08:00
// printf("\nNo!!!!!!!!!!!!\n");
2021-12-03 17:33:42 +08:00
return 1 ;
}
2021-11-26 18:25:26 +08:00
int error ;
2021-12-06 17:55:51 +08:00
seabreeze_set_trigger_mode ( m_iSpectralmeterHandle , & error , 0 ) ; // trigger to normal
2021-12-03 17:33:42 +08:00
seabreeze_set_integration_time_microsec ( m_iSpectralmeterHandle , & error , iExposureTimeInMS * 1000 ) ;
2022-03-21 16:43:39 +08:00
// printf("Set integration time result is [%s]\n", get_error_string(error));
2021-12-06 17:55:51 +08:00
2021-12-06 09:26:32 +08:00
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-12-03 17:33:42 +08:00
m_iExposureTime = iExposureTimeInMS ;
2021-11-26 18:25:26 +08:00
2021-12-06 09:26:32 +08:00
// //----------------------------------------------------------------------------------------------------------------
// int error;
// long *spectrometer_ids;
// int number_of_spectrometers;
//
// number_of_spectrometers = sbapi_get_number_of_spectrometer_features(m_iSpectralmeterHandle, &error);
// printf("\t\t\tResult is %d [%s]\n", number_of_spectrometers, sbapi_get_error_string(error));
// spectrometer_ids = (long *)calloc(number_of_spectrometers, sizeof(long));
// number_of_spectrometers = sbapi_get_spectrometer_features(m_iSpectralmeterHandle, &error, spectrometer_ids, number_of_spectrometers);
// printf("\t\t\tResult is %d [%s]\n", number_of_spectrometers, sbapi_get_error_string(error));
//
// sbapi_spectrometer_set_integration_time_micros(m_iSpectralmeterHandle, spectrometer_ids[0], &error, iExposureTimeInMS*1000);
// printf("\t\t\t\tResult is [%s]\n", sbapi_get_error_string(error));
2021-12-03 17:33:42 +08:00
return 0 ;
2021-11-26 18:25:26 +08:00
}
//<2F> <> ȡ<EFBFBD> ع<EFBFBD> ʱ<EFBFBD> <CAB1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int OceanOptics_lib : : GetExposureTime ( int & iExposureTimeInMS )
{
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
printf ( " \n No!!!!!!!!!!!! \n " ) ;
return 1 ;
2021-11-26 18:25:26 +08:00
}
2021-12-03 17:33:42 +08:00
iExposureTimeInMS = m_iExposureTime ;
2021-11-26 18:25:26 +08:00
2021-12-03 17:33:42 +08:00
return 0 ;
2021-11-26 18:25:26 +08:00
}
//<2F> <> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> <C4BF> <EFBFBD> ¶<EFBFBD>
int OceanOptics_lib : : SetDeviceTemperature ( float fTemperature )
{
2021-12-06 09:26:32 +08:00
bool ret ;
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
printf ( " \n No!!!!!!!!!!!! \n " ) ;
return 1 ;
}
2021-11-26 18:25:26 +08:00
int error ;
2021-12-06 09:26:32 +08:00
// printf("\nSetting TEC temperature to -5C\n");
2021-11-26 18:25:26 +08:00
seabreeze_set_tec_temperature ( m_iSpectralmeterHandle , & error , fTemperature ) ;
2021-12-06 09:26:32 +08:00
// printf("Set tec temperature result is [%s]\n", get_error_string(error));
ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-11-26 18:25:26 +08:00
2021-12-06 09:26:32 +08:00
// printf("\nSetting TEC enable to true\n");
2021-11-26 18:25:26 +08:00
seabreeze_set_tec_enable ( m_iSpectralmeterHandle , & error , 1 ) ;
2021-12-06 09:26:32 +08:00
// printf("Set tec enable result is [%s]\n", get_error_string(error));
ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-11-26 18:25:26 +08:00
2021-12-03 17:33:42 +08:00
return 0 ;
2021-11-26 18:25:26 +08:00
}
//<2F> <> ȡ<EFBFBD> ¶<EFBFBD> <C2B6> <EFBFBD> <EFBFBD> <EFBFBD>
int OceanOptics_lib : : GetDeviceTemperature ( float & fTemperature )
{
2021-12-06 17:55:51 +08:00
dark_pixel_count = seabreeze_get_electric_dark_pixel_indices ( index ,
error_code , dark_pixels , MAX_DARK_PIXELS ) ;
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
printf ( " \n No!!!!!!!!!!!! \n " ) ;
return 1 ;
}
2021-11-26 18:25:26 +08:00
double temp ;
int error ;
// usleep(1000000);
2021-12-06 09:26:32 +08:00
// printf("\nGetting TEC temperature\n");
2021-11-26 18:25:26 +08:00
temp = seabreeze_read_tec_temperature ( m_iSpectralmeterHandle , & error ) ;
2021-12-06 09:26:32 +08:00
// printf("Read tec temperature result is %1.2f C [%s]\n", temp, get_error_string(error));
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-11-26 18:25:26 +08:00
fTemperature = temp ;
2021-12-03 17:33:42 +08:00
return 0 ;
2021-11-26 18:25:26 +08:00
}
//<2F> <> ȡ<EFBFBD> 豸<EFBFBD> <E8B1B8> Ϣ
int OceanOptics_lib : : GetDeviceInfo ( DeviceInfo & Info )
{
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
printf ( " \n No!!!!!!!!!!!! \n " ) ;
return 1 ;
}
string deviceType = GetDeviceType ( m_iSpectralmeterHandle ) ;
string SN = GetSerialNumber ( m_iSpectralmeterHandle ) ;
Info . strPN = deviceType ;
Info . strSN = SN ;
return 0 ;
2021-11-26 18:25:26 +08:00
}
//<2F> <> ȡ<EFBFBD> 豸<EFBFBD> <E8B1B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int OceanOptics_lib : : GetDeviceAttribute ( DeviceAttribute & Attr )
{
2021-12-03 17:33:42 +08:00
if ( m_iSpectralmeterHandle = = - 100 )
{
printf ( " \n No!!!!!!!!!!!! \n " ) ;
return 1 ;
}
2021-11-26 18:25:26 +08:00
int error ;
int flag ;
int spec_length ;
double * wls = 0 ;
2021-12-06 09:26:32 +08:00
// printf("\n\nGetting formatted spectrum length.\n");
2021-11-26 18:25:26 +08:00
spec_length = seabreeze_get_formatted_spectrum_length ( m_iSpectralmeterHandle , & error ) ;
2021-12-06 09:26:32 +08:00
// printf("Get formatted spectrum length result is (%d) [%s]\n", spec_length, get_error_string(error));
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-11-26 18:25:26 +08:00
Attr . iPixels = spec_length ;
2021-12-06 09:26:32 +08:00
long minimum_time ;
minimum_time = seabreeze_get_min_integration_time_microsec ( m_iSpectralmeterHandle , & error ) ;
2022-03-21 14:13:29 +08:00
Attr . iMinIntegrationTimeInMS = minimum_time / 1000 ;
2021-11-26 18:25:26 +08:00
Attr . iMaxIntegrationTimeInMS = 60000 ;
if ( spec_length > 0 ) {
wls = ( double * ) calloc ( ( size_t ) spec_length , sizeof ( double ) ) ;
2021-12-06 09:26:32 +08:00
// printf("\nGetting wavelengths.\n");
2021-11-26 18:25:26 +08:00
flag = seabreeze_get_wavelengths ( m_iSpectralmeterHandle , & error , wls , spec_length ) ;
2021-12-06 09:26:32 +08:00
// printf("Get wavelengths result is (%d) [%s]\n", flag, get_error_string(error));
// printf("\tPixel 20 is wavelength %1.2f nm\n", wls[20]);
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return 1 ;
}
2021-11-26 18:25:26 +08:00
for ( int tmp = 0 ; tmp < spec_length ; tmp + + )
{
Attr . fWaveLengthInNM [ tmp ] = wls [ tmp ] ;
}
free ( wls ) ;
}
2021-11-25 18:50:24 +08:00
2021-12-03 17:33:42 +08:00
return 0 ;
2021-11-25 18:50:24 +08:00
}
2021-12-03 17:33:42 +08:00
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>
{
2021-12-06 09:26:32 +08:00
//cout << "not found\n";//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
return false ;
2021-12-03 17:33:42 +08:00
}
else //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ڡ<EFBFBD>
{
2021-12-06 09:26:32 +08:00
//cout <<"found\n"; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
return true ;
2021-12-03 17:33:42 +08:00
}
}
2021-12-06 09:26:32 +08:00
2021-11-25 18:50:24 +08:00
const char * OceanOptics_lib : : get_error_string ( int error )
{
static char buffer [ 32 ] ;
seabreeze_get_error_string ( error , buffer , sizeof ( buffer ) ) ;
return buffer ;
}
2023-03-19 20:37:07 +08:00
void OceanOptics_lib : : test_nonlinearity_coeffs_feature ( )
{
int error = 0 ;
int number_of_nonlinearity_coeff_features ;
long * nonlinearity_coeff_feature_ids = 0 ;
double buffer [ 10 ] ;
int i ;
int length ;
printf ( " \n \t Testing nonlinearity coefficient features: \n " ) ;
printf ( " \t \t Getting number of nonlinearity coefficient features: \n " ) ;
number_of_nonlinearity_coeff_features =
sbapi_get_number_of_nonlinearity_coeffs_features ( m_iSpectralmeterHandle , & error ) ;
printf ( " \t \t \t Result is %d [%s] \n " , number_of_nonlinearity_coeff_features ,
sbapi_get_error_string ( error ) ) ;
if ( 0 = = number_of_nonlinearity_coeff_features ) {
printf ( " \t No nonlinearity coefficient capabilities found. \n " ) ;
// tallyUnsupportedFeatures(unsupportedFeatureCount);
return ;
}
nonlinearity_coeff_feature_ids =
( long * ) calloc ( number_of_nonlinearity_coeff_features , sizeof ( long ) ) ;
printf ( " \t \t Getting nonlinearity coefficient feature IDs... \n " ) ;
number_of_nonlinearity_coeff_features = sbapi_get_nonlinearity_coeffs_features (
m_iSpectralmeterHandle , & error , nonlinearity_coeff_feature_ids ,
number_of_nonlinearity_coeff_features ) ;
printf ( " \t \t \t Result 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 , m_iSpectralmeterHandle , nonlinearity_coeff_feature_ids [ i ] ) ;
printf ( " \t \t \t Attempting to get nonlinearity coefficients... \n " ) ;
memset ( buffer , ( int ) 0 , sizeof ( buffer ) ) ;
length = sbapi_nonlinearity_coeffs_get ( m_iSpectralmeterHandle ,
nonlinearity_coeff_feature_ids [ i ] , & error , buffer , 10 ) ;
printf ( " \t \t \t \t Result is %d [%s] \n " , length , sbapi_get_error_string ( error ) ) ;
if ( 0 = = error & & length > 0 ) {
printf ( " \t \t \t \t First calibration term: %1.2e \n " , buffer [ 0 ] ) ;
}
printf ( " \t \t %d: Finished testing device 0x%02lX, nonlinearity coeffs 0x%02lX \n " ,
i , m_iSpectralmeterHandle , nonlinearity_coeff_feature_ids [ i ] ) ;
}
free ( nonlinearity_coeff_feature_ids ) ;
printf ( " \t Finished testing nonlinearity coefficient capabilities. \n " ) ;
}
2021-12-03 17:33:42 +08:00
string OceanOptics_lib : : GetDeviceType ( int index )
{
char type [ 16 ] ;
int error ;
seabreeze_get_model ( index , & error , type , sizeof ( type ) ) ;
2021-12-06 09:26:32 +08:00
// printf("...Result is (%s) [%s]\n", type, get_error_string(error));
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return " " ;
}
2021-12-03 17:33:42 +08:00
type [ 15 ] = ' \0 ' ;
string deviceType = type ;
return deviceType ;
}
2021-11-26 18:25:26 +08:00
string OceanOptics_lib : : GetSerialNumber ( int index )
2021-11-25 18:50:24 +08:00
{
2021-11-26 18:25:26 +08:00
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>
2021-11-25 18:50:24 +08:00
int flag ;
int error ;
2021-12-06 09:26:32 +08:00
// printf("\n\nGetting serial number.\n");
2021-11-25 18:50:24 +08:00
flag = seabreeze_get_serial_number ( index , & error , serial_number , 32 ) ;
2021-12-06 09:26:32 +08:00
// printf("Get serial number result is (%d) [%s]\n", flag, get_error_string(error));
bool ret = isSuccess ( ( char * ) get_error_string ( error ) ) ;
if ( ! ret )
{
return " " ;
}
2021-11-25 18:50:24 +08:00
serial_number [ 31 ] = ' \0 ' ;
if ( flag > 0 ) {
2022-03-21 16:43:39 +08:00
// printf("\tSerial number: [%s]\n", serial_number);
2021-11-25 18:50:24 +08:00
}
2021-11-26 18:25:26 +08:00
string sn = serial_number ;
return sn ;
2021-11-25 18:50:24 +08:00
}