1 | __author__ = 'delerue' |
---|
2 | |
---|
3 | from PIL import Image |
---|
4 | import subprocess |
---|
5 | import time |
---|
6 | import urllib |
---|
7 | from datetime import datetime |
---|
8 | from bpm_constants import * |
---|
9 | from writeclient import writeclient |
---|
10 | |
---|
11 | #global SCOPE_IP |
---|
12 | #SCOPE_IP = '10.0.1.112' |
---|
13 | scope_image_url="http://"+SCOPE_IP+"/crt_print.png" |
---|
14 | |
---|
15 | def read_image(image_name_and_path): |
---|
16 | p = subprocess.Popen(["display",image_name_and_path]) |
---|
17 | print "tic" |
---|
18 | time.sleep(10) |
---|
19 | print "toc" |
---|
20 | p.kill() |
---|
21 | |
---|
22 | |
---|
23 | def read_images_from_scope(nimages): |
---|
24 | iimage=1 |
---|
25 | subproc=0 |
---|
26 | start_time_str=datetime.now().strftime("%Y%m%d_%H%M%S") |
---|
27 | for iimage in range(nimages): |
---|
28 | image_name_and_path=data_dir+"scope_image_"+start_time_str+"_"+str(iimage)+".png" |
---|
29 | urllib.urlretrieve(scope_image_url,image_name_and_path) |
---|
30 | if (subproc !=0): |
---|
31 | subproc.kill() |
---|
32 | subproc = subprocess.Popen(["display",image_name_and_path]) |
---|
33 | time.sleep(2) |
---|
34 | time.sleep(10) |
---|
35 | if (subproc !=0): |
---|
36 | subproc.kill() |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | def scpi_query(command): |
---|
41 | reply=writeclient(SCOPE_IP,5025,command+chr(10),1) |
---|
42 | print "SCPI: ",command," => ", reply |
---|
43 | return reply |
---|
44 | |
---|
45 | def scpi_command(command): |
---|
46 | writeclient(SCOPE_IP,5025,command+chr(10),1) |
---|
47 | print "SCPI: ",command |
---|
48 | |
---|
49 | def turn_on(): |
---|
50 | scpi_command('CHAN1:STAT ON \nCHAN1:STAT?') |
---|
51 | scpi_command('CHAN2:STAT ON \nCHAN2:STAT?') |
---|
52 | scpi_command('CHAN3:STAT ON \nCHAN1:STAT?') |
---|
53 | scpi_command('CHAN4:STAT ON \nCHAN2:STAT?') |
---|
54 | scpi_command('CURS1:STAT ON \nCURS1:STAT?') |
---|
55 | |
---|
56 | def turn_off(): |
---|
57 | scpi_command('CURS1:STAT OFF \nCURS1:STAT?') |
---|
58 | scpi_command('CHAN1:STAT OFF \nCHAN1:STAT?') |
---|
59 | scpi_command('CHAN2:STAT OFF \nCHAN2:STAT?') |
---|
60 | scpi_command('CHAN3:STAT OFF \nCHAN2:STAT?') |
---|
61 | scpi_command('CHAN4:STAT OFF \nCHAN2:STAT?') |
---|
62 | |
---|
63 | def suppress_alignea(l): |
---|
64 | L = '' |
---|
65 | for i in l: |
---|
66 | if not(i == '\n'): |
---|
67 | L += i |
---|
68 | return(L) |
---|
69 | |
---|
70 | def read_scope_and_write(position, path): |
---|
71 | fichier = open(path, "a") |
---|
72 | fichier.write(str(position)+' ') |
---|
73 | L = [position] |
---|
74 | for i in range(4): |
---|
75 | scpi_command('CURS1:SOUR CH'+str(i+1)+' \n CURS1:SOUR?') |
---|
76 | valeur = scpi_query('CURS1:FUNC UPE \n CURS:RES?') |
---|
77 | valeur = suppress_alignea(valeur) |
---|
78 | L.append(float(valeur)) |
---|
79 | fichier.write(valeur+' ') |
---|
80 | fichier.write('\n') |
---|
81 | fichier.close() |
---|
82 | return(L) |
---|
83 | |
---|
84 | |
---|
85 | def read_scope_and_write_2D(x ,y ,path): |
---|
86 | fichier = open(path, "a") |
---|
87 | fichier.write(str(x)+' '+str(y)+' ') |
---|
88 | L = [x,y] |
---|
89 | for i in range(4): |
---|
90 | scpi_command('CURS1:SOUR CH'+str(i+1)+' \n CURS1:SOUR?') |
---|
91 | valeur = scpi_query('CURS1:FUNC UPE \n CURS:RES?') |
---|
92 | valeur = suppress_alignea(valeur) |
---|
93 | L.append(float(valeur)) |
---|
94 | fichier.write(valeur+' ') |
---|
95 | fichier.write('\n') |
---|
96 | fichier.close() |
---|
97 | return(L) |
---|
98 | |
---|
99 | |
---|