source: ETALON/BPM/scope_function.py @ 778

Last change on this file since 778 was 778, checked in by moutardier, 6 years ago

Correction of path in bpm_constante.py + creation fonction acquisition for taking data along a matrice (work) and create new fonction for this

File size: 2.6 KB
Line 
1__author__ = 'delerue'
2
3from PIL import Image
4import subprocess
5import time
6import urllib
7from datetime import datetime
8from bpm_constants import *
9from writeclient import writeclient
10
11#global SCOPE_IP
12#SCOPE_IP = '10.0.1.112'
13scope_image_url="http://"+SCOPE_IP+"/crt_print.png"
14
15def 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
23def 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
40def scpi_query(command):
41    reply=writeclient(SCOPE_IP,5025,command+chr(10),1)
42    print "SCPI: ",command," => ", reply
43    return reply
44
45def scpi_command(command):
46    writeclient(SCOPE_IP,5025,command+chr(10),1)
47    print "SCPI: ",command
48
49def 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
56def 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
63def suppress_alignea(l):
64    L = ''
65    for i in l:
66        if not(i == '\n'):
67            L += i
68    return(L)
69   
70def 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
85def 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
Note: See TracBrowser for help on using the repository browser.