Skip to content
Snippets Groups Projects
ts2_cav.py 2.51 KiB
Newer Older
import epics
import json
import time
from threading import Thread

class ts2_cavScreen(Thread):
    def __init__(self, stop_signal):
        Thread.__init__(self)
        self.stop_signal = stop_signal

    def run(self):
        pvs = ['TS2-010CRM:Cryo-TE-010:MeasValue', 'TS2-010CRM:Cryo-TE-011:MeasValue', 'TS2-010CRM:Cryo-TE-012:MeasValue', 'TS2-010CRM:Cryo-TE-013:MeasValue', 'TS2-010CRM:Cryo-TE-014:MeasValue', 'TS2-010CRM:Cryo-TE-015:MeasValue', 'TS2-010CRM:Cryo-TE-018:MeasValue', 'TS2-010CRM:Cryo-TE-019:MeasValue', 'TS2-010CRM:Cryo-TE-020:MeasValue', 'TS2-010CRM:Cryo-TE-021:MeasValue', 'TS2-010CRM:Cryo-TE-022:MeasValue', 'TS2-010CRM:Cryo-TE-023:MeasValue', 'TS2-010CRM:Cryo-TE-024:MeasValue', 'TS2-010CRM:Cryo-TE-025:MeasValue', 'TS2-010CRM:Cryo-TE-028:MeasValue', 'TS2-010CRM:Cryo-TE-029:MeasValue', 'TS2-010CRM:Cryo-TE-030:MeasValue', 'TS2-010CRM:Cryo-TE-031:MeasValue', 'TS2-010CRM:Cryo-TE-032:MeasValue', 'TS2-010CRM:Cryo-TE-033:MeasValue', 'TS2-010CRM:Cryo-TE-034:MeasValue', 'TS2-010CRM:Cryo-TE-035:MeasValue', 'TS2-010CRM:Cryo-TE-038:MeasValue', 'TS2-010CRM:Cryo-TE-039:MeasValue', 'TS2-010CRM:Cryo-TE-041:MeasValue', 'TS2-010CRM:Cryo-TE-042:MeasValue', 'TS2-010CRM:Cryo-TE-043:MeasValue', 'TS2-010CRM:Cryo-TE-044:MeasValue', 'TS2-010CRM:Cryo-TE-045:MeasValue', 'TS2-010CRM:Cryo-TE-048:MeasValue', 'TS2-010CRM:Cryo-TE-049:MeasValue' ]

        epics_dict={}
        for pv in pvs:
            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
Emanuele Laface's avatar
Emanuele Laface committed
                    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.'
Emanuele Laface's avatar
Emanuele Laface committed
                    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)
            time.sleep(0.5)
          
        for pv in epics_dict:
            epics_dict[pv].clear_auto_monitor()
            epics_dict[pv].disconnect()