From 14711be782bf2d7b6ccda77fbff958706b5ba392 Mon Sep 17 00:00:00 2001 From: tangchao Date: Thu, 25 Nov 2021 18:50:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + ocean_lib/IrisFiberSpectrometerBase.h | 42 +++++++++++ ocean_lib/ZZ_Types.h | 44 +++++++++++ ocean_lib/library.cpp | 101 ++++++++++++++++++++++++++ ocean_lib/library.h | 58 +++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 .gitignore create mode 100644 ocean_lib/IrisFiberSpectrometerBase.h create mode 100644 ocean_lib/ZZ_Types.h create mode 100644 ocean_lib/library.cpp create mode 100644 ocean_lib/library.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f99abe --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/ocean_lib/build +/ocean_lib/.idea \ No newline at end of file diff --git a/ocean_lib/IrisFiberSpectrometerBase.h b/ocean_lib/IrisFiberSpectrometerBase.h new file mode 100644 index 0000000..c271a5f --- /dev/null +++ b/ocean_lib/IrisFiberSpectrometerBase.h @@ -0,0 +1,42 @@ +#include +#include "ZZ_Types.h" +#pragma once +using namespace ZZ_MISCDEF; +using namespace ZZ_MISCDEF::IRIS::FS; + +class CIrisFSBase +{ +public: + //CIrisFSBase(); + //virtual ~CIrisFSBase()= 0; +public: + //初始化设备 + //此处string为指明连接哪个ocean光谱仪的参数,可自行更换为其他c/c++标准类型 + //0为无错误,不同错误请返回不同值 + virtual int Initialize(bool bIsUSBMode,ZZ_U8 ucPortNumber,std::string strDeviceName) = 0; + +// //关闭设备 +// virtual void Close() = 0; +// +// //单次数据采集 +// virtual int SingleShot(DataFrame &dfData) = 0; +// +// //设置曝光时间 +// virtual int SetExposureTime(int iExposureTimeInMS) = 0; +// +// //获取曝光时间设置 +// virtual int GetExposureTime(int &iExposureTimeInMS) = 0; +// +// //设置目标温度 +// virtual int SetDeviceTemperature(float fTemperature) = 0; +// +// //获取温度设置 +// virtual int GetDeviceTemperature(float &fTemperature) = 0; +// +// //获取设备信息 +// virtual int GetDeviceInfo(DeviceInfo &Info) = 0; +// +// //获取设备特征数据 +// virtual int GetDeviceAttribute(DeviceAttribute &Attr) = 0; + +}; diff --git a/ocean_lib/ZZ_Types.h b/ocean_lib/ZZ_Types.h new file mode 100644 index 0000000..abb4a8b --- /dev/null +++ b/ocean_lib/ZZ_Types.h @@ -0,0 +1,44 @@ +////////////////////////////////////////////////////////////////////////// +//类型说明文件 +////////////////////////////////////////////////////////////////////////// +#pragma once + +#include + +namespace ZZ_MISCDEF +{ + typedef unsigned char ZZ_U8; + typedef unsigned short int ZZ_U16; + typedef unsigned long int ZZ_U32; + + + namespace IRIS + { + //Fiber Spectrometer + namespace FS + { + typedef struct tagDataFrame + { + ZZ_U16 usExposureTimeInMS; + ZZ_U16 usData[4096]; + float fTemperature; + double dTimes = 0; + }DataFrame; + + typedef struct tagDeviceInfo + { + std::string strPN; + std::string strSN; + }DeviceInfo; + + typedef struct tagDeviceAttribute + { + int iPixels; + int iMaxIntegrationTimeInMS; + int iMinIntegrationTimeInMS; + float fWaveLengthInNM[4096]; + }DeviceAttribute; + } + + } +} diff --git a/ocean_lib/library.cpp b/ocean_lib/library.cpp new file mode 100644 index 0000000..8b7624a --- /dev/null +++ b/ocean_lib/library.cpp @@ -0,0 +1,101 @@ +#include "library.h" + +#include + +//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 < 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); + } +} diff --git a/ocean_lib/library.h b/ocean_lib/library.h new file mode 100644 index 0000000..b9e6c2b --- /dev/null +++ b/ocean_lib/library.h @@ -0,0 +1,58 @@ +#ifndef OCEAN_LIB_LIBRARY_H +#define OCEAN_LIB_LIBRARY_H + +#include +#include +#include +#include +#include "api/SeaBreezeWrapper.h" + +#include "IrisFiberSpectrometerBase.h" +#include "api/seabreezeapi/SeaBreezeAPI.h" + + +//void hello(); + +class OceanOptics_lib:public CIrisFSBase +{ +public: + //鍒濆鍖栬澶 + //姝ゅstring涓烘寚鏄庤繛鎺ュ摢涓猳cean鍏夎氨浠殑鍙傛暟锛屽彲鑷鏇存崲涓哄叾浠朿/c++鏍囧噯绫诲瀷 + //0涓烘棤閿欒锛屼笉鍚岄敊璇杩斿洖涓嶅悓鍊 + int Initialize(bool bIsUSBMode,ZZ_U8 ucPortNumber,std::string strDeviceName); +// +// //鍏抽棴璁惧 +// void Close(); +// +// //鍗曟鏁版嵁閲囬泦 +// int SingleShot(DataFrame &dfData); +// +// //璁剧疆鏇濆厜鏃堕棿 +// int SetExposureTime(int iExposureTimeInMS); +// +// //鑾峰彇鏇濆厜鏃堕棿璁剧疆 +// int GetExposureTime(int &iExposureTimeInMS); +// +// //璁剧疆鐩爣娓╁害 +// int SetDeviceTemperature(float fTemperature); +// +// //鑾峰彇娓╁害璁剧疆 +// int GetDeviceTemperature(float &fTemperature); +// +// //鑾峰彇璁惧淇℃伅 +// int GetDeviceInfo(DeviceInfo &Info); +// +// //鑾峰彇璁惧鐗瑰緛鏁版嵁 +// int GetDeviceAttribute(DeviceAttribute &Attr); + + //tc + static const char* get_error_string(int error); + void read_serial_number_test(int index); +}; + + + + + + +#endif //OCEAN_LIB_LIBRARY_H