第一次提交
This commit is contained in:
101
ocean_lib/library.cpp
Normal file
101
ocean_lib/library.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include "library.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//void hello() {
|
||||
// std::cout << "Hello, World!" << std::endl;
|
||||
//}
|
||||
|
||||
|
||||
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];
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
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;
|
||||
// }
|
||||
//
|
||||
// // 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;
|
||||
}
|
||||
|
||||
const char* OceanOptics_lib::get_error_string(int error)
|
||||
{
|
||||
static char buffer[32];
|
||||
seabreeze_get_error_string(error, buffer, sizeof(buffer));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void OceanOptics_lib::read_serial_number_test(int index)
|
||||
{
|
||||
char serial_number[32];
|
||||
int flag;
|
||||
int error;
|
||||
|
||||
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));
|
||||
serial_number[31] = '\0';
|
||||
if(flag > 0) {
|
||||
printf("\tSerial number: [%s]\n", serial_number);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user