Commit 86ff3fbf6193d4d26770c9914dd85b05f6d1d896
1 parent
9534feb524
Exists in
master
replace 4 spaces by tabs
Showing 1 changed file with 90 additions and 90 deletions Side-by-side Diff
FPC1000_viewer.py
... | ... | @@ -14,111 +14,111 @@ |
14 | 14 | #============================================================================== |
15 | 15 | |
16 | 16 | def parse(): |
17 | - """ | |
18 | - Specific parsing procedure for Allan Deviation plotting tool. | |
19 | - :returns: populated namespace (parser) | |
20 | - """ | |
21 | - parser = argparse.ArgumentParser(description = 'R&S FPC1000 spectrum viewer', | |
22 | - epilog = 'Example: \'./FPC1000_viewer.py -ip \'192.168.0.2\' -p 1234\' plot current spectrum from given device') | |
17 | + """ | |
18 | + Specific parsing procedure for Allan Deviation plotting tool. | |
19 | + :returns: populated namespace (parser) | |
20 | + """ | |
21 | + parser = argparse.ArgumentParser(description = 'R&S FPC1000 spectrum viewer', | |
22 | + epilog = 'Example: \'./FPC1000_viewer.py -ip \'192.168.0.2\' -p 1234\' plot current spectrum from given device') | |
23 | 23 | |
24 | - parser.add_argument('-ip', | |
25 | - action='store', | |
26 | - dest='ip', | |
27 | - default=IP, | |
28 | - help='device IP (default '+IP+')') | |
24 | + parser.add_argument('-ip', | |
25 | + action='store', | |
26 | + dest='ip', | |
27 | + default=IP, | |
28 | + help='device IP (default '+IP+')') | |
29 | 29 | |
30 | - parser.add_argument('-p', | |
31 | - action='store', | |
32 | - dest='port', | |
33 | - default=PORT, | |
34 | - help='device port (default '+str(PORT)+')') | |
30 | + parser.add_argument('-p', | |
31 | + action='store', | |
32 | + dest='port', | |
33 | + default=PORT, | |
34 | + help='device port (default '+str(PORT)+')') | |
35 | 35 | |
36 | - args = parser.parse_args() | |
37 | - return args | |
36 | + args = parser.parse_args() | |
37 | + return args | |
38 | 38 | |
39 | 39 | #============================================================================== |
40 | 40 | |
41 | 41 | def send(sock, command): |
42 | - sock.send("%s\n"%command) | |
42 | + sock.send("%s\n"%command) | |
43 | 43 | |
44 | 44 | #============================================================================== |
45 | 45 | |
46 | 46 | def read(sock): |
47 | - ans = '' | |
48 | - nb_data_list = [] | |
49 | - nb_data = '' | |
50 | - try: | |
51 | - while ans != '\n': | |
52 | - ans = sock.recv(1) | |
53 | - nb_data_list.append(ans) # Return the number of data | |
54 | - list_size = len(nb_data_list) | |
55 | - for j in range (0, list_size): | |
56 | - nb_data = nb_data+nb_data_list[j] | |
57 | - return nb_data | |
58 | - except socket.timeout: | |
59 | - print "Socket timeout error when reading." | |
47 | + ans = '' | |
48 | + nb_data_list = [] | |
49 | + nb_data = '' | |
50 | + try: | |
51 | + while ans != '\n': | |
52 | + ans = sock.recv(1) | |
53 | + nb_data_list.append(ans) # Return the number of data | |
54 | + list_size = len(nb_data_list) | |
55 | + for j in range (0, list_size): | |
56 | + nb_data = nb_data+nb_data_list[j] | |
57 | + return nb_data | |
58 | + except socket.timeout: | |
59 | + print "Socket timeout error when reading." | |
60 | 60 | |
61 | 61 | #============================================================================== |
62 | 62 | |
63 | 63 | def get_spectrum(sock): |
64 | - send(sock, 'FREQ:STAR?') | |
65 | - x1 = read(sock) | |
66 | - x1 = float(x1.replace('\n','')) | |
67 | - send(sock, 'FREQ:STOP?') | |
68 | - x2 = read(sock) | |
69 | - x2 = float(x2.replace('\n','')) | |
70 | - send(sock, 'TRAC?') | |
71 | - y = read(sock) | |
72 | - y = numpy.array(y.replace('\n','').split(','), dtype='float') | |
73 | - x = numpy.linspace(x1, x2, len(y)) | |
74 | - return (x, y) | |
64 | + send(sock, 'FREQ:STAR?') | |
65 | + x1 = read(sock) | |
66 | + x1 = float(x1.replace('\n','')) | |
67 | + send(sock, 'FREQ:STOP?') | |
68 | + x2 = read(sock) | |
69 | + x2 = float(x2.replace('\n','')) | |
70 | + send(sock, 'TRAC?') | |
71 | + y = read(sock) | |
72 | + y = numpy.array(y.replace('\n','').split(','), dtype='float') | |
73 | + x = numpy.linspace(x1, x2, len(y)) | |
74 | + return (x, y) | |
75 | 75 | |
76 | 76 | #============================================================================== |
77 | 77 | |
78 | 78 | def main(): |
79 | - """ | |
80 | - Main script | |
81 | - """ | |
82 | - # Parse command line | |
83 | - args = parse() | |
84 | - # ip | |
85 | - ip = str(args.ip) | |
86 | - # port | |
87 | - port = int(args.port) | |
79 | + """ | |
80 | + Main script | |
81 | + """ | |
82 | + # Parse command line | |
83 | + args = parse() | |
84 | + # ip | |
85 | + ip = str(args.ip) | |
86 | + # port | |
87 | + port = int(args.port) | |
88 | 88 | |
89 | - try: | |
90 | - sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_TCP) | |
91 | - sock.settimeout(10.0) | |
92 | - sock.connect((ip, port)) | |
89 | + try: | |
90 | + sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_TCP) | |
91 | + sock.settimeout(10.0) | |
92 | + sock.connect((ip, port)) | |
93 | 93 | |
94 | - app = QtGui.QApplication([]) | |
94 | + app = QtGui.QApplication([]) | |
95 | 95 | |
96 | - win = pyqtgraph.GraphicsWindow(title='Basic FPC1000 viewer (%s:%i)'%(ip, port)) | |
96 | + win = pyqtgraph.GraphicsWindow(title='Basic FPC1000 viewer (%s:%i)'%(ip, port)) | |
97 | 97 | |
98 | - pyqtgraph.setConfigOptions(antialias=True) | |
98 | + pyqtgraph.setConfigOptions(antialias=True) | |
99 | 99 | |
100 | - global curve, ptr, p1 | |
101 | - p1 = win.addPlot(title="Spectrum") | |
102 | - curve = p1.plot(pen='y') | |
103 | - ptr = 0 | |
104 | - def update(): | |
105 | - global curve, ptr, p1 | |
106 | - (x_data, y_data) = get_spectrum(sock) | |
107 | - curve.setData(x = x_data, y = y_data) | |
108 | - if ptr == 0: | |
109 | - p1.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted | |
110 | - ptr += 1 | |
111 | - timer = QtCore.QTimer() | |
112 | - timer.timeout.connect(update) | |
113 | - timer.start(500) | |
100 | + global curve, ptr, p1 | |
101 | + p1 = win.addPlot(title="Spectrum") | |
102 | + curve = p1.plot(pen='y') | |
103 | + ptr = 0 | |
104 | + def update(): | |
105 | + global curve, ptr, p1 | |
106 | + (x_data, y_data) = get_spectrum(sock) | |
107 | + curve.setData(x = x_data, y = y_data) | |
108 | + if ptr == 0: | |
109 | + p1.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted | |
110 | + ptr += 1 | |
111 | + timer = QtCore.QTimer() | |
112 | + timer.timeout.connect(update) | |
113 | + timer.start(500) | |
114 | 114 | |
115 | - if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): | |
116 | - QtGui.QApplication.instance().exec_() | |
115 | + if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): | |
116 | + QtGui.QApplication.instance().exec_() | |
117 | 117 | |
118 | - except: | |
119 | - pass | |
118 | + except: | |
119 | + pass | |
120 | 120 | |
121 | - ## Start Qt event loop unless running in interactive mode or using pyside. | |
121 | + ## Start Qt event loop unless running in interactive mode or using pyside. | |
122 | 122 | if __name__ == '__main__': |
123 | - main() | |
123 | + main() |