-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_dual_logger.py
executable file
·47 lines (39 loc) · 1.16 KB
/
example_dual_logger.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
#!/bin/python3
import time
import sys
# Import Keithley DMM library
import KeithleyDMM
# Instrument connection settings
gpib_port = 0
k196_addr = 7
k199_addr = 1
try:
# Instantiate instruments
k196 = KeithleyDMM.keithley196(k196_addr)
k199 = KeithleyDMM.keithley199(k199_addr)
# Open new .csv log file with start time in its name
f = open(time.strftime('Log_%Y-%m-%d_%H-%M-%S.csv'), 'a')
# Loop untill stoprd by ctrl-c
while(1):
# Get Current Time
timestamp = time.localtime()
# Read instruments
v1 = k196.read()
v2 = k199.read()
# Get measurement units
u1 = k196.units
u2 = k199.units
# Make date and time strings
d = time.strftime('%Y-%m-%d', timestamp)
t = time.strftime('%H:%M:%S', timestamp)
# Assemble output string
out_str = (d + '; ' + t + '; ' + str(v1) + '; ' + u1 + '; ' + str(v2) + '; ' + u2)
# Write output string to file
f.write(out_str + '\n')
print(out_str)
# Wait for a bit before repeating
time.sleep(1)
except KeyboardInterrupt:
# Close file and exit
f.close()
sys.exit(0)