From e67e1a26e4d3891a3e93b1e931a917223261a4ca Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Tue, 3 Nov 2015 21:04:00 +0100 Subject: [PATCH 1/1] Graph plot added into Python test software. Signed-off-by: Pavel Pisa --- host/app/dadpyscan/dadpyscan.py | 74 +++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/host/app/dadpyscan/dadpyscan.py b/host/app/dadpyscan/dadpyscan.py index f1170cc..c01a2f1 100755 --- a/host/app/dadpyscan/dadpyscan.py +++ b/host/app/dadpyscan/dadpyscan.py @@ -6,6 +6,11 @@ import time import numpy import argparse import random +import time +import matplotlib +matplotlib.use('GTKAgg') +#matplotlib.interactive(True) +from matplotlib import pyplot as plt class rdevice(object): def __init__(self, rcon = None): @@ -69,6 +74,22 @@ class rdevice(object): if (sl == last_line): return res + def get_multiline_vector(self, command = None, first_line = 'begin', + last_line = 'end', try_cycles = 10): + self.wait_stamp() + self.rcon.write(command); + s = self.get_multiline(last_line = last_line) + if s is None: + print("scan read timeout") + return None + si = s.find(first_line) + ei = s.find(last_line) + if (si == -1) or (ei == -1): + print("begin, end not found") + return None + si = s.find('\n', si, ei) + return numpy.fromstring(s[si:ei], dtype=float, count=-1, sep=' ') + def rdevice_com_test(rcon): rcon.write("init\n"); rcon.write("run\n"); @@ -134,20 +155,11 @@ if __name__ == '__main__': scan_cnt = 0 scan_all=numpy.ndarray(shape=(0,0), dtype=float) while True: - r.wait_stamp() - r.rcon.write("run\n"); - s = r.get_multiline(last_line = 'end') - if s is None: - print("scan read timeout") - continue - si = s.find('bank') - ei = s.find('end') - if (si == -1) or (ei == -1): - print("bank, end not found") + scan_act=r.get_multiline_vector(command = 'run\n', + first_line = 'bank', last_line = 'end') + if scan_act is None: continue - si = s.find('\n', si, ei) - scan_act=numpy.fromstring(s[si:ei], dtype=float, count=-1, sep=' ') - print(scan_act); + print(scan_act) if scan_all.size == 0: scan_all=numpy.ndarray(shape=(scan_count,scan_act.size), dtype=float) scan_all[scan_cnt,:]=scan_act @@ -166,3 +178,39 @@ if __name__ == '__main__': F.write('\n') F.close() exit(0) + + if action == 'plot': + plt_block = True + + if not plt_block: + fig, ax = plt.subplots(1, 1) + plt.show(False) + plt.draw() + r.wait_stamp() + r.rcon.write("init\n"); + scan_cnt = 0 + scan_last = None; + plt_first = True + + while True: + scan_act=r.get_multiline_vector(command = 'run\n', + first_line = 'bank', last_line = 'end') + if scan_act is None: + continue + print(scan_act) + if scan_last is None: + scan_last = scan_act + if plt_block or plt_first: + fig, ax = plt.subplots(1, 1) + last_line = ax.plot(range(len(scan_last)), scan_last, 'y')[0] + act_line = ax.plot(range(len(scan_act)), scan_act, 'r')[0] + plt_first = False + else: + last_line.set_data(range(len(scan_last)), scan_last) + act_line.set_data(range(len(scan_act)), scan_act) + #act_line.set_xdata(scan_act) + fig.canvas.draw() + plt.show(plt_block) + + scan_last = scan_act + time.sleep(1) -- 2.39.2