-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitorPhotodiodesOnKeyPress.c
More file actions
166 lines (133 loc) · 4.4 KB
/
monitorPhotodiodesOnKeyPress.c
File metadata and controls
166 lines (133 loc) · 4.4 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
*
* This program will be used to quickly record the amount of
* contamination present in the probe detector from the
* pump laser.
*
*
*/
#include "interfacing/interfacing.h"
#include "mathTools.h"
#define NUMCHANNELS 4
void collectAndRecordData(char* fileName);
void writeFileHeader(char* fileName, char* comments);
int main (int argc, char **argv)
{
time_t rawtime;
struct tm * timeinfo;
char fileName[BUFSIZE],comments[BUFSIZE];
char dataCollectionFileName[] = "/home/pi/.takingData";
FILE *dataCollectionFlagFile, *fp;
if (argc==2) {
strcpy(comments,argv[1]);
} else {
printf("Usage:\n$ sudo ./monitorPhotodiodes <comments>\n");
return 0;
}
dataCollectionFlagFile=fopen(dataCollectionFileName,"w");
if (!dataCollectionFlagFile) {
printf("Unable to open file: %s\n",dataCollectionFileName);
exit(1);
}
initializeBoard();
initializeUSB1208();
// get file name. Use format "MonitorPhotodiodes"+$DATE+$TIME+".dat"
time(&rawtime);
timeinfo=localtime(&rawtime);
struct stat st = {0};
strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo);
if (stat(fileName, &st) == -1){ // Create the directory for the Day's data
mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO );
}
strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/MonitorPhotodiodes%F_%H%M%S.dat",timeinfo);
printf("\n%s\n",fileName);
writeFileHeader(fileName, comments);
fp=fopen(fileName,"a");
if (!fp) {
printf("unable to open file: %s\n",fileName);
exit(1);
}
homeMotor(PROBE_MOTOR);
collectAndRecordData(fileName);
closeUSB1208();
fclose(dataCollectionFlagFile);
remove(dataCollectionFileName);
return 0;
}
void writeFileHeader(char* fileName, char* comments){
FILE* fp;
float returnFloat;
fp=fopen(fileName,"w");
if (!fp) {
printf("unable to open file: %s\n",fileName);
exit(1);
}
fprintf(fp,"#Filename:\t%s\n",fileName);
fprintf(fp,"#Comments:\t%s\n",comments);
/** Record System Stats to File **/
/** Pressure Gauges **/
getIonGauge(&returnFloat);
printf("IonGauge %2.2E Torr \n",returnFloat);
fprintf(fp,"#IonGauge(Torr):\t%2.2E\n",returnFloat);
getConvectron(GP_TOP2,&returnFloat);
printf("CVGauge(Source Foreline): %2.2E Torr\n", returnFloat);
fprintf(fp,"#CVGauge(Source Foreline)(Torr):\t%2.2E\n", returnFloat);
getConvectron(GP_TOP1,&returnFloat);
printf("CVGauge(Target Foreline): %2.2E Torr\n", returnFloat);
fprintf(fp,"#CVGauge(Target Foreline)(Torr):\t%2.2E\n", returnFloat);
/** Temperature Controllers **/
getPVCN7500(CN_RESERVE,&returnFloat);
fprintf(fp,"#T_res:\t%f\n",returnFloat);
getSVCN7500(CN_RESERVE,&returnFloat);
fprintf(fp,"#T_res_set:\t%f\n",returnFloat);
getPVCN7500(CN_TARGET,&returnFloat);
fprintf(fp,"#T_trg:\t%f\n",returnFloat);
getSVCN7500(CN_TARGET,&returnFloat);
fprintf(fp,"#T_trg_set:\t%f\n",returnFloat);
/** End System Stats Recording **/
//fprintf(fp,"TEMP\tFREQ\tPUMP\tStdDev\tPROBE\tStdDev\tREF\tStdDev\n");
fprintf(fp,"K617\tStdDev\tPUMP\tStdDev\tPROBE\tStdDev\tREF\tStdDev\n");
fclose(fp);
}
void collectAndRecordData(char* fileName){
FILE* fp;
char c = 'r';
int k=0,i;
int timeCounter=0;
int nSamples = 16; // The number of data points to collect
int delayTime=1000; // Time in ms
float involts[NUMCHANNELS];
fp=fopen(fileName,"a");
if (!fp) {
printf("unable to open file: %s\n",fileName);
exit(1);
}
// Allocate some memory to store measurements for calculating
// error bars.
float* measurement = malloc(nSamples*sizeof(float));
while(c !='q'){
for(k=0;k<NUMCHANNELS;k++){
involts[k]=0.0;
}
if(timeCounter%15==0) printf(" Keithly | PUMP | PROBE | REFERENCE\n"); // Channels 0-3
// grab several readings and average
for(k=0;k<NUMCHANNELS;k++){
for (i=0;i<nSamples;i++){
getUSB1208AnalogIn(k,&measurement[i]);
involts[k]=involts[k]+measurement[i];
delay(delayTime/NUMCHANNELS/nSamples);
}
involts[k]=fabs(involts[k])/(float)nSamples;
fprintf(fp,"%0.4f\t%0.4f\t",involts[k],stdDeviation(measurement,nSamples));
printf(" %0.4f %0.4f ",involts[k],stdDeviation(measurement,nSamples));
if(k<NUMCHANNELS) printf(" | ");
}
fprintf(fp,"\n");
printf("\n Press Return for next datapoint or enter 'q' to quit\n");
c=getchar();
timeCounter++;
}
fprintf(fp,"\n");
fclose(fp);
free(measurement);
}