Changeset 638 in ETALON for CLIO


Ignore:
Timestamp:
Mar 2, 2017, 12:03:27 AM (7 years ago)
Author:
delerue
Message:

CLIO controls updated

Location:
CLIO/control
Files:
13 added
3 edited

Legend:

Unmodified
Added
Removed
  • CLIO/control/CLIO_graphical_interface.py

    r637 r638  
    1515import os
    1616
    17 data_directory="/Users/delerue/Downloads/CLIO/"
     17from motor_function import *
     18
     19data_directory_base="/var/www/html/CLIO/"
     20today_str = time.strftime("%Y%m%d")
     21data_directory=data_directory_base+today_str+"/"
    1822
    1923threshold_recent=   20
     
    2226ImagesDisplaySize=(600,400)
    2327
     28MOTOR_NUMBER=1;
     29FILE_PAUSE='/home/etalon-admin/acquisition_data/pause_acquisition';
     30FILE_STOP='/home/etalon-admin/acquisition_data/stop_acquisition';
     31
    2432imageNames=[]
    25 imageNames.append("/Users/delerue/Downloads/CLIO/last_zoom.png")
    26 imageNames.append("/Users/delerue/Downloads/CLIO/last_signal.png")
    27 
     33imageNames.append("/home/etalon-admin/control/no_data.png")
     34imageNames.append("/home/etalon-admin/control/no_data.png")
    2835
    2936class MainWindow(Frame):
     
    4047    def initUI(self):
    4148
    42     #----------------
     49    #----------------       
    4350        self.terminate=0
    44        
     51        print(data_directory)
    4552        # canvas for image
    4653        self.canvas = Canvas(self.parent, width=800, height=400)
     
    5461        self.imageLabel2=Label(self.frameImages,image=self.my_images[1])
    5562        self.imageLabel2.pack(side = "right", fill = "both", expand = "yes")
    56 #        self.images_on_canvas = []
    57 #        self.images_on_canvas.append(self.canvas.create_image(  0,   0, anchor = NW, image = self.my_images[0]))
    58 #        self.images_on_canvas.append(self.canvas.create_image(400, 0, anchor = NW, image = self.my_images[1]))
    59 #        self.images_on_canvas.append(Label( image = self.my_images[0]))
    60 #        self.images_on_canvas.append(self.canvas.create_image(400, 0, anchor = NW, image = self.my_images[1]))
    6163
    6264        #Control buttons
     
    7375        self.latestFileProcessed = Label(self.frameStatus, font=('times', 14, 'bold'), bg='blue')
    7476        self.latestFileProcessed.pack(side=TOP)
     77        self.latestFileWithSignal = Label(self.frameStatus, font=('times', 14, 'bold'), bg='blue')
     78        self.latestFileWithSignal.pack(side=TOP)
    7579
    7680        #data acquisition
     
    7983        labelAcquisition=Label(self.frameAcquisition,text='Data Acquisition')
    8084        labelAcquisition.grid(row=0,column=0,columnspan=2)
    81         self.buttonAcq = Button(self.frameAcquisition, text="Start acquisition", command=self.onButtonAcqStart)
    82         self.buttonAcq.grid(row=1,column=0)
    83         self.buttonAcq = Button(self.frameAcquisition, text="Pause acquisition", command=self.onButtonAcqPause)
    84         self.buttonAcq.grid(row=1,column=1)
    85         self.labelAcquisitionStatus=Label(self.frameAcquisition,text='Status: unkown', bg='blue')
    86         self.labelAcquisitionStatus.grid(row=2,column=0)
     85        self.buttonAcqPause = Button(self.frameAcquisition, text="Pause acquisition", command=self.onButtonAcqPause)
     86        self.buttonAcqPause.grid(row=1,column=0)
     87        self.buttonAcqStop = Button(self.frameAcquisition, text="Stop acquisition", command=self.onButtonAcqStop)
     88        self.buttonAcqStop.grid(row=2,column=0)
     89        self.labelAcquisitionStatus=Label(self.frameAcquisition,text='Status: unkown', bg='magenta')
     90        self.labelAcquisitionStatus.grid(row=3,column=0)
    8791     
    8892           
    89        
    90 #        labelxa=Label(self.frameXA,text='Xa')
    91 #        labelxa.pack(side=TOP)
    92 #        scaleXA = Scale(self.frameXA, from_=0, to=100,
    93 #            command=self.onButton)
    94 #        scaleXA.pack()
    95 
    96 
    97         # button to control position
    98         self.button = Button(self.frameAllControls, text="Change1", command=self.onButton)
    99         self.button.pack(side=LEFT)
    100         self.button2 = Button(self.frameAllControls, text="Change2", command=self.onButton)
    101         self.button2.pack(side=LEFT)
     93        #Motor function
     94        self.frameMotors = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN)
     95        self.frameMotors.pack(side=LEFT)
     96        labelMotors=Label(self.frameMotors,text='Motors Control')
     97        labelMotors.grid(row=0,column=0,columnspan=4)
     98        buttonRetractFull = Button(self.frameMotors, text="Retract completely", command=self.onButtonRetract)
     99        buttonRetractFull.grid(row=1,column=0)
     100        buttonInsert = Button(self.frameMotors, text="Insert to signal pos.", command=self.onButtonInsert)
     101        buttonInsert.grid(row=2,column=0)
     102        buttonBackward20k = Button(self.frameMotors, text="Backward 20k", command=self.onButtonBkd20k)
     103        buttonBackward20k.grid(row=1,column=1)
     104        buttonBackward100k = Button(self.frameMotors, text="Backward 100k", command=self.onButtonBkd100k)
     105        buttonBackward100k.grid(row=1,column=2)
     106        buttonBackward1m = Button(self.frameMotors, text="Backward 1M", command=self.onButtonBkd1m)
     107        buttonBackward1m.grid(row=1,column=3)
     108        buttonForward20k = Button(self.frameMotors, text="Forward 20k", command=self.onButtonFwd20k)
     109        buttonForward20k.grid(row=2,column=1)
     110        buttonForward100k = Button(self.frameMotors, text="Forward 100k", command=self.onButtonFwd100k)
     111        buttonForward100k.grid(row=2,column=2)
     112        buttonForward1m = Button(self.frameMotors, text="Forward 1M", command=self.onButtonFwd1m)
     113        buttonForward1m.grid(row=2,column=3)
     114        self.labelPosition=Label(self.frameMotors,text='Status: unkown', bg='blue')
     115        self.labelPosition.grid(row=3,column=0,columnspan=4)
     116     
    102117       
    103118        #Exit
     
    106121
    107122        self.update_clock()
    108 
    109     #----------------
    110     def onButtonAcqStart(self):
    111         # next image
    112         self.my_image_number += 1
    113     #----------------
    114     def onButtonAcqPause(self):
    115 
    116         # next image
    117         self.my_image_number += 1
    118     #----------------
    119     def onButton(self):
    120 
    121         # next image
    122         self.my_image_number += 1
    123 
    124         # return to first image
    125         self.my_image_number = 0
    126 
    127         # change image
    128 #        self.canvas.itemconfig(self.image_on_canvas, image = self.my_images[self.my_image_number])
     123        self.motorUpdateErrors=0;
     124        self.getMotorPosition(1)
     125
    129126
    130127    def update_clock(self):
     
    133130       
    134131        list_of_files_acquired = glob.glob(data_directory+"data_CLIO*.txt")
    135         latest_file_acquired = max(list_of_files_acquired, key=os.path.getctime)
    136         filetime=os.path.getctime(latest_file_acquired)
    137         if (time.time()-filetime)<threshold_recent:
    138             bgcolortxt='green'
    139         elif (time.time()-filetime)<threshold_old:
    140             bgcolortxt='blue'
    141         else:
    142             bgcolortxt='red'
    143         self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt)
    144 
    145         list_of_files_processed = glob.glob(data_directory+"data_CLIO*.sig")
    146         latest_file_processed = max(list_of_files_processed, key=os.path.getctime)
    147         filetime=os.path.getctime(latest_file_processed)
    148         if (time.time()-filetime)<threshold_recent:
    149             bgcolortxt='green'
    150         elif (time.time()-filetime)<threshold_old:
    151             bgcolortxt='blue'
    152         else:
    153             bgcolortxt='red'
    154         self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt)
    155 
    156         imageNames[0]=latest_file_processed.replace(".sig","_zoom.png")
    157         imageNames[1]=latest_file_processed.replace(".sig","_signal.png")
     132        #print(list_of_files_acquired)
     133        if (len(list_of_files_acquired)>0):
     134            latest_file_acquired = max(list_of_files_acquired, key=os.path.getctime)
     135            filetime=os.path.getctime(latest_file_acquired)
     136            if (time.time()-filetime)<threshold_recent:
     137                bgcolortxt='green'
     138            elif (time.time()-filetime)<threshold_old:
     139                bgcolortxt='blue'
     140            else:
     141                bgcolortxt='red'
     142            self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt)
     143
     144        list_of_files_processed = glob.glob(data_directory+"data_CLIO*.png")
     145        #print(list_of_files_processed)
     146        if (len(list_of_files_processed)>0):
     147            latest_file_processed = max(list_of_files_processed, key=os.path.getctime)
     148            filetime=os.path.getctime(latest_file_processed)
     149            if (time.time()-filetime)<threshold_recent:
     150                bgcolortxt='green'
     151            elif (time.time()-filetime)<threshold_old:
     152                bgcolortxt='blue'
     153            else:
     154                bgcolortxt='red'
     155            self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt)
     156            imageNames[0]=latest_file_processed;
     157
     158
     159        list_of_files_with_signal = glob.glob(data_directory+"data_CLIO*.sig")
     160        #print(list_of_files_with_signal)
     161        if (len(list_of_files_with_signal)>0):
     162            latest_file_with_signal = max(list_of_files_with_signal, key=os.path.getctime)
     163            filetime=os.path.getctime(latest_file_with_signal)
     164            if (time.time()-filetime)<threshold_recent:
     165                bgcolortxt='green'
     166            elif (time.time()-filetime)<threshold_old:
     167                bgcolortxt='blue'
     168            else:
     169                bgcolortxt='red'
     170            self.latestFileWithSignal.config(text=os.path.basename(latest_file_with_signal),bg=bgcolortxt)
     171
     172            imageNames[0]=latest_file_with_signal.replace(".sig","_zoom.png")
     173            imageNames[1]=latest_file_with_signal.replace(".sig","_signal.png")
     174            self.newImage2=ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS))
     175            self.imageLabel2.configure(image=self.newImage2)
     176            self.imageLabel2.image=self.newImage2
     177
    158178        self.newImage1=ImageTk.PhotoImage(Image.open(imageNames[0]).resize(ImagesDisplaySize, Image.ANTIALIAS))
    159         self.newImage2=ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS))
    160 #        self.images_on_canvas[0].config(image=self.my_images[0])
    161 #        self.images_on_canvas[0].reconfigure(self.canvas.create_image(  0,   0, anchor = NW, image = self.my_images[0]))
    162 #        self.images_on_canvas[1].reconfigure(self.canvas.create_image(400, 0, anchor = NW, image = self.my_images[1]))
    163179        self.imageLabel1.configure(image=self.newImage1)
    164180        self.imageLabel1.image=self.newImage1
    165         self.imageLabel2.configure(image=self.newImage2)
    166         self.imageLabel2.image=self.newImage2
    167        
    168         self.labelAcquisitionStatus.config(text='checking')
    169        
    170 #        fid = open('/Users/delerue/Downloads/bpm_pos.tmp', 'r')
    171 #        self.canvas.itemconfigure(self.xpos,text=xval)
    172 #       fid.close()
     181
     182
     183        #Check acquisition status
     184        stop_file = glob.glob(FILE_STOP)
     185        pause_file = glob.glob(FILE_PAUSE)
     186        if (len(stop_file)):
     187            self.labelAcquisitionStatus.config(text="Stop",bg='red')
     188            self.buttonAcqPause.config(text="Program stopped!")
     189        elif (len(pause_file)):
     190            self.labelAcquisitionStatus.config(text="Pause", bg='blue')
     191            self.buttonAcqPause.config(text="Restart")
     192        else:
     193            self.labelAcquisitionStatus.config(text="Enabled", bg='green')
     194           
    173195        self.update_idletasks()
    174196        if self.terminate==0:
    175197                self.after(500, self.update_clock)
     198
     199
     200    def getMotorPosition(self,start_updates):
     201        try:
     202            motor_position=motor_get(MOTOR_NUMBER, 'actual_position');
     203            print("Motor position ");
     204            print(motor_position);
     205            self.labelPosition.config(text=motor_position);
     206            self.labelPosition.config(bg='green');
     207            self.motorUpdateErrors=0;
     208        except:
     209            time.sleep(1)
     210            print "Error while reading the motor position"
     211            time.sleep(1)
     212            motor_position=-1;
     213            if (self.motorUpdateErrors>10):
     214                self.labelPosition.config(bg='blue');
     215            if (self.motorUpdateErrors>30):
     216                self.labelPosition.config(bg='red');
     217            self.motorUpdateErrors=self.motorUpdateErrors+1;
     218        if ((self.terminate==0)and(start_updates==1)):
     219            print "No Motor position update"
     220            print "start_updates"
     221            print start_updates
     222            #self.after(1000, self.getMotorPosition(1))
     223
     224               
     225    #----------------
     226    def onButtonRetract(self):
     227        print "Move motor Retract"       
     228        motor_move_absolute(MOTOR_NUMBER,10000,0)
     229        self.getMotorPosition(0)
     230        time.sleep(2)
     231        self.getMotorPosition(0)
     232
     233    def onButtonInsert(self):
     234        print "Move motor Insert"       
     235        motor_move_absolute(MOTOR_NUMBER,10000,7200000)
     236        self.getMotorPosition(0)
     237        time.sleep(2)
     238        self.getMotorPosition(0)
     239
     240
     241    def moveMotor(self,direction,step):
     242        print "Move motor ",direction,"  ",step       
     243        if ((direction!=0)and(step>0)):
     244            motor_move_relative(MOTOR_NUMBER,10000,direction*step)
     245            self.getMotorPosition(0)
     246            time.sleep(2)
     247            self.getMotorPosition(0)
     248            time.sleep(2)
     249            self.getMotorPosition(0)
     250   
     251    #----------------
     252    def onButtonBkd20k(self):
     253        self.moveMotor(-1,20000)
     254
     255        #----------------
     256    def onButtonBkd100k(self):
     257        self.moveMotor(-1,100000)
     258
     259    #----------------
     260    def onButtonBkd1m(self):
     261        self.moveMotor(-1,1000000)
     262
     263    #----------------
     264    def onButtonFwd20k(self):
     265        self.moveMotor(1,20000)
     266
     267    #----------------
     268    def onButtonFwd100k(self):
     269        self.moveMotor(1,100000)
     270
     271    #----------------
     272    def onButtonFwd1m(self):
     273        self.moveMotor(1,1000000)
     274
     275
     276    #----------------
     277    def onButtonAcqPause(self):
     278        pause_file = glob.glob(FILE_PAUSE)
     279        if (len(pause_file)==0):
     280            filename=FILE_PAUSE
     281            fid=open(filename,'w')
     282            fid.write("pause")
     283            fid.close()
     284        else:
     285            os.remove(FILE_PAUSE)
     286            self.buttonAcqPause.config(text="Pause")
     287
     288    #----------------
     289    def onButtonAcqStop(self):
     290        filename=FILE_STOP
     291        fid=open(filename,'w')
     292        fid.write("stop")
     293        fid.close()
     294       
     295    #----------------
     296#    def onButton(self):
     297
     298        # next image
     299#        self.my_image_number += 1
     300
     301        # return to first image
     302#        self.my_image_number = 0
    176303
    177304    def onExitKey(self,event):
  • CLIO/control/clio_constants.py

    r628 r638  
    33global data_dir
    44#data_dir="C:\\CLIO\\data\\20161201\\"
    5 data_dir="/Users/delerue/Downloads/CLIO/"
     5data_dir="/home/etalon-admin/acquisition_data"
    66
    77SCOPE1_IP='129.175.202.193'
  • CLIO/control/read_data.py

    r636 r638  
    1111
    1212def read_data(filename):
    13     alldata=np.loadtxt(filename, dtype='int16', comments='#', delimiter='  ', usecols=range(1,33), converters={ _:lambda s:  int(s , 16)  for _ in range(0,33) })
     13    nchannels=32
     14    alldata=np.loadtxt(filename, dtype='int32', comments='#', delimiter='  ', usecols=range(0,nchannels), converters={ _:lambda s:  int(s , 16)  for _ in range(0,nchannels) })
    1415    #alldata=np.loadtxt('/Users/delerue/Downloads/data_CLIO_2017-01-23_22-40-25_tail20.txt', dtype='int16', delimiter='  ', usecols=range(1,33), converters={ _:lambda s:  int('0'+s , 16)  for _ in range(0,33) })
    1516    #print(alldata)
    16     data_length=len(alldata[:,1])
    17     print(alldata[:,1])
    18     print(range(1,data_length+1))
     17    data_length=len(alldata)
     18    print('Records: ', data_length)
     19    print(alldata[1,:])
     20    alldata=alldata%(2**16)
     21    alldata=(2**15)-alldata
     22    alldata=alldata*(5000000/2**16)
     23    print(alldata[1,:])
     24#    print((2**15)-alldata[1,:])
     25#    print(overflow_data[1,:])
     26    #print(range(1,data_length+1))
    1927
    20     fig=plt.figure(figsize=(6, 4))
    21     for idata in range(0,32):
     28    alldata[:,30]=alldata[:,30]/10
     29    fig=plt.figure(figsize=(12, 8))
     30#    for idata in range(17,nchannels):
     31    for idata in range(28,29):
    2232        txtline='r--'
    23         if idata == 1:
     33        if idata%6==0:
     34            txtline='b'
     35        if idata%6==1:
     36            txtline='g'
     37        if idata%6==2:
     38            txtline='k'
     39        if idata%6==3:
     40            txtline='c'
     41        if idata%6==4:
     42            txtline='m'
     43        if idata%6==5:
     44            txtline='y'
     45        if idata==17:
     46            txtline='r'
     47        if idata==20:
     48            txtline='r'
     49        if idata==22:
     50            txtline='r'
     51        if idata==30:
    2452            txtline='bs'
    25         if idata == 2:
    26             txtline='g^'
    27        
    28         plt.plot(range(1,data_length+1),alldata[:,idata], txtline)
    29     plt.show()
     53
     54#28 Is position
     55           
     56#        data_start=9022
     57#        data_length=9035
     58        data_start=1
     59        data_length=9035
     60        plt.plot(range(data_start,data_length),alldata[range(data_start,data_length),idata], txtline)
     61#    plt.show()
    3062    imagename=filename.replace('.txt','.png')
    3163    print(imagename)
    3264    fig.savefig(imagename)
    3365    plt.close(fig)
     66    imagename_no_path=imagename.replace('/var/www/html/CLIO/20170208/','')
     67    fid=open('list.html','a');
     68    fid.write("<A HREF=")
     69    fid.write(imagename_no_path)
     70    fid.write("><IMG SRC=")
     71    fid.write(imagename_no_path)
     72    fid.write(" width=600>")
     73    fid.write("</A><BR/>")
     74    fid.write(imagename_no_path)
     75    fid.write("<BR/><BR/>\n")
     76    fid.close()
     77
     78    #Looking for electrons
     79    if (min(alldata[:,30])<-10000):
     80        elec=alldata[:,30]
     81        pos_elec=elec.argmin()
     82        print(pos_elec)
     83        figzoom=plt.figure(figsize=(12, 8))
     84        for idata in range(17,nchannels):
     85            txtline='r--'
     86            if idata%5==0:
     87                txtline='g'
     88            if idata%5==2:
     89                txtline='k'
     90            if idata%5==3:
     91                txtline='c'
     92            if idata%5==4:
     93                txtline='m'
     94            if idata%5==1:
     95                txtline='y'
     96            if idata==17:
     97                txtline='g'
     98            if idata==20:
     99                txtline='g'
     100            if idata==22:
     101                txtline='r'
     102            if idata==30:
     103                txtline='bs'
     104           
     105            data_start=pos_elec-50           
     106            data_length=pos_elec+50
     107            plt.plot(range(data_start,data_length),alldata[range(data_start,data_length),idata], txtline)
     108            #    plt.show()
     109        imagenamezoom=filename.replace('.txt','_zoom.png')
     110        figzoom.savefig(imagenamezoom)
     111        plt.close(figzoom)
     112   
     113        imagenamezoom_no_path=imagenamezoom.replace('/var/www/html/CLIO/20170208/','')
     114        fid=open('zoom_list.html','a');
     115        fid.write("<A HREF=")
     116        fid.write(imagenamezoom_no_path)
     117        fid.write("><IMG SRC=")
     118        fid.write(imagenamezoom_no_path)
     119        fid.write(" width=600>")
     120        fid.write("</A><BR/>")
     121        fid.write(imagenamezoom_no_path)
     122        fid.write("<BR/><BR/>\n")
     123        fid.close()
     124       
    34125    return;
    35 read_data('/Users/delerue/Downloads/data_CLIO_2017-01-23_22-04-38_head5.txt')
     126
     127#read_data('/Users/delerue/Downloads/data_CLIO_2017-01-23_22-04-38_head5.txt')
     128
     129#read_data('/home/etalon-admin/DAQ/18ai32ssc1m/savedata/data_CLIO_2017-02-06_17-59-06.txt')
     130#read_data('/home/etalon-admin/DAQ/18ai32ssc1m/savedata/data_CLIO_2017-02-06_18-47-26.txt')
     131#read_data('/home/etalon-admin/svn/ETALON/CLIO/control/data/last.txt')
     132#HWaddr 64:00:6a:3a:6f:1c
Note: See TracChangeset for help on using the changeset viewer.