|
@@ -1,71 +1,121 @@
|
|
|
-from PyQt4 import QtGui
|
|
|
-
|
|
|
-
|
|
|
-from ..base import kcgwidget as kcgw
|
|
|
-from ..base.globals import glob as global_objects
|
|
|
-
|
|
|
-__widget_id__ = None
|
|
|
-
|
|
|
-epics_reachable = True
|
|
|
-try: # try to import epics
|
|
|
- import epics
|
|
|
- no_epics = False
|
|
|
-
|
|
|
- os.environ["EPICS_BASE"] = config.epics_base_path
|
|
|
-
|
|
|
- try: # if import was successful, try to find libca and test for connectivity with config.epics_test_pv
|
|
|
- # sys.stderr = os.devnull # epics.ca.find_libca() prints a useless None to stderr if libca is not found
|
|
|
- epics.ca.find_libca()
|
|
|
- # sys.stderr = sys.__stderr__
|
|
|
- if epics.caget(config.epics_test_pv) == None:
|
|
|
- no_epics = True
|
|
|
- epics_reachable = False
|
|
|
- logging.error("Epics is not accessible (possible Timeout)")
|
|
|
-
|
|
|
- except epics.ca.ChannelAccessException as e:
|
|
|
- if str(e) == "cannot find Epics CA DLL":
|
|
|
- no_epics = True
|
|
|
- logging.error("Epics CA DLL not found")
|
|
|
-
|
|
|
-
|
|
|
-except ImportError:
|
|
|
- no_epics = True
|
|
|
-
|
|
|
-class EpicsWidget(kcgw.KCGWidgets):
|
|
|
- def __init__(self, unique_id, parent):
|
|
|
- super(EpicsWidget, self).__init__()
|
|
|
-
|
|
|
- self.id = unique_id
|
|
|
- self.par = parent
|
|
|
-
|
|
|
- self.layout = QtGui.QHBoxLayout()
|
|
|
- self.setLayout(self.layout)
|
|
|
-
|
|
|
- self.button1 = self.createButton("Button 1", connect=self.pressed)
|
|
|
- self.button2 = self.createButton("Button 2", connect=self.pressed)
|
|
|
-
|
|
|
- self.layout.addWidget(self.button1)
|
|
|
- self.layout.addWidget(self.button2)
|
|
|
-
|
|
|
- self.setWindowTitle("Epics Widget")
|
|
|
-
|
|
|
- def pressed(self):
|
|
|
- print('Pressed')
|
|
|
-
|
|
|
- def closeEvent(self, event):
|
|
|
- global __widget_id__
|
|
|
- __widget_id__ = None
|
|
|
- del self.par.widgets[self.id]
|
|
|
-
|
|
|
-
|
|
|
-def addExampleWidget():
|
|
|
- global __widget_id__
|
|
|
- if __widget_id__:
|
|
|
- global_objects.get_global('area').widgets[__widget_id__].setFocus()
|
|
|
- else:
|
|
|
- nid = kcgw.idg.genid()
|
|
|
- __widget_id__ = nid
|
|
|
- w = exampleWidget(nid, global_objects.get_global('area'))
|
|
|
- global_objects.get_global('area').newWidget(w, "Epics Widget", nid, widget_type=4)
|
|
|
-
|
|
|
-kcgw.register_widget(QtGui.QIcon(config.icon_path("sproject.svg")), "Epics Widget", addExampleWidget, "Ctrl+e")
|
|
|
+from PyQt4 import QtGui
|
|
|
+
|
|
|
+
|
|
|
+from ..base import kcgwidget as kcgw
|
|
|
+from ..base.globals import glob as global_objects
|
|
|
+from ..base import log
|
|
|
+from .. import config
|
|
|
+import configparser
|
|
|
+import os
|
|
|
+
|
|
|
+__widget_id__ = None
|
|
|
+
|
|
|
+try: # try to import epics
|
|
|
+ import epics
|
|
|
+ no_epics = False
|
|
|
+except ImportError:
|
|
|
+ no_epics = True
|
|
|
+ logging.error("Python Epics not found")
|
|
|
+
|
|
|
+
|
|
|
+def setup():
|
|
|
+
|
|
|
+ load_config()
|
|
|
+
|
|
|
+ os.environ["EPICS_BASE"] = config.epics_base_path
|
|
|
+ try: # if import was successful, try to find libca and test for connectivity with config.epics_test_pv
|
|
|
+ # sys.stderr = os.devnull # epics.ca.find_libca() prints a useless None to stderr if libca is not found
|
|
|
+ epics.ca.find_libca()
|
|
|
+ # sys.stderr = sys.__stderr__
|
|
|
+ if epics.caget(config.epics_test_pv) == None:
|
|
|
+ no_epics = True
|
|
|
+ epics_reachable = False
|
|
|
+ logging.error("Epics is not accessible (possible Timeout)")
|
|
|
+
|
|
|
+ except epics.ca.ChannelAccessException as e:
|
|
|
+ if str(e) == "cannot find Epics CA DLL":
|
|
|
+ no_epics = True
|
|
|
+ logging.error("Epics CA DLL not found")
|
|
|
+
|
|
|
+ for entry in config.epics_log_entry_pvs:
|
|
|
+ log.logger.predefined_parameters.append([entry[0], [epics.caget, entry[1]]])
|
|
|
+ if entry[2] == "True":
|
|
|
+ log.logger.register_parameter(entry[0], epics.caget, entry[1])
|
|
|
+
|
|
|
+
|
|
|
+def load_config():
|
|
|
+
|
|
|
+ epics_key = ["epics_log_entry_pvs", "epics_test_pv", "epics_base_path"]
|
|
|
+ defaultstring = '[EPICS]\n# These are PVs that will be possible to insert into log files\n# This variable is to be a list consisting of touples of two entries,\n# the first ist the Text that describes the value and the second is the EPICS PV that\n# holds that value\n epics_log_entry_pvs = [\n ("Beam Energy (GeV)", "A:SR:BeamInfo:01:Energy"),\n ("Beam Current (mA)", "A:SR:BeamInfo:01:Current"),\n ("Beam Lifetime (s)", "A:SR:BeamInfo:01:Lifetime"),\n ("Beam Lifetime (H:M:S)", "A:SR:BeamInfo:01:Lifetime:String"),\n ("Injection Rate (mA/s)", "A:SR:BeamInfo:01:InjRate"),\n ("Injection Rate (mA/5s)", "A:SR:BeamInfo:01:InjRate:5s"),\n ("Fill Number", "A:SR:OperationStatus:01:FillNumber")\n ]\n# This pv is used to determine if epics pvs are accessible\n epics_test_pv = "A:SR:BeamInfo:01:Current"\n# Path to your epics base installation\n epics_base_path = "/opt/epics/base/"'
|
|
|
+
|
|
|
+ if not os.path.isfile(os.path.join(os.path.expanduser("~"),".kcg","epics.cfg")):
|
|
|
+ with open(os.path.join(os.path.expanduser("~"),'.kcg','epics.cfg', 'w+')) as f:
|
|
|
+ f.write(defaultstring)
|
|
|
+
|
|
|
+ parser = configparser.ConfigParser()
|
|
|
+ parser.optionxform = str
|
|
|
+ parser.read(os.path.join(os.path.expanduser("~"),".kcg","epics.cfg"))
|
|
|
+
|
|
|
+ c_epics = config.ConfSection('EPICS', epics_key, parser)
|
|
|
+ error = c_epics.read()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 8888888888 d8b 888 888d8b 888 888
|
|
|
+# 888 Y8P 888 o 888Y8P 888 888
|
|
|
+# 888 888 d8b 888 888 888
|
|
|
+# 8888888 88888b. 888 .d8888b.d8888b 888 d888b 888888 .d88888 .d88b. .d88b. 888888
|
|
|
+# 888 888 "88b888d88P" 88K 888d88888b888888d88" 888d88P"88bd8P Y8b888
|
|
|
+# 888 888 888888888 "Y8888b.88888P Y88888888888 888888 88888888888888
|
|
|
+# 888 888 d88P888Y88b. X888888P Y8888888Y88b 888Y88b 888Y8b. Y88b.
|
|
|
+# 888888888888888P" 888 "Y8888P 88888P'888P Y888888 "Y88888 "Y88888 "Y8888 "Y888
|
|
|
+# 888 888
|
|
|
+# 888 Y8b d88P
|
|
|
+# 888 "Y88P"
|
|
|
+#
|
|
|
+
|
|
|
+class EpicsWidget(kcgw.KCGWidgets):
|
|
|
+ def __init__(self, unique_id, parent):
|
|
|
+ super(EpicsWidget, self).__init__()
|
|
|
+
|
|
|
+ self.id = unique_id
|
|
|
+ self.par = parent
|
|
|
+
|
|
|
+ self.layout = QtGui.QHBoxLayout()
|
|
|
+ self.setLayout(self.layout)
|
|
|
+
|
|
|
+ self.button1 = self.createButton("Button 1", connect=self.pressed)
|
|
|
+ self.button2 = self.createButton("Button 2", connect=self.pressed)
|
|
|
+
|
|
|
+ self.layout.addWidget(self.button1)
|
|
|
+ self.layout.addWidget(self.button2)
|
|
|
+
|
|
|
+ self.setWindowTitle("Epics Widget")
|
|
|
+
|
|
|
+ def pressed(self):
|
|
|
+ print('Pressed')
|
|
|
+
|
|
|
+ def closeEvent(self, event):
|
|
|
+ global __widget_id__
|
|
|
+ __widget_id__ = None
|
|
|
+ del self.par.widgets[self.id]
|
|
|
+
|
|
|
+
|
|
|
+def addEpicsWidget():
|
|
|
+ global __widget_id__
|
|
|
+ if __widget_id__:
|
|
|
+ global_objects.get_global('area').widgets[__widget_id__].setFocus()
|
|
|
+ else:
|
|
|
+ nid = kcgw.idg.genid()
|
|
|
+ __widget_id__ = nid
|
|
|
+ w = EpicsWidget(nid, global_objects.get_global('area'))
|
|
|
+ global_objects.get_global('area').newWidget(w, "Epics Widget", nid, widget_type=4)
|
|
|
+
|
|
|
+kcgw.register_widget(QtGui.QIcon(config.icon_path("sproject.svg")), "Epics Widget", addEpicsWidget, "Ctrl+e")
|