def readBlocks(self, *, recurse=True, variable=None, checkEach=False, index=-1, **kwargs): """ Perform background reads """ checkEach = checkEach or self.forceCheckEach if variable is not None: pr.startTransaction(variable._block, type=rim.Read, checkEach=checkEach, variable=variable, index=index, **kwargs) else: for block in self._blocks: if block.bulkOpEn: pr.startTransaction(block, type=rim.Read, checkEach=checkEach, **kwargs) if recurse: for key, value in self.devices.items(): value.readBlocks(recurse=True, checkEach=checkEach, **kwargs)
def verifyBlocks(self, *, recurse=True, variable=None, checkEach=False, **kwargs): """ Perform background verify """ checkEach = checkEach or self.forceCheckEach if variable is not None: pr.startTransaction( variable._block, type=rim.Verify, checkEach=checkEach, **kwargs) # Verify range is set by previous write else: for block in self._blocks: if block.bulkOpEn: pr.startTransaction(block, type=rim.Verify, checkEach=checkEach, **kwargs) if recurse: for key, value in self.devices.items(): value.verifyBlocks(recurse=True, checkEach=checkEach, **kwargs)
def get(self, *, index=-1, read=True): try: if read: pr.startTransaction(self._block, type=rogue.interfaces.memory.Read, forceWr=False, checkEach=True, variable=self, index=index) return self._get(index) except Exception as e: pr.logException(self._log, e) raise e
def set(self, value, *, index=-1, write=True): self._log.debug("{}.set({})".format(self, value)) try: self._set(value, index) if write: pr.startTransaction(self._block, type=rogue.interfaces.memory.Write, forceWr=True, checkEach=True, variable=self, index=index) except Exception as e: pr.logException(self._log, e) raise e
def readBlocks(self, *, recurse=True, variable=None, checkEach=False, index=-1, **kwargs): """ Perform background reads """ checkEach = checkEach or self.forceCheckEach if variable is not None: freeze = isinstance(variable, list) and any( v.name.startswith('AdcChannel') for v in variable) if freeze: self.FreezeDebug(1) pr.startTransaction(variable._block, type=rim.Read, checkEach=checkEach, variable=variable, index=index, **kwargs) if freeze: self.FreezeDebug(0) else: self.FreezeDebug(1) for block in self._blocks: if block.bulkOpEn: pr.startTransaction(block, type=rim.Read, checkEach=checkEach, **kwargs) self.FreezeDebug(0) if recurse: for key, value in self.devices.items(): value.readBlocks(recurse=True, checkEach=checkEach, **kwargs)
def writeBlocks(self, *, force=False, recurse=True, variable=None, checkEach=False, index=-1, **kwargs): """ Write all of the blocks held by this Device to memory """ checkEach = checkEach or self.forceCheckEach if variable is not None: pr.startTransaction(variable._block, type=rim.Write, forceWr=force, checkEach=checkEach, variable=variable, index=index, **kwargs) else: for block in self._blocks: if block.bulkOpEn: pr.startTransaction(block, type=rim.Write, forceWr=force, checkEach=checkEach, **kwargs) if recurse: for key, value in self.devices.items(): value.writeBlocks(force=force, recurse=True, checkEach=checkEach, **kwargs)
def post(self, value, *, index=-1): """ Set the value and write to hardware if applicable using a posted write. This method does not call through parent.writeBlocks(), but rather calls on self._block directly. """ self._log.debug("{}.post({})".format(self, value)) try: self._block.set(self, value, index) pr.startTransaction(self._block, type=rim.Post, forceWr=False, checkEach=True, variable=self, index=index) except Exception as e: pr.logException(self._log, e) self._log.error( "Error posting value '{}' to variable '{}' with type {}". format(value, self.path, self.typeStr)) raise e
def _poll(self): """Run by the poll thread""" while True: if self.empty() or self.paused(): # Sleep until woken with self._condLock: self._condLock.wait() if self._run is False: self._log.info("PollQueue thread exiting") return else: continue else: # Sleep until the top entry is ready to be polled # Or a new entry is added by updatePollInterval now = datetime.datetime.now() readTime = self.peek().readTime waitTime = (readTime - now).total_seconds() with self._condLock: self._log.debug(f'Poll thread sleeping for {waitTime}') self._condLock.wait(waitTime) self._log.debug(f'Global reference count: {sys.getrefcount(None)}') with self._condLock: # Stop the thread if someone set run to False if self._run is False: self._log.info("PollQueue thread exiting") return # Wait for block count to be zero while self.blockCount > 0: self._condLock.wait() # Start update capture with self._root.updateGroup(): # Pop all timed out entries from the queue now = datetime.datetime.now() blockEntries = [] for entry in self._expiredEntries(now): self._log.debug(f'Polling Block {entry.block.path}') blockEntries.append(entry) try: pr.startTransaction( entry.block, type=rogue.interfaces.memory.Read) except Exception as e: pr.logException(self._log, e) # Update the entry with new read time entry.readTime = now + entry.interval entry.count = next(self._counter) # Push the updated entry back into the queue heapq.heappush(self._pq, entry) for entry in blockEntries: try: pr.checkTransaction(entry.block) except Exception as e: pr.logException(self._log, e)
def queuedTouch(cmd, arg): print(f'Queueing command {cmd.path}({arg})') cmd._set(arg, -1) pr.startTransaction(cmd._block, type=rim.Write, forceWr=True, checkEach=False, variable=cmd, index=-1)
def nonBlockingTouchZero(cmd, arg): print(f'Sending nonblocking touch zero command for {cmd.path}') cmd._set(0, -1) pr.startTransaction(cmd._block, type=rim.Write, forceWr=True, checkEach=False, variable=cmd, index=-1)