def _load(self, ramp_image): if ramp_image.image == None or self.pv_name == None: return None if __debug__ == True: print( "I am going to write the stepping binary image to PV: {0}...". format(self.pv_name)) if _NO_CATOOLS_ == True: print("...but I see no catools module imported.") print("Image: ", ramp_image.image) print("Image len, bytes:", len(ramp_image.image)) if _NO_CATOOLS_ == True: return None try: connect(self.pv_name, throw=False) caput(self.pv_name, ramp_image.image, wait=True) except: if __debug__ == True: print("My write to CA has failed.") return None return 0
def __init__(self, parent=None): QObject.__init__(self, parent) self.extractMask = 0 # 0 - no mask, 1 - mask self.extractStatus = 0 self.extractRequest = 0 # 0 - idle, 1 - requested self.eventCount = 0 # incrementing when cycle end. self.startSrc = 0 # source of starting signals self.pvs_connect = [ "V5:SYN:XFER:SwitchC", "V5:SYN:XFER:MaskC.B0", "V5:SYN:XFER:StartC.PROC", "V5:SYN:XFER:StopC.PROC" ] catools.connect(self.pvs_connect) catools.camonitor("V5:SYN:XFER:EventM", self.eventUpdate, datatype=int) catools.camonitor("V5:SYN:XFER:StatusRbv", self.statusUpdate, datatype=int) catools.camonitor("V5:SYN:XFER:MaskC.RBV", self.maskUpdate, datatype=int) catools.camonitor("V5:SYN:XFER:SwitchC", self.startSrcUpdate, datatype=int)
def setConnection(self): connected = False for i in range(RECONNECT_ATTEMPTS): try: catools.connect(self.pv) if self.direction == "mp": if self.datatype == "wfint": self.client.subscribe(self.chan + "#") else: self.client.subscribe(self.chan) elif self.direction == "pm": self.thread.start() camonitor(self.pv, self.pushValue) logger.info("(%s, %s) connection set" % (self.pv, self.chan)) connected = True break except Exception as e: logger.error("Trouble with connection to " + self.pv + " or " + self.chan + ": " + str(e)) logger.debug(traceback.format_exc()) #cothread.Quit() continue if not connected: logger.error("Unable to connect to " + self.pv + " or " + self.chan + ", giving up")
def setPV(self, PV): self._pv = PV try: connect(PV, wait=True, cainfo=True) except: logInstance.logger.error('Process Variable ' + str(PV) + ' not connected') print ('Process Variable ' + str(PV) + ' not connected')
def setConnection(self): try: catools.connect(self.pv) if self.direction == "mp": if self.datatype == "wfint": self.client.subscribe(self.chan + "#") else: self.client.subscribe(self.chan) elif self.direction == "pm": camonitor(self.pv, self.updateChan) print(self.chan + " connection set") except Exception as e: print("Trouble with connection:\n" + traceback.format_exc())
def config(name,geometry,engine,tag,author): diff=Diffractometer(name, geometry, engine, tag, author) diff.pvList=pvList diff.dummySetup(name, geometry, engine, tag, author) i=0 for angle in diff.getangleList(): angle.setPV(pvList[i]) try: caget(pvList[i],timeout=1.5) except: raise RuntimeWarning('Unable to connect'+pvList[i]) diff.logger.warning('Unable to connect'+pvList[i]) connect(pvList[i],wait=False,cainfo=True) i+=1 return diff
def assignPV(name, pv): angList = diff.getangleList() pvDict = dict() for angle in angList: pvDict[angle.getName()] = angle.getPV() if pvDict.has_key(name): if connect(pv, wait=False, cainfo=True).state == 2: if pv not in diff.getPVList(): for entry in angList: if entry.getName() == name: entry.setPV(pv) else: for entry in angList: if entry.getPV() == pv: angle1 = entry if entry.getName() == name: angle2 = entry temp = angle2.getPV() angle2.setPV(pv) angle1.setPV(temp) else: logInstance.logger.warning('PV does not exist or it is not live') raise Exception('PV does not exist or it is not live') else: logInstance.logger.warning('Angle does not exist')
def _get_mac_address(self): pv = ".X" # Pick a PV that is hosted on the device node = connect(self.epicsID + pv, cainfo=True).host.split(":")[0] # Get the IP address of the host host_info = Popen(["arp", "-n", node], stdout=PIPE).communicate()[0] # Get info about the host using arp host_info = host_info.split("\n")[1] # Split the info sent back index = host_info.find(":") # Find the first ":", used in the MAC address host_info = host_info[index - 2:index + 15] # Get the MAC address return host_info
def connect(pvs, cainfo=False, wait=True, timeout=5, throw=True): """ Convenience function that wraps the cothread.catools.connect() function with safe handling of unicode strings in Python 2.X. """ # The argument 'cainfo' redefines module function # pylint: disable=redefined-outer-name return catools.connect(_to_str(pvs), cainfo=cainfo, wait=wait, timeout=timeout, throw=throw)
def updateTable(self): #def callback(self, value, index): #while(True): #if self.startUpdate: disConnectedPVs = [] connectedPVs = [] self.table.clear() self.table.setHorizontalHeaderLabels(self.keys) self.table.setSortingEnabled(False) #print("update table:") #print(self.allPVList) #cothread.Sleep(2) connnectionStatus = connect(self.allPVList, cainfo=True, wait=False, timeout=2, throw=False) for status in connnectionStatus: if status.ok != True: disConnectedPVs.append(status.name) else: connectedPVs.append(status.name) if len(disConnectedPVs) > 0: print("%d PVs seem disconnected: \n"%len(disConnectedPVs)) print(disConnectedPVs) self.label.setText("%d PVs in the original snapshot, but only %d pairs of setpoint &\ readback in this table because some PVs don't have readbacks or they are disconnected\n\nPlease click the \ button below to update data\n"%(self.rowCount,len(connectedPVs))) self.allPVList = connectedPVs try: pvValues = caget(self.allPVList) except: print("Oops: can't get PV values to verify setpoint and readback") self.label.setText("Oops: can't get PV values to verify setpoint and readback\n\n") traceback.print_exc() return #print(pvValues) for i in range(int(len(self.allPVList)/self.pvListColumn)): self.__setTableItem(self.table, i, 0, str(self.allPVList[i]))#setpoint PV name self.__setTableItem(self.table, i, 1, str(self.allPVList[i+int(len(self.allPVList)/self.pvListColumn)])) self.__setTableItem(self.table, i, 2, str(pvValues[i])) self.__setTableItem(self.table, i, 3, str(pvValues[i+int(len(self.allPVList)/self.pvListColumn)])) diff_ = abs(pvValues[i] - pvValues[i+int(len(self.allPVList)/self.pvListColumn)]) diff = diff_.__format__('.9f') self.__setTableItem(self.table, i, 4, str(diff)) self.__setTableItem(self.table, i, 5, str(pvValues[i+int((self.pvListColumn-1)*len(self.allPVList)/self.pvListColumn)])) #self.table.resize(self.table.sizeHint()) self.table.setSortingEnabled(True) self.table.sortItems(4,1) self.table.resizeColumnsToContents()
def _load(self, ramp_image): if ramp_image.image == None or self.pv_name == None: return None if __debug__ == True: print "I am going to write the stepping binary image to PV: {0}...".format(self.pv_name) if _NO_CATOOLS_ == True: print "...but I see no catools module imported." print "Image: ", ramp_image.image print "Image len, bytes:", len(ramp_image.image) if _NO_CATOOLS_ == True: return None try: connect(self.pv_name, throw=False) caput(self.pv_name, ramp_image.image, wait=True) except: if __debug__ == True: print "My write to CA has failed." return None return 0
def _load(self, ramp_image): if self.pv_name == None: return None if ramp_image.image == None: return None if self.channel_index == None: return None pRamping = self.pv_name + 'Chan' + str(self.channel_index) + '-Asyn.BOUT' if __debug__ == True: print "Preparing to load full ramp in channel " + str(self.channel_index) + " using PV:" print pRamping print "Destination channel index is", self.channel_index print "I am going to write the binary image of full ramp to PV with prefix: {0}...".format(self.pv_name) if _NO_CATOOLS_ == True: print "...but I see no catools module imported." #print "Image: ", ramp_image.image print "Image len, bytes:", len(ramp_image.image) if _NO_CATOOLS_ == True: return None try: #Writing binary ramp table... connect(pRamping, throw=False) caput(pRamping, ramp_image.image, wait=True) except: if __debug__ == True: print "My write to CA has failed." return None return 0
def __init__(self, parent=None): QObject.__init__(self, parent) # state variables. self.runmode = 0 # 0 - continous, 1 - counter self.runRequested = 0 # 0 - run not requested, 1 - requested self.counterRun = 0 # 0 - not running, 1 - running self.shotsLeft = 0 # 4095 - stop point self.nevents = 0 # inctementing when counter cycle ends self.nshots = 0 # number of requested shots # pre-connect PV's self.pvs_connect = [ "V5:SYN:Status00C.B4", "V5:SYN:CountC", "V5:SYN:StartC.PROC", "V5:SYN:StopC.PROC" ] catools.connect(self.pvs_connect) catools.camonitor("V5:SYN:CountM", self.shotsLeftUpdate, datatype=int) catools.camonitor("V5:SYN:EventM", self.neventsUpdate, datatype=int) catools.camonitor("V5:SYN:Status00Rbv", self.statusUpdate, datatype=int)
def _load(self, ramp_image): if self.pv_name == None: return None if ramp_image.image == None: return None if self.channel_index == None: return None pRamping = self.pv_name + 'Chan' + str(self.channel_index) + '-Asyn.BOUT' if __debug__ == True: print("Preparing to load full ramp in channel " + str(self.channel_index) + " using PV:") print(pRamping) print("Destination channel index is", self.channel_index) print("I am going to write the binary image of full ramp to PV with prefix: {0}...".format(self.pv_name)) if _NO_CATOOLS_ == True: print("...but I see no catools module imported.") #print "Image: ", ramp_image.image print("Image len, bytes:", len(ramp_image.image)) if _NO_CATOOLS_ == True: return None try: #Writing binary ramp table... connect(pRamping, throw=False) caput(pRamping, ramp_image.image, wait=True) except: if __debug__ == True: print("My write to CA has failed.") return None return 0
def get_mac_address(epics_id): """ Args: epics_id (Str): The EPICS name of the device. Returns: str: mac address of the device. """ pv = "SA:X" # Any PV hosts on the device could be used here node = connect( ':'.join((epics_id, pv)), cainfo=True).host.split(":")[0] # Get the IP address of the host host_info = Popen(["arp", "-n", node], stdout=PIPE).communicate()[ 0] # Uses arp to get more info about the host host_info = host_info.split("\n")[1] # Splits the data about the host index = host_info.find(":") # Gets the first ":", used in the MAC address host_info = host_info[index - 2:index + 15] # Gets the devices MAC address return host_info
def get_reconnected_pvnames(do_return=False): '''Report those paused pv names, which are reconnected / online again.''' try: from cothread.catools import connect except: print("Aborted: python-cothread is not installed") return pvnames = [] paused_pvnames = report_paused_pvs(do_return=True) results = connect(paused_pvnames, cainfo=True, throw=False) for result in results: if result.ok: pvnames.append(result.name) _log(pvnames, 'reconnected pvnames') if do_return: return pvnames
def updateTable(self): #def callback(self, value, index): #while(True): #if self.startUpdate: disConnectedPVs = [] connectedPVs = [] self.table.clear() self.table.setHorizontalHeaderLabels(self.keys) self.table.setSortingEnabled(False) #print("update table:") #print(self.allPVList) #cothread.Sleep(2) connnectionStatus = connect(self.allPVList, cainfo=True, wait=False, timeout=2, throw=False) for status in connnectionStatus: if status.ok != True: disConnectedPVs.append(status.name) else: connectedPVs.append(status.name) if len(disConnectedPVs) > 0: print("%d PVs seem disconnected: \n" % len(disConnectedPVs)) print(disConnectedPVs) self.label.setText( "%d PVs in the original snapshot, but only %d pairs of setpoint &\ readback in this table because some PVs don't have readbacks or they are disconnected\n\nPlease click the \ button below to update data\n" % (self.rowCount, len(connectedPVs))) self.allPVList = connectedPVs try: pvValues = caget(self.allPVList) except: print("Oops: can't get PV values to verify setpoint and readback") self.label.setText( "Oops: can't get PV values to verify setpoint and readback\n\n" ) traceback.print_exc() return #print(pvValues) for i in range(int(len(self.allPVList) / self.pvListColumn)): self.__setTableItem(self.table, i, 0, str(self.allPVList[i])) #setpoint PV name self.__setTableItem( self.table, i, 1, str(self.allPVList[ i + int(len(self.allPVList) / self.pvListColumn)])) self.__setTableItem(self.table, i, 2, str(pvValues[i])) self.__setTableItem( self.table, i, 3, str(pvValues[i + int(len(self.allPVList) / self.pvListColumn)])) diff_ = abs(pvValues[i] - pvValues[i + int(len(self.allPVList) / self.pvListColumn)]) diff = diff_.__format__('.9f') self.__setTableItem(self.table, i, 4, str(diff)) self.__setTableItem( self.table, i, 5, str(pvValues[i + int((self.pvListColumn - 1) * len(self.allPVList) / self.pvListColumn)])) #self.table.resize(self.table.sizeHint()) self.table.setSortingEnabled(True) self.table.sortItems(4, 1) self.table.resizeColumnsToContents()