diff --git a/PythonServer/pos-python-server.py b/PythonServer/pos-python-server.py index 3cd86dca3e4e0d0d27d4c3592e730a78c986ecf6..115852ed15ae2bf90b81a3127cf159a1b705541d 100755 --- a/PythonServer/pos-python-server.py +++ b/PythonServer/pos-python-server.py @@ -197,7 +197,6 @@ class myHandler(BaseHTTPRequestHandler): self.wfile.write(bytes('The server is running', "utf-8")) return - def on_exit(signum, frame): print(f'Signal handler called with signal {signum}') raise SystemExit("Exiting") @@ -205,18 +204,14 @@ def on_exit(signum, frame): signal.signal(signal.SIGTERM, on_exit) try: - posThread = posScreen(stop_signal) - posThread.start() - interlocksThread = interlocksScreen(stop_signal) - interlocksThread.start() - instrumentsThread = instrumentsScreen(stop_signal) - instrumentsThread.start() - ts2_cavThread = ts2_cavScreen(stop_signal) - ts2_cavThread.start() - ts2_screensThread = ts2_screensScreen(stop_signal) - ts2_screensThread.start() - ts2_tpcircuitsThread = ts2_tpcircuitsScreen(stop_signal) - ts2_tpcircuitsThread.start() + threadList = { 'POS': posScreen(stop_signal), + 'Interlocks': interlocksScreen(stop_signal), + 'Instruments': instrumentsScreen(stop_signal), + 'TS2 Cavities': ts2_cavScreen(stop_signal), + 'TS2 Screens': ts2_screensScreen(stop_signal), + 'TS2 2-Phase Circuits': ts2_tpcircuitsScreen(stop_signal) } + for thread in threadList: + threadList[thread].start() server = HTTPServer(('', PORT_NUMBER), myHandler) print ('Started httpserver on port ' , PORT_NUMBER) diff --git a/PythonServer/screens/example.py b/PythonServer/screens/example.py index c2cf30bbf8780587cf6bc4c75aa81ecd657d8c33..916409fe28ee6cc4f3a85fcfbf123585f7fe7988 100755 --- a/PythonServer/screens/example.py +++ b/PythonServer/screens/example.py @@ -19,43 +19,46 @@ class mybeautifulScreen(Thread): epics_dict[pv]=epics.PV(pv, auto_monitor=True) while(not self.stop_signal.isSet()): - json_dict={} - for pv in epics_dict: - json_dict[pv]={} - if epics_dict[pv].connected: + try: + json_dict={} + for pv in epics_dict: + json_dict[pv]={} + if epics_dict[pv].connected: - # Example of Array - if pv=='PV-ARRAY': # The arrays need a list made by pairs of X,Y - y_data=list(epics_dict[pv].value) - x_data=list(linspace(0,10,len(y_data))) # in this case the X axis will go from 0 to 10 - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue + # Example of Array + if pv=='PV-ARRAY': # The arrays need a list made by pairs of X,Y + y_data=list(epics_dict[pv].value) + x_data=list(linspace(0,10,len(y_data))) # in this case the X axis will go from 0 to 10 + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue - # Example of Image - if pv=='PV-IMAGE': # We need to create the PNG + # Example of Image + if pv=='PV-IMAGE': # We need to create the PNG + try: + imarray = epics_dict[PV-IMAGE].value.reshape(154,206) # From the array I reshape into the size of the image + except: + imarray = zeros((154,206)) # If I don't get the correct data I do a blank image + plt.imsave('/var/www/data/tmp-my_image.png', imarray, cmap='jet') # Save as tmp + os.rename('/var/www/data/tmp-my_image.png', '/var/www/data/my_image.png') # Swap the tmp image with the final one. This trick is used to avoid blinking image in the final page. + + json_dict[pv]['units']=epics_dict[pv].units # I set the units for all the PVs + json_dict[pv]['timestamp']=epics_dict[pv].timestamp # I set the units for all the PVs try: - imarray = epics_dict[PV-IMAGE].value.reshape(154,206) # From the array I reshape into the size of the image + json_dict[pv]['value']=round(epics_dict[pv].value,3) # Where possible I round the value to three decimal digits except: - imarray = zeros((154,206)) # If I don't get the correct data I do a blank image - plt.imsave('/var/www/data/tmp-my_image.png', imarray, cmap='jet') # Save as tmp - os.rename('/var/www/data/tmp-my_image.png', '/var/www/data/my_image.png') # Swap the tmp image with the final one. This trick is used to avoid blinking image in the final page. - - json_dict[pv]['units']=epics_dict[pv].units # I set the units for all the PVs - json_dict[pv]['timestamp']=epics_dict[pv].timestamp # I set the units for all the PVs - try: - json_dict[pv]['value']=round(epics_dict[pv].value,3) # Where possible I round the value to three decimal digits - except: - json_dict[pv]['value']=epics_dict[pv].value - else: - json_dict[pv]['units']='n.c.' # If the PV is disconnected I assign n.c. as unit an blank value - json_dict[pv]['timestamp']='' # If the PV is disconnected I assign n.c. as unit an blank value - json_dict[pv]['value']='' + json_dict[pv]['value']=epics_dict[pv].value + else: + json_dict[pv]['units']='n.c.' # If the PV is disconnected I assign n.c. as unit an blank value + json_dict[pv]['timestamp']='' # If the PV is disconnected I assign n.c. as unit an blank value + json_dict[pv]['value']='' - tmp_json = json.dumps(json_dict) # Create the JSON from dictionary - tmp_json = tmp_json.replace('NaN','0') # Replace the occurences of NaN with 0 - tmp_json = tmp_json.replace('Infinity','0') # Replace the infinities with 0 - with open('/var/www/data/my_file.json','w') as datafile: # Write the final file - datafile.write(tmp_json) + tmp_json = json.dumps(json_dict) # Create the JSON from dictionary + tmp_json = tmp_json.replace('NaN','0') # Replace the occurences of NaN with 0 + tmp_json = tmp_json.replace('Infinity','0') # Replace the infinities with 0 + with open('/var/www/data/my_file.json','w') as datafile: # Write the final file + datafile.write(tmp_json) + except: + continue time.sleep(0.5) # Refresh every half a second for pv in epics_dict: # When the stop signal is set, it cancels all the auto monitor and disconnects diff --git a/PythonServer/screens/instruments.py b/PythonServer/screens/instruments.py index a65dfe845670c3322af74420086b38adad009576..d1878c3e58f93e4cc09376f583b1adf3f08b3151 100755 --- a/PythonServer/screens/instruments.py +++ b/PythonServer/screens/instruments.py @@ -21,176 +21,179 @@ class instrumentsScreen(Thread): while(not self.stop_signal.isSet()): try: - if epics_dict['LEBT-010:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].connected: - imarray = epics_dict['LEBT-010:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].value.reshape(154,206) - else: + try: + if epics_dict['LEBT-010:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].connected: + imarray = epics_dict['LEBT-010:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].value.reshape(154,206) + else: + imarray = zeros((154,206)) + except: imarray = zeros((154,206)) - except: - imarray = zeros((154,206)) - plt.imsave('/var/www/data/tmp-npm-vimage.png', imarray, cmap='jet') - os.rename('/var/www/data/tmp-npm-vimage.png', '/var/www/data/npm-vimage.png') - - try: - if epics_dict['LEBT-010:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].connected: - imarray = epics_dict['LEBT-010:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].value.reshape(154,206) - else: + plt.imsave('/var/www/data/tmp-npm-vimage.png', imarray, cmap='jet') + os.rename('/var/www/data/tmp-npm-vimage.png', '/var/www/data/npm-vimage.png') + + try: + if epics_dict['LEBT-010:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].connected: + imarray = epics_dict['LEBT-010:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].value.reshape(154,206) + else: + imarray = zeros((154,206)) + except: imarray = zeros((154,206)) - except: - imarray = zeros((154,206)) - plt.imsave('/var/www/data/tmp-npm-himage.png', imarray, cmap='jet') - os.rename('/var/www/data/tmp-npm-himage.png', '/var/www/data/npm-himage.png') - - try: - if epics_dict['LEBT-020:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].connected: - imarray = epics_dict['LEBT-020:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].value.reshape(154,206) - else: + plt.imsave('/var/www/data/tmp-npm-himage.png', imarray, cmap='jet') + os.rename('/var/www/data/tmp-npm-himage.png', '/var/www/data/npm-himage.png') + + try: + if epics_dict['LEBT-020:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].connected: + imarray = epics_dict['LEBT-020:PBI-NPM-002:VCAMSLOWIMG-ArrayData'].value.reshape(154,206) + else: + imarray = zeros((154,206)) + except: imarray = zeros((154,206)) - except: - imarray = zeros((154,206)) - plt.imsave('/var/www/data/tmp-npm-commissioning-vimage.png', imarray, cmap='jet') - os.rename('/var/www/data/tmp-npm-commissioning-vimage.png', '/var/www/data/npm-commissioning-vimage.png') - - try: - if epics_dict['LEBT-020:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].connected: - imarray = epics_dict['LEBT-020:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].value.reshape(154,206) - else: + plt.imsave('/var/www/data/tmp-npm-commissioning-vimage.png', imarray, cmap='jet') + os.rename('/var/www/data/tmp-npm-commissioning-vimage.png', '/var/www/data/npm-commissioning-vimage.png') + + try: + if epics_dict['LEBT-020:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].connected: + imarray = epics_dict['LEBT-020:PBI-NPM-001:HCAMSLOWIMG-ArrayData'].value.reshape(154,206) + else: + imarray = zeros((154,206)) + except: imarray = zeros((154,206)) - except: - imarray = zeros((154,206)) - plt.imsave('/var/www/data/tmp-npm-commissioning-himage.png', imarray, cmap='jet') - os.rename('/var/www/data/tmp-npm-commissioning-himage.png', '/var/www/data/npm-commissioning-himage.png') - - try: - if epics_dict['LNS-ISRC-010:PBI-EMV:BUFF-CURRENT'].connected: - pos = epics_dict['LNS-ISRC-010:PBI-EMV:MTR.NPTS'].value - ang = epics_dict['LNS-ISRC-010:PBI-EMV:PS.NPTS'].value - imarray = (epics_dict['LNS-ISRC-010:PBI-EMV:BUFF-CURRENT'].value)[:pos*ang].reshape((ang,pos)) - imarray=(imarray*255) - else: + plt.imsave('/var/www/data/tmp-npm-commissioning-himage.png', imarray, cmap='jet') + os.rename('/var/www/data/tmp-npm-commissioning-himage.png', '/var/www/data/npm-commissioning-himage.png') + + try: + if epics_dict['LNS-ISRC-010:PBI-EMV:BUFF-CURRENT'].connected: + pos = epics_dict['LNS-ISRC-010:PBI-EMV:MTR.NPTS'].value + ang = epics_dict['LNS-ISRC-010:PBI-EMV:PS.NPTS'].value + imarray = (epics_dict['LNS-ISRC-010:PBI-EMV:BUFF-CURRENT'].value)[:pos*ang].reshape((ang,pos)) + imarray=(imarray*255) + else: + imarray = zeros((200,200)) + except: imarray = zeros((200,200)) - except: - imarray = zeros((200,200)) - plt.imsave('/var/www/data/tmp-emu-vimage.png', imarray, cmap='jet') - os.rename('/var/www/data/tmp-emu-vimage.png', '/var/www/data/emu-vimage.png') - - try: - if epics_dict['LNS-ISRC-010:PBI-EMH:BUFF-CURRENT'].connected: - pos = epics_dict['LNS-ISRC-010:PBI-EMH:MTR.NPTS'].value - ang = epics_dict['LNS-ISRC-010:PBI-EMH:PS.NPTS'].value - imarray = (epics_dict['LNS-ISRC-010:PBI-EMH:BUFF-CURRENT'].value)[:pos*ang].reshape((ang,pos)) - imarray=(imarray*255) - else: + plt.imsave('/var/www/data/tmp-emu-vimage.png', imarray, cmap='jet') + os.rename('/var/www/data/tmp-emu-vimage.png', '/var/www/data/emu-vimage.png') + + try: + if epics_dict['LNS-ISRC-010:PBI-EMH:BUFF-CURRENT'].connected: + pos = epics_dict['LNS-ISRC-010:PBI-EMH:MTR.NPTS'].value + ang = epics_dict['LNS-ISRC-010:PBI-EMH:PS.NPTS'].value + imarray = (epics_dict['LNS-ISRC-010:PBI-EMH:BUFF-CURRENT'].value)[:pos*ang].reshape((ang,pos)) + imarray=(imarray*255) + else: + imarray = zeros((200,200)) + except: imarray = zeros((200,200)) - except: - imarray = zeros((200,200)) - plt.imsave('/var/www/data/tmp-emu-himage.png', imarray, cmap='jet') - os.rename('/var/www/data/tmp-emu-himage.png', '/var/www/data/emu-himage.png') - - json_dict={} - for pv in epics_dict: - json_dict[pv]={} - if epics_dict[pv].connected: - json_dict[pv]['units']=epics_dict[pv].units - json_dict[pv]['timestamp']=epics_dict[pv].timestamp - if pv=='ISrc-010:PBI-BCM-001:AI4-Compressed': - y_data=list(epics_dict[pv].value*bcm_correction) - x_data=list(linspace(0,12.8,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-010:PBI-BCM-001:AI5-Compressed': - y_data=list(epics_dict[pv].value) - x_data=list(linspace(0,12.8,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-020:PBI-FC-001:AMC31-AOI11-ArrayDataComp': - fc_resizer = int(len(publicpvs[pv].value)/200) - y_data=list(epics_dict[pv].value[::fc_resizer]) - x_data=list(linspace(0,10,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-010:PBI-NPM-001:HCAMFITS-Y_RBV': - y_data=list(epics_dict[pv].value) - x_size=len(y_data)*epics_dict['LEBT-010:PBI-NPM-001:HCAM-SCALEFACT'].value/1000 - x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-010:PBI-NPM-002:VCAMFITS-Y_RBV': - y_data=list(epics_dict[pv].value) - x_size=len(y_data)*epics_dict['LEBT-010:PBI-NPM-002:VCAM-SCALEFACT'].value/1000 - x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-020:PBI-NPM-001:HCAMFITS-Y_RBV': - y_data=list(epics_dict[pv].value) - x_size=len(y_data)*epics_dict['LEBT-020:PBI-NPM-001:HCAM-SCALEFACT'].value/1000 - x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-020:PBI-NPM-002:VCAMFITS-Y_RBV': - y_data=list(epics_dict[pv].value) - x_size=len(y_data)*epics_dict['LEBT-020:PBI-NPM-002:VCAM-SCALEFACT'].value/1000 - x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-010:PBI-NPM-001:HCAM-SCALEFACT': - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' - continue - if pv=='LEBT-010:PBI-NPM-002:VCAM-SCALEFACT': - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' - continue - if pv=='LEBT-020:PBI-NPM-001:HCAM-SCALEFACT': - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' - continue - if pv=='LEBT-020:PBI-NPM-002:VCAM-SCALEFACT': + plt.imsave('/var/www/data/tmp-emu-himage.png', imarray, cmap='jet') + os.rename('/var/www/data/tmp-emu-himage.png', '/var/www/data/emu-himage.png') + + json_dict={} + for pv in epics_dict: + json_dict[pv]={} + if epics_dict[pv].connected: + json_dict[pv]['units']=epics_dict[pv].units + json_dict[pv]['timestamp']=epics_dict[pv].timestamp + if pv=='ISrc-010:PBI-BCM-001:AI4-Compressed': + y_data=list(epics_dict[pv].value*bcm_correction) + x_data=list(linspace(0,12.8,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-010:PBI-BCM-001:AI5-Compressed': + y_data=list(epics_dict[pv].value) + x_data=list(linspace(0,12.8,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-020:PBI-FC-001:AMC31-AOI11-ArrayDataComp': + fc_resizer = int(len(publicpvs[pv].value)/200) + y_data=list(epics_dict[pv].value[::fc_resizer]) + x_data=list(linspace(0,10,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-010:PBI-NPM-001:HCAMFITS-Y_RBV': + y_data=list(epics_dict[pv].value) + x_size=len(y_data)*epics_dict['LEBT-010:PBI-NPM-001:HCAM-SCALEFACT'].value/1000 + x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-010:PBI-NPM-002:VCAMFITS-Y_RBV': + y_data=list(epics_dict[pv].value) + x_size=len(y_data)*epics_dict['LEBT-010:PBI-NPM-002:VCAM-SCALEFACT'].value/1000 + x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-020:PBI-NPM-001:HCAMFITS-Y_RBV': + y_data=list(epics_dict[pv].value) + x_size=len(y_data)*epics_dict['LEBT-020:PBI-NPM-001:HCAM-SCALEFACT'].value/1000 + x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-020:PBI-NPM-002:VCAMFITS-Y_RBV': + y_data=list(epics_dict[pv].value) + x_size=len(y_data)*epics_dict['LEBT-020:PBI-NPM-002:VCAM-SCALEFACT'].value/1000 + x_data=list(linspace(-x_size/2,x_size/2,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-010:PBI-NPM-001:HCAM-SCALEFACT': + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' + continue + if pv=='LEBT-010:PBI-NPM-002:VCAM-SCALEFACT': + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' + continue + if pv=='LEBT-020:PBI-NPM-001:HCAM-SCALEFACT': + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' + continue + if pv=='LEBT-020:PBI-NPM-002:VCAM-SCALEFACT': + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' + continue + + try: + if epics_dict['LEBT-010:PBI-Dpl-001:IMG1-ArrayData'].connected: + start_image = epics_dict['LEBT-010:PBI-Dpl-001:ROI1-MinX'].value + end_image = start_image + epics_dict['LEBT-010:PBI-Dpl-001:ROI1-SizeX'].value + imarray = tile(epics_dict['LEBT-010:PBI-Dpl-001:IMG1-ArrayData'].value[start_image:end_image], (256,1)) + else: + imarray = zeros((256,512)) + except: + imarray = zeros((256,512)) + plt.imsave('/var/www/data/tmp-dpl.png', imarray, cmap='hot') + os.rename('/var/www/data/tmp-dpl.png', '/var/www/data/dpl.png') + + if pv=='LEBT-010:PBI-Dpl-001:FIT1-Y_RBV': + y_data=list(epics_dict[pv].value) + pixel2lambda=(epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MaxWavelength'].value-epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MinWavelength'].value)/1024 + start_wave = epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MinWavelength'].value + epics_dict['LEBT-010:PBI-Dpl-001:ROI1-MinX'].value*pixel2lambda + end_wave = epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MinWavelength'].value + (epics_dict['LEBT-010:PBI-Dpl-001:ROI1-MinX'].value+epics_dict['LEBT-010:PBI-Dpl-001:ROI1-SizeX'].value)*pixel2lambda + x_data=list(linspace(start_wave, end_wave, len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + + if epics_dict[pv].count>1 or epics_dict[pv].count==0: + continue + try: + json_dict[pv]['value']=round(epics_dict[pv].value,3) + except: + json_dict[pv]['value']=epics_dict[pv].value + else: json_dict[pv]['units']='n.c.' json_dict[pv]['timestamp']='' json_dict[pv]['value']='' - continue - - try: - if epics_dict['LEBT-010:PBI-Dpl-001:IMG1-ArrayData'].connected: - start_image = epics_dict['LEBT-010:PBI-Dpl-001:ROI1-MinX'].value - end_image = start_image + epics_dict['LEBT-010:PBI-Dpl-001:ROI1-SizeX'].value - imarray = tile(epics_dict['LEBT-010:PBI-Dpl-001:IMG1-ArrayData'].value[start_image:end_image], (256,1)) - else: - imarray = zeros((256,512)) - except: - imarray = zeros((256,512)) - plt.imsave('/var/www/data/tmp-dpl.png', imarray, cmap='hot') - os.rename('/var/www/data/tmp-dpl.png', '/var/www/data/dpl.png') - - if pv=='LEBT-010:PBI-Dpl-001:FIT1-Y_RBV': - y_data=list(epics_dict[pv].value) - pixel2lambda=(epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MaxWavelength'].value-epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MinWavelength'].value)/1024 - start_wave = epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MinWavelength'].value + epics_dict['LEBT-010:PBI-Dpl-001:ROI1-MinX'].value*pixel2lambda - end_wave = epics_dict['LEBT-010:PBI-Dpl-001:SPECT-MinWavelength'].value + (epics_dict['LEBT-010:PBI-Dpl-001:ROI1-MinX'].value+epics_dict['LEBT-010:PBI-Dpl-001:ROI1-SizeX'].value)*pixel2lambda - x_data=list(linspace(start_wave, end_wave, len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - - if epics_dict[pv].count>1 or epics_dict[pv].count==0: - continue - try: - json_dict[pv]['value']=round(epics_dict[pv].value,3) - except: - json_dict[pv]['value']=epics_dict[pv].value - else: - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' - - tmp_json = json.dumps(json_dict) - tmp_json = tmp_json.replace('NaN','0') - tmp_json = tmp_json.replace('Infinity','0') - with open('/var/www/data/instruments.json','w') as datafile: - datafile.write(tmp_json) + + tmp_json = json.dumps(json_dict) + tmp_json = tmp_json.replace('NaN','0') + tmp_json = tmp_json.replace('Infinity','0') + with open('/var/www/data/instruments.json','w') as datafile: + datafile.write(tmp_json) + except: + continue time.sleep(0.5) for pv in epics_dict: diff --git a/PythonServer/screens/interlocks.py b/PythonServer/screens/interlocks.py index fede35cb3de6b68123d6e9fe047ea06f3b753da8..82da388b720b751ec11f3a441033db59060616fb 100755 --- a/PythonServer/screens/interlocks.py +++ b/PythonServer/screens/interlocks.py @@ -16,26 +16,29 @@ class interlocksScreen(Thread): epics_dict[pv]=epics.PV(pv, auto_monitor=True) while(not self.stop_signal.isSet()): - json_dict={} - for pv in epics_dict: - json_dict[pv]={} - if epics_dict[pv].connected: - json_dict[pv]['units']=epics_dict[pv].units - json_dict[pv]['timestamp']=epics_dict[pv].timestamp - try: - json_dict[pv]['value']=round(epics_dict[pv].value,3) - except: - json_dict[pv]['value']=epics_dict[pv].value - else: - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' + try: + json_dict={} + for pv in epics_dict: + json_dict[pv]={} + if epics_dict[pv].connected: + json_dict[pv]['units']=epics_dict[pv].units + json_dict[pv]['timestamp']=epics_dict[pv].timestamp + try: + json_dict[pv]['value']=round(epics_dict[pv].value,3) + except: + json_dict[pv]['value']=epics_dict[pv].value + else: + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' - tmp_json = json.dumps(json_dict) - tmp_json = tmp_json.replace('NaN','0') - tmp_json = tmp_json.replace('Infinity','0') - with open('/var/www/data/interlocks.json','w') as datafile: - datafile.write(tmp_json) + tmp_json = json.dumps(json_dict) + tmp_json = tmp_json.replace('NaN','0') + tmp_json = tmp_json.replace('Infinity','0') + with open('/var/www/data/interlocks.json','w') as datafile: + datafile.write(tmp_json) + except: + continue time.sleep(0.5) for pv in epics_dict: diff --git a/PythonServer/screens/pos.py b/PythonServer/screens/pos.py index 62d32cd13bc75b99666de93fcd4f557687eec9d3..765b5c7cb36ee6722ae2b1758b71244921694ee8 100755 --- a/PythonServer/screens/pos.py +++ b/PythonServer/screens/pos.py @@ -17,66 +17,69 @@ class posScreen(Thread): epics_dict[pv]=epics.PV(pv, auto_monitor=True) while(not self.stop_signal.isSet()): - json_dict={} - for pv in epics_dict: - json_dict[pv]={} - if epics_dict[pv].connected: - json_dict[pv]['units']=epics_dict[pv].units - json_dict[pv]['timestamp']=epics_dict[pv].timestamp - if pv=='ISrc-010:PBI-BCM-001:AI4-Compressed': - y_data_array=epics_dict[pv].value - y_data=list(y_data_array) - x_data_array=linspace(0,12.8,len(y_data)) - x_data=list(x_data_array) - json_dict[pv]['value']=list(zip(x_data,y_data)) - json_dict['pulse']={} - json_dict['max_curr']={} - json_dict['pulse']['units']='ms' - json_dict['max_curr']['units']='mA' - if y_data_array.max()<1: - json_dict['beam']=2 - json_dict['pulse']['value']='0' - json_dict['max_curr']['value']='0' - else: - threshold=max(y_data_array)*0.25 - json_dict['pulse']['value']=round(x_data_array[y_data_array>threshold].max()-x_data_array[y_data_array>threshold].min(),2) - json_dict['max_curr']['value']=round(max(y_data_array),2) - if epics_dict['ISrc-010:ISS-Magtr:Setup.B6'].value and epics_dict['ISrc-010:ISS-HVPS:PwrR'].value: - json_dict['beam']=0 - else: - json_dict['beam']=1 - continue - if pv=='LEBT-010:PBI-BCM-001:AI5-Compressed': - y_data=list(epics_dict[pv].value) - x_data=list(linspace(0,12.8,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - if pv=='LEBT-020:PBI-FC-001:AMC31-AOI11-ArrayDataComp': - fc_resizer = int(len(epics_dict[pv].value)/200) - y_data=list(epics_dict[pv].value[::fc_resizer]) - x_data=list(linspace(0,10,len(y_data))) - json_dict[pv]['value']=list(zip(x_data,y_data)) - continue - try: - json_dict[pv]['value']=round(epics_dict[pv].value,3) - except: - json_dict[pv]['value']=epics_dict[pv].value - else: - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' try: - json_dict['ISrc-010:TS-EVG-01:Mxc1-Frequency-RB']['value']=int(json_dict['ISrc-010:TS-EVG-01:Mxc1-Frequency-RB']['value']) - json_dict['ISrc-010:ISS-EVR-Magtr:Pul0-Width-RB']['value']=int(json_dict['ISrc-010:ISS-EVR-Magtr:Pul0-Width-RB']['value']) - except: - json_dict['ISrc-010:TS-EVG-01:Mxc1-Frequency-RB']['value']='' - json_dict['ISrc-010:ISS-EVR-Magtr:Pul0-Width-RB']['value']='' + json_dict={} + for pv in epics_dict: + json_dict[pv]={} + if epics_dict[pv].connected: + json_dict[pv]['units']=epics_dict[pv].units + json_dict[pv]['timestamp']=epics_dict[pv].timestamp + if pv=='ISrc-010:PBI-BCM-001:AI4-Compressed': + y_data_array=epics_dict[pv].value + y_data=list(y_data_array) + x_data_array=linspace(0,12.8,len(y_data)) + x_data=list(x_data_array) + json_dict[pv]['value']=list(zip(x_data,y_data)) + json_dict['pulse']={} + json_dict['max_curr']={} + json_dict['pulse']['units']='ms' + json_dict['max_curr']['units']='mA' + if y_data_array.max()<1: + json_dict['beam']=2 + json_dict['pulse']['value']='0' + json_dict['max_curr']['value']='0' + else: + threshold=max(y_data_array)*0.25 + json_dict['pulse']['value']=round(x_data_array[y_data_array>threshold].max()-x_data_array[y_data_array>threshold].min(),2) + json_dict['max_curr']['value']=round(max(y_data_array),2) + if epics_dict['ISrc-010:ISS-Magtr:Setup.B6'].value and epics_dict['ISrc-010:ISS-HVPS:PwrR'].value: + json_dict['beam']=0 + else: + json_dict['beam']=1 + continue + if pv=='LEBT-010:PBI-BCM-001:AI5-Compressed': + y_data=list(epics_dict[pv].value) + x_data=list(linspace(0,12.8,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + if pv=='LEBT-020:PBI-FC-001:AMC31-AOI11-ArrayDataComp': + fc_resizer = int(len(epics_dict[pv].value)/200) + y_data=list(epics_dict[pv].value[::fc_resizer]) + x_data=list(linspace(0,10,len(y_data))) + json_dict[pv]['value']=list(zip(x_data,y_data)) + continue + try: + json_dict[pv]['value']=round(epics_dict[pv].value,3) + except: + json_dict[pv]['value']=epics_dict[pv].value + else: + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' + try: + json_dict['ISrc-010:TS-EVG-01:Mxc1-Frequency-RB']['value']=int(json_dict['ISrc-010:TS-EVG-01:Mxc1-Frequency-RB']['value']) + json_dict['ISrc-010:ISS-EVR-Magtr:Pul0-Width-RB']['value']=int(json_dict['ISrc-010:ISS-EVR-Magtr:Pul0-Width-RB']['value']) + except: + json_dict['ISrc-010:TS-EVG-01:Mxc1-Frequency-RB']['value']='' + json_dict['ISrc-010:ISS-EVR-Magtr:Pul0-Width-RB']['value']='' - tmp_json = json.dumps(json_dict) - tmp_json = tmp_json.replace('NaN','0') - tmp_json = tmp_json.replace('Infinity','0') - with open('/var/www/data/pos.json','w') as datafile: - datafile.write(tmp_json) + tmp_json = json.dumps(json_dict) + tmp_json = tmp_json.replace('NaN','0') + tmp_json = tmp_json.replace('Infinity','0') + with open('/var/www/data/pos.json','w') as datafile: + datafile.write(tmp_json) + except: + continue time.sleep(0.5) for pv in epics_dict: diff --git a/PythonServer/screens/ts2_cav.py b/PythonServer/screens/ts2_cav.py index 5cb073544f88d1f3ebb094038351502536c47aac..88e6e1fff968d7ebaefe324372f11eb7af18751a 100755 --- a/PythonServer/screens/ts2_cav.py +++ b/PythonServer/screens/ts2_cav.py @@ -16,26 +16,30 @@ class ts2_cavScreen(Thread): epics_dict[pv]=epics.PV(pv, auto_monitor=True) while(not self.stop_signal.isSet()): - json_dict={} - for pv in epics_dict: - json_dict[pv]={} - if epics_dict[pv].connected: - json_dict[pv]['units']=epics_dict[pv].units - json_dict[pv]['timestamp']=epics_dict[pv].timestamp - try: - json_dict[pv]['value']=round(epics_dict[pv].value,3) - except: - json_dict[pv]['value']=epics_dict[pv].value - else: - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' - - tmp_json = json.dumps(json_dict) - tmp_json = tmp_json.replace('NaN','0') - tmp_json = tmp_json.replace('Infinity','0') - with open('/var/www/data/ts2_cav.json','w') as datafile: - datafile.write(tmp_json) + try: + json_dict={} + for pv in epics_dict: + json_dict[pv]={} + if epics_dict[pv].connected: + json_dict[pv]['units']=epics_dict[pv].units + json_dict[pv]['timestamp']=epics_dict[pv].timestamp + try: + json_dict[pv]['value']=round(epics_dict[pv].value,3) + except: + json_dict[pv]['value']=epics_dict[pv].value + else: + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' + + tmp_json = json.dumps(json_dict) + tmp_json = tmp_json.replace('NaN','0') + tmp_json = tmp_json.replace('Infinity','0') + with open('/var/www/data/ts2_cav.json','w') as datafile: + datafile.write(tmp_json) + + except: + continue time.sleep(0.5) for pv in epics_dict: diff --git a/PythonServer/screens/ts2_screens.py b/PythonServer/screens/ts2_screens.py index f8496acbf5c0df07ea6871581e419254933ab06a..6850c93ec80890999c8439c0216dd69a08aca236 100755 --- a/PythonServer/screens/ts2_screens.py +++ b/PythonServer/screens/ts2_screens.py @@ -16,26 +16,29 @@ class ts2_screensScreen(Thread): epics_dict[pv]=epics.PV(pv, auto_monitor=True) while(not self.stop_signal.isSet()): - json_dict={} - for pv in epics_dict: - json_dict[pv]={} - if epics_dict[pv].connected: - json_dict[pv]['units']=epics_dict[pv].units - json_dict[pv]['timestamp']=epics_dict[pv].timestamp - try: - json_dict[pv]['value']=round(epics_dict[pv].value,3) - except: - json_dict[pv]['value']=epics_dict[pv].value - else: - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' + try: + json_dict={} + for pv in epics_dict: + json_dict[pv]={} + if epics_dict[pv].connected: + json_dict[pv]['units']=epics_dict[pv].units + json_dict[pv]['timestamp']=epics_dict[pv].timestamp + try: + json_dict[pv]['value']=round(epics_dict[pv].value,3) + except: + json_dict[pv]['value']=epics_dict[pv].value + else: + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' - tmp_json = json.dumps(json_dict) - tmp_json = tmp_json.replace('NaN','0') - tmp_json = tmp_json.replace('Infinity','0') - with open('/var/www/data/ts2_screens.json','w') as datafile: - datafile.write(tmp_json) + tmp_json = json.dumps(json_dict) + tmp_json = tmp_json.replace('NaN','0') + tmp_json = tmp_json.replace('Infinity','0') + with open('/var/www/data/ts2_screens.json','w') as datafile: + datafile.write(tmp_json) + except: + continue time.sleep(0.5) for pv in epics_dict: diff --git a/PythonServer/screens/ts2_tpcircuits.py b/PythonServer/screens/ts2_tpcircuits.py index d6fc49daf6b777525e1e1db5dc53fe7ced4695d7..61d1bb92a42404400e5f0d60096b10db963834fd 100755 --- a/PythonServer/screens/ts2_tpcircuits.py +++ b/PythonServer/screens/ts2_tpcircuits.py @@ -16,26 +16,29 @@ class ts2_tpcircuitsScreen(Thread): epics_dict[pv]=epics.PV(pv, auto_monitor=True) while(not self.stop_signal.isSet()): - json_dict={} - for pv in epics_dict: - json_dict[pv]={} - if epics_dict[pv].connected: - json_dict[pv]['units']=epics_dict[pv].units - json_dict[pv]['timestamp']=epics_dict[pv].timestamp - try: - json_dict[pv]['value']=round(epics_dict[pv].value,3) - except: - json_dict[pv]['value']=epics_dict[pv].value - else: - json_dict[pv]['units']='n.c.' - json_dict[pv]['timestamp']='' - json_dict[pv]['value']='' + try: + json_dict={} + for pv in epics_dict: + json_dict[pv]={} + if epics_dict[pv].connected: + json_dict[pv]['units']=epics_dict[pv].units + json_dict[pv]['timestamp']=epics_dict[pv].timestamp + try: + json_dict[pv]['value']=round(epics_dict[pv].value,3) + except: + json_dict[pv]['value']=epics_dict[pv].value + else: + json_dict[pv]['units']='n.c.' + json_dict[pv]['timestamp']='' + json_dict[pv]['value']='' - tmp_json = json.dumps(json_dict) - tmp_json = tmp_json.replace('NaN','0') - tmp_json = tmp_json.replace('Infinity','0') - with open('/var/www/data/ts2_tpcircuits.json','w') as datafile: - datafile.write(tmp_json) + tmp_json = json.dumps(json_dict) + tmp_json = tmp_json.replace('NaN','0') + tmp_json = tmp_json.replace('Infinity','0') + with open('/var/www/data/ts2_tpcircuits.json','w') as datafile: + datafile.write(tmp_json) + except: + continue time.sleep(0.5) for pv in epics_dict: