-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadSpec.cpp
71 lines (61 loc) · 1.83 KB
/
readSpec.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
/* Includes */
#include <iostream>
#include <cstdlib>
#include <string>
#include "api/seabreezeapi/SeaBreezeAPI.h"
#include <fstream>
#ifndef _WINDOWS
#include <unistd.h>
#else
#include <Windows.h>
#endif
using namespace std;
int readSpec() {
SeaBreezeAPI::shutdown();
SeaBreezeAPI* API = SeaBreezeAPI::getInstance();
unsigned long number_of_devices;
long *device_ids;
long device_id;
int *error_code=0;
char *nameBuffer;
int flag;
long *feature_id;
int status=0;
int pixel_num;
double *spectra=0;
API->probeDevices();
number_of_devices = API->getNumberOfDeviceIDs();
cout<<number_of_devices<<endl;
device_ids = (long *)calloc(number_of_devices, sizeof(long));
number_of_devices=API->getDeviceIDs(device_ids, number_of_devices);
device_id=device_ids[0];
nameBuffer=(char *)calloc(80, sizeof(char));
flag=API->getDeviceType(device_id, error_code, nameBuffer, 79);
if(flag > 0) {
cout<<"The device type is: "<<nameBuffer<<endl;
}
status=API->openDevice(device_id, error_code);
if (status) {
cout<<"Can't open this spectrometer!"<<endl;
}
API->getNumberOfSpectrometerFeatures(device_id, error_code);
feature_id=(long *)calloc(number_of_devices, sizeof(long));
API->getSpectrometerFeatures(device_id, error_code, feature_id, number_of_devices);
pixel_num=API->spectrometerGetFormattedSpectrumLength(device_id, feature_id[0], error_code);
cout<<pixel_num<<endl;
spectra=(double *)calloc(pixel_num, sizeof(double));
pixel_num=API->spectrometerGetFormattedSpectrum(device_id, feature_id[0], error_code, spectra, pixel_num);
while (1){
ofstream myfile;
myfile.open ("example.txt");
for (size_t i = 0; i < pixel_num; i++) {
myfile << spectra[i]<<"\n";
}
myfile.close();
cout<<"Success!"<<endl;
}
API->closeDevice(device_id, error_code);
return 0;
}
//