forked from LiamsGitHub/AS7265x-spectrometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
88 lines (61 loc) · 1.87 KB
/
test.py
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
# Script to test spectrometer.py
import spectrometer as spect
import time
import datetime
"""
#spectrometer members:
def init()
def boardPresent()
def hwVersion()
def swVersion()
def temperatures()
def setBlueLED(state)
def shutterLED(device,state)
def setLEDDriveCurrent(current)
def setIntegrationTime(time)
def setGain(gain)
def readRAW()
def readCAL()
"""
fname = '/home/pi/python/' # Directory for results data
def newFile(fname):
# Open a unique file for the results data
t = datetime.datetime.now()
year = str(t.year)
month = str(t.month)
day = str(t.day)
hour = str(t.hour)
min = str(t.minute)
fname = fname + 'spectrumdata' + year + month.zfill(2) + day.zfill(2) + "time" + hour.zfill(2) + 'h' + min.zfill(2) + '.txt'
fh = open (fname,'w')
return fh
# Test read of all calibrated and raw values
def ReadAllData():
duration = 3600 * 20 # Desired time in secs for total run. 3600 secs per hour. 60 secs per minute.
sleepPeriod = 60 * 10 # Sleep seconds between passes (interval between measurements)
procTime = 6 # Board compute time per cycle (1 pass of RAW and CAL data fetch)
passes = int(duration / (sleepPeriod + procTime))
print ("Test duration(s): " +str(duration) + " Sleep period: " + str(sleepPeriod) + " Number of Passes: " +str(passes) )
print ("Start time: " + str(datetime.datetime.now()))
fhandle = newFile(fname)
count = 0
while (count < passes):
print (count)
RAWvalues = spect.readRAW()
CALvalues = spect.readCAL()
string = ""
for val in RAWvalues:
string = string + str(val) + ','
for val in CALvalues:
string = string + str(val) + ','
string = string + "\n"
fhandle.write(string)
print (string)
time.sleep(sleepPeriod)
count = count +1
print ("End time: " + str(datetime.datetime.now()))
fhandle.close()
# ---- main() -----
#spect.init()
#spect.hwVersion()
ReadAllData()