forked from LabPy/lantz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanfrequency.py
69 lines (50 loc) · 1.81 KB
/
scanfrequency.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
# -*- coding: utf-8 -*-
"""
scanfrequency
~~~~~~~~~~~~~
This example shows how to program a CLI using a lantz drivers, but
without the backend-frontend classes that simplifies app development.
:copyright: 2014 by Lantz Authors, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import time
def scan_frequency(inst, start, stop, step, wait):
"""Scan frequency in an instrument.
:param start: Start frequency.
:type start: Quantity
:param stop: Stop frequency.
:type stop: Quantity
:param step: Step frequency.
:type step: Quantity
:param wait: Waiting time.
:type wait: Quantity
"""
in_secs = wait.to('seconds').magnitude
current = start
while current < stop:
inst.frequency = current
time.sleep(in_secs)
current += step
if __name__ == '__main__':
import argparse
from lantz import Q_
from lantz.drivers.examples import LantzSignalGeneratorTCP
parser = argparse.ArgumentParser()
parser.add_argument('start', type=float,
help='Start frequency [Hz]')
parser.add_argument('stop', type=float,
help='Stop frequency [Hz]')
parser.add_argument('step', type=float,
help='Step frequency [Hz]')
parser.add_argument('wait', type=float,
help='Waiting time at each step [s]')
args = parser.parse_args()
Hz = Q_(1, 'Hz')
sec = Q_(1, 'sec')
def print_change(new, old):
print('Changed from {} to {}'.format(old, new))
with LantzSignalGeneratorTCP('localhost', 5678) as inst:
print(inst.idn)
inst.frequency_changed.connect(print_change)
scan_frequency(inst, args.start * Hz, args.stop * Hz,
args.step * Hz, args.wait * sec)