-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathexperiment.py
77 lines (66 loc) · 2.18 KB
/
experiment.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
# -*- coding: utf-8 -*-
from lantz.drivers.examples import LantzSignalGeneratorTCP
from lantz.drivers.examples import LantzVoltmeterTCP
import lantz.log
lantz.log.log_to_screen(lantz.log.DEBUG)
lantz.log.log_to_socket(lantz.log.DEBUG)
from lantz import Q_
volt = Q_(1, 'V')
milivolt = Q_(1, 'mV')
Hz = Q_(1, 'Hz')
def simple_test():
with LantzSignalGeneratorTCP(host='localhost', port=5678) as actuator:
print('The identification of the actuator is : ' + actuator.idn)
actuator.amplitude = 3 * volt
actuator.offset = 200 * milivolt
actuator.frequency = 20 * Hz
actuator.output_enabled = True
actuator.waveform = 'sine'
actuator.refresh()
actuator.dout[1] = True
print(actuator.dout[1])
print(actuator.din[2])
actuator.calibrate()
actuator.self_test(1, 3)
with LantzVoltmeterTCP(host='localhost', port=5679) as sensor:
print('The identification of the sensor is : ' + sensor.idn)
sensor.range[0] = 10
sensor.self_test()
sensor.refresh()
print(sensor.voltage[0])
print(sensor.voltage[1])
sensor.calibrate()
sensor.auto_range(0)
print(sensor.range[0])
print(sensor.voltage[0])
def test_experiment():
import time
actuator = LantzSignalGeneratorTCP(host='localhost', port=5678)
sensor = LantzVoltmeterTCP(host='localhost', port=5679)
actuator.initialize()
sensor.initialize()
actuator.amplitude = 3 * volt
actuator.offset = 500 * milivolt
actuator.frequency = 1 * Hz
actuator.output_enabled = True
actuator.waveform = 'sine'
sensor.range[0] = 10
sensor.range[1] = 10
data = []
start_time = time.time()
try:
lantz.log.log_to_screen(lantz.log.ERROR)
while time.time() - start_time < 10:
datapoint = (time.time()-start_time,
sensor.voltage[0],
sensor.voltage[1])
data.append(datapoint)
print(data)
except KeyboardInterrupt:
print('Ending ')
finally:
actuator.finalize()
sensor.finalize()
if __name__ == '__main__':
simple_test()
test_experiment()