Ignore:
Timestamp:
Nov 2, 2017, 12:38:09 PM (7 years ago)
Author:
delerue
Message:

CLIO control system updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CLIO/control/CLIO_graphical_interface.py

    r691 r744  
    1515import os
    1616import subprocess
     17import urllib2
    1718
    1819#from motor_function import *
     
    2627from clio_constants import *
    2728
    28 INSERTED_VALUE1=4000000
     29INSERTED_VALUE1=5500000
    2930INSERTED_VALUE2=5000000
    3031
     
    3233threshold_old=      100
    3334
    34 ImagesDisplaySize=(600,400)
     35ImagesDisplaySize=(400,300)
     36N_IMAGES_LINES=2
     37N_IMAGES_COLS=3
     38N_IMAGES=N_IMAGES_LINES*N_IMAGES_COLS
    3539
    3640PROCESSES_REFRESH_INTERVAL=10
    3741
    3842imageNames=[]
    39 imageNames.append(code_directory+"no_data.png")
    40 imageNames.append(code_directory+"no_data.png")
     43for iimage in range(N_IMAGES):
     44    imageNames.append(code_directory+"no_data.png")
     45   
     46URI='http://'+IP_POWER_IP+'/Set.cmd'
     47auth_handler=urllib2.HTTPBasicAuthHandler()
     48auth_handler.add_password(realm='IP9258',uri=URI,user='admin',passwd='12345678')
     49opener= urllib2.build_opener(auth_handler)
     50urllib2.install_opener(opener)
    4151
    4252#This is used for variables that are not updated on each refresh cycle
     
    5868        self.terminate=0
    5969        self.refresh_loop=0
    60         print(data_directory)
    6170        # canvas for image
    62         self.canvas = Canvas(self.parent, width=800, height=400)
     71        self.canvas = Canvas(self.parent, width=800, height=800)
    6372        self.frameImages = Frame(self.parent, borderwidth=10)
    6473        self.frameImages.grid(row=1, column=0)
    6574        self.my_images=[]
    66         self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[0]).resize(ImagesDisplaySize, Image.ANTIALIAS)))
    67         self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS)))
    68         self.imageLabel1=Label(self.frameImages,image=self.my_images[0])
    69         self.imageLabel1.pack(side = "left", fill = "both", expand = "yes")
    70         self.imageLabel2=Label(self.frameImages,image=self.my_images[1])
    71         self.imageLabel2.pack(side = "right", fill = "both", expand = "yes")
     75        self.imageLabel=[]
     76        self.newImage=[]       
     77        for iline in range(N_IMAGES_LINES):
     78            for icol in range(N_IMAGES_COLS):
     79                iimage=iline*N_IMAGES_COLS+icol
     80                self.my_images.append(ImageTk.PhotoImage(Image.open(imageNames[iimage]).resize(ImagesDisplaySize, Image.ANTIALIAS)))
     81                self.imageLabel.append(Label(self.frameImages,image=self.my_images[iimage]))
     82                self.imageLabel[iimage].grid(row=iline,column=icol)
    7283
    7384        #Control buttons
     
    98109        self.labelAcquisitionStatus=Label(self.frameAcquisition,text='Status: unkown', bg='magenta')
    99110        self.labelAcquisitionStatus.grid(row=3,column=0)
     111        self.labelAcquisitionRate=Label(self.frameAcquisition,text='Rate: unkown', bg='magenta')
     112        self.labelAcquisitionRate.grid(row=4,column=0)
     113        self.labelAcquisitionPause=Label(self.frameAcquisition,text='Pause: unkown', bg='magenta')
     114        self.labelAcquisitionPause.grid(row=5,column=0)
    100115     
    101            
     116        #Power status
     117        self.framePower = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN)
     118        self.framePower.pack(side=LEFT)
     119        labelPower=Label(self.framePower,text='IP Power')
     120        labelPower.grid(row=0,column=0,columnspan=2)
     121        self.buttonPower=[ Button(self.framePower, text=str(ipower), command= lambda v=ipower: self.onButtonPower(v)) for ipower in range(4) ]
     122        for ipower in range(4):
     123            self.buttonPower[ipower].grid(row=ipower+1,column=0)
     124            #self.buttonPower[ipower].pack(side=BOTTOM)
     125        self.buttonPower[0].config(text="Camera")
     126        self.buttonPower[1].config(text="Blinker")
     127        self.buttonPower[2].config(text="Amplifier")
     128        self.buttonPower[3].config(text="Wago+Pot")
     129                   
    102130        #Motor function
    103131        self.frameMotors = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN)
     
    135163        self.frameProcesses = Frame(self.frameAllControls, borderwidth=10, relief=SUNKEN)
    136164        self.frameProcesses.pack(side=LEFT)
     165        self.labelProcessIPPower=Label(self.frameProcesses,text='IP Power', bg='blue')
     166        self.labelProcessIPPower.grid(row=0,column=0,columnspan=1)
    137167        self.labelProcessWago=Label(self.frameProcesses,text='WAGO', bg='blue')
    138         self.labelProcessWago.grid(row=0,column=0,columnspan=1)
     168        self.labelProcessWago.grid(row=1,column=0,columnspan=1)
    139169        self.labelProcessMotorMonitor=Label(self.frameProcesses,text='Motor monitor', bg='blue')
    140         self.labelProcessMotorMonitor.grid(row=1,column=0,columnspan=1)
     170        self.labelProcessMotorMonitor.grid(row=2,column=0,columnspan=1)
    141171        self.labelProcessSaveData=Label(self.frameProcesses,text='Savedata', bg='blue')
    142         self.labelProcessSaveData.grid(row=2,column=0,columnspan=1)
     172        self.labelProcessSaveData.grid(row=3,column=0,columnspan=1)
    143173        self.labelProcessProcessRecent=Label(self.frameProcesses,text='Process recent', bg='blue')
    144         self.labelProcessProcessRecent.grid(row=3,column=0,columnspan=1)
     174        self.labelProcessProcessRecent.grid(row=4,column=0,columnspan=1)
    145175       
    146176        #Exit
     
    165195            if (time.time()-filetime)<threshold_recent:
    166196                bgcolortxt='green'
     197                fgcolortxt='black'
    167198            elif (time.time()-filetime)<threshold_old:
    168199                bgcolortxt='blue'
    169             else:
    170                 bgcolortxt='red'
    171             self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt)
     200                fgcolortxt='white'
     201            else:
     202                bgcolortxt='red'
     203                fgcolortxt='black'
     204            self.latestFileAcquired.config(text=os.path.basename(latest_file_acquired),bg=bgcolortxt,fg=fgcolortxt)
    172205
    173206        list_of_files_processed = glob.glob(data_directory+"data_CLIO*.png")
    174207        #print(list_of_files_processed)
    175208        if (len(list_of_files_processed)>0):
    176             latest_file_processed = max(list_of_files_processed, key=os.path.getctime)
     209            #latest_file_processed = max(list_of_files_processed, key=os.path.getctime)
     210            latest_file_processed = max(sorted(list_of_files_processed))
    177211            filetime=os.path.getctime(latest_file_processed)
    178212            if (time.time()-filetime)<threshold_recent:
    179213                bgcolortxt='green'
     214                fgcolortxt='black'
    180215            elif (time.time()-filetime)<threshold_old:
    181216                bgcolortxt='blue'
    182             else:
    183                 bgcolortxt='red'
    184             self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt)
     217                fgcolortxt='white'
     218            else:
     219                bgcolortxt='red'
     220                fgcolortxt='black'
     221            self.latestFileProcessed.config(text=os.path.basename(latest_file_processed),bg=bgcolortxt,fg=fgcolortxt)
    185222            imageNames[0]=latest_file_processed;
    186223
     
    189226        #print(list_of_files_with_signal)
    190227        if (len(list_of_files_with_signal)>0):
    191             latest_file_with_signal = max(list_of_files_with_signal, key=os.path.getctime)
     228            #latest_file_with_signal = max(list_of_files_with_signal, key=os.path.getctime)
     229            latest_file_with_signal = max(sorted(list_of_files_with_signal))
    192230            filetime=os.path.getctime(latest_file_with_signal)
    193231            if (time.time()-filetime)<threshold_recent:
    194232                bgcolortxt='green'
     233                fgcolortxt='black'
    195234            elif (time.time()-filetime)<threshold_old:
    196235                bgcolortxt='blue'
    197             else:
    198                 bgcolortxt='red'
    199             self.latestFileWithSignal.config(text=os.path.basename(latest_file_with_signal),bg=bgcolortxt)
    200 
    201             imageNames[0]=latest_file_with_signal.replace(".sig","_zoom.png")
    202             imageNames[1]=latest_file_with_signal.replace(".sig","_signal.png")
     236                fgcolortxt='white'
     237            else:
     238                bgcolortxt='red'
     239                fgcolortxt='black'
     240            self.latestFileWithSignal.config(text=os.path.basename(latest_file_with_signal),bg=bgcolortxt,fg=fgcolortxt)
     241
     242            imageNames[0]=latest_file_with_signal.replace(".sig",".png")
     243            imageNames[1]=latest_file_with_signal.replace(".sig","_zoom.png")
     244            imageNames[2]=latest_file_with_signal.replace(".sig","_signal.png")
    203245            time.sleep(0.1)
    204             try:
    205                 self.newImage2=ImageTk.PhotoImage(Image.open(imageNames[1]).resize(ImagesDisplaySize, Image.ANTIALIAS))
    206             except:
    207                 print("An error occurred while opening the image")
    208             self.imageLabel2.configure(image=self.newImage2)
    209             self.imageLabel2.image=self.newImage2
    210         time.sleep(0.1)
    211         try:
    212                 self.newImage1=ImageTk.PhotoImage(Image.open(imageNames[0]).resize(ImagesDisplaySize, Image.ANTIALIAS))
    213         except:
    214                 print("An error occurred while opening the image")
    215         self.imageLabel1.configure(image=self.newImage1)
    216         self.imageLabel1.image=self.newImage1
    217 
     246
     247            self.newImage=[]
     248            for iimage in range(N_IMAGES):
     249                try:
     250                    self.newImage.append(ImageTk.PhotoImage(Image.open(imageNames[iimage]).resize(ImagesDisplaySize, Image.ANTIALIAS)))
     251                    self.imageLabel[iimage].configure(image=self.newImage[iimage])
     252                    self.imageLabel[iimage].image=self.newImage[iimage]
     253                except:
     254                    print("An error occurred while opening the image: "+imageNames[iimage]+" image "+str(iimage))
     255                time.sleep(0.1)
     256
     257       
    218258        self.getMotorPosition()
    219259        #Check acquisition status
     
    221261        pause_file = glob.glob(FILE_PAUSE)
    222262        if (len(stop_file)):
    223             self.labelAcquisitionStatus.config(text="Stop",bg='red')
     263            self.labelAcquisitionStatus.config(text="Stop",bg='red',fg='black')
    224264            self.buttonAcqPause.config(text="Program stopped!")
    225265        elif (len(pause_file)):
    226             self.labelAcquisitionStatus.config(text="Pause", bg='blue')
     266            self.labelAcquisitionStatus.config(text="Pause", bg='blue',fg='white')
    227267            self.buttonAcqPause.config(text="Restart")
    228268        else:
    229             self.labelAcquisitionStatus.config(text="Enabled", bg='green')
     269            self.labelAcquisitionStatus.config(text="Enabled", bg='green',fg='black')
    230270
    231271        #check remote processes
     
    270310        if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==4):
    271311            try:
    272                 response=subprocess.check_output("ps -edf | grep -v grep | grep -c process_recent_files",shell=True)
     312#                response=subprocess.check_output("ps -edf | grep -v grep | grep -c process_recent_files",shell=True)
     313                response=subprocess.check_output("ps -edf | grep -v grep | grep -c makefile_recent",shell=True)
    273314            except:
    274315                response='0'
     
    283324                self.after(500, self.update_clock)
    284325
    285 
    286 
     326        if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==5):
     327            response=os.system("ping -c 1 "+IP_POWER_IP)
     328            if response==0:
     329                self.labelProcessIPPower.config(bg='green')
     330            else:
     331                self.labelProcessIPPower.config(bg='red')
     332
     333        if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==6):
     334            self.set_power_buttons_color()
     335
     336        if (self.refresh_loop%PROCESSES_REFRESH_INTERVAL==7):
     337            fid=open(FILE_ACQ_INFO,'r')
     338            fileline=fid.readline()
     339            print fileline
     340            key_values={}
     341            while len(fileline)>0:
     342                print fileline
     343                entries=fileline.replace('\n','').split(' ')
     344                key_values[entries[0]]=entries[1]
     345                fileline=fid.readline()
     346            fid.close()
     347            if (key_values['RATE']):
     348                rate_value=36000./float(key_values['RATE'])
     349                self.labelAcquisitionRate.config(text='Rate= '+str(rate_value)+'kS/s',bg='white')
     350           
     351            if (key_values['PAUSE']):
     352                self.labelAcquisitionPause.config(text='Wait= '+key_values['PAUSE']+' ms',bg='white')
     353           
    287354    def getMotorPosition(self):
    288355        if (len(glob.glob(motor_position_info))>0):
     
    291358            key_values={}
    292359            while len(fileline)>0:
    293                 #print fileline
     360                print fileline
    294361                entries=fileline.replace('#','').replace(' ','').replace('\n','').split('=')
    295362                key_values[entries[0]]=entries[1]
     
    298365            if key_values['motor_value']:
    299366                self.labelPositionStep.config(text=key_values['motor_value']);
    300                 self.labelPositionStep.config(bg='green');
    301             else:
    302                 self.labelPositionStep.config(bg='red');
     367                self.labelPositionStep.config(bg='green',fg='black');
     368            else:
     369                self.labelPositionStep.config(bg='red',fg='black');
    303370
    304371            if key_values['current_value']:
    305372                self.labelPositionCurrent.config(text=key_values['current_value']);
    306                 self.labelPositionCurrent.config(bg='green');
    307             else:
    308                 self.labelPositionCurrent.config(bg='red');
     373                self.labelPositionCurrent.config(bg='green',fg='black');
     374            else:
     375                self.labelPositionCurrent.config(bg='red',fg='black');
    309376        else:
    310             self.labelPositionCurrent.config(bg='blue');
    311             self.labelPositionStep.config(bg='blue');
     377            self.labelPositionCurrent.config(bg='blue',fg='white');
     378            self.labelPositionStep.config(bg='blue',fg='white');
     379
     380    def set_power_buttons_color(self):
     381        power_request=urllib2.urlopen(URI+'?CMD=GetPower')
     382        values=power_request.read().replace('<html>','').replace('</html>\r\n','').replace('p6','').split(',')
     383        #            print repr(values)
     384        for ipower in range(4):
     385            print values[ipower].split('=')[1]
     386            if (values[ipower].split('=')[1]=='1'):
     387                self.buttonPower[ipower].config(bg='green')
     388            else:
     389                self.buttonPower[ipower].config(bg='cyan')       
    312390               
    313391    #----------------
     
    360438        self.moveMotor(1,1000000)
    361439
     440    def onButtonPower(self,value):
     441        print('Power value='+str(value))
     442        print(repr(self.buttonPower[value].cget("bg")))
     443        power_state=0
     444        if (self.buttonPower[value].cget("bg")=='green'):
     445            power_state=1
     446        self.buttonPower[value].config(bg='blue')
     447        power_request=urllib2.urlopen(URI+'?CMD=SetPower+P6'+str(value+1)+'='+str(1-power_state))
     448        values=power_request.read().replace('<html>','').replace('</html>\r\n','').replace('p6','').split(',')
     449        self.after(2000, self.set_power_buttons_color)
    362450
    363451    #----------------
Note: See TracChangeset for help on using the changeset viewer.