def initialize_matrix(self, resource): self.emit("message", "Open all matrix channels...") matrix = K707B(resource) matrix.identification logging.info("matrix: open all channels.") matrix.channel.open() channels = matrix.channel.getclose() logging.info("matrix channels: %s", channels) self.emit("message", "Opened all matrix channels.")
def open_matrix(self): try: with self.resources.get("matrix") as matrix_res: matrix = K707B(matrix_res) matrix.channel.open() # open all logger.info("Matrix: opened all channels") except Exception as exc: raise RuntimeError( f"Matrix failed to open channels, {exc.args}") from exc
def after_finalize(self, **kwargs): """Reset marix switch to a save state.""" matrix_enable = self.get_parameter('matrix_enable') if matrix_enable: try: with self.resources.get("matrix") as matrix_res: matrix = K707B(matrix_res) matrix.channel.open() # open all except Exception as exc: raise RuntimeError( f"Matrix failed to open channels, {exc.args}") from exc super().after_finalize(**kwargs)
def read_matrix(self): self.set("matrix_model", "") self.set("matrix_channels", "") try: with self.resources.get("matrix") as matrix_res: matrix = K707B(matrix_res) model = matrix.identification self.set("matrix_model", model) channels = matrix.channel.getclose() self.set("matrix_channels", ','.join(channels)) except (ResourceError, OSError): pass
def close_matrix(self, channels): try: with self.resources.get("matrix") as matrix_res: matrix = K707B(matrix_res) matrix.channel.close(channels) closed_channels = matrix.channel.getclose() if sorted(closed_channels) != sorted(channels): raise RuntimeError("Matrix mismatch in closed channels") logger.info("Matrix: closed channels: %s", ', '.join(closed_channels)) except Exception as exc: raise RuntimeError( f"Failed to close matrix channels {channels}, {exc.args}" ) from exc
def before_initialize(self, **kwargs): """Setup matrix switch.""" super().before_initialize(**kwargs) matrix_enable = self.get_parameter('matrix_enable') if matrix_enable: matrix_channels = self.get_parameter('matrix_channels') logger.info("Matrix close channels: %s", matrix_channels) try: with self.resources.get("matrix") as matrix_res: matrix = K707B(matrix_res) closed_channels = matrix.channel.getclose() if closed_channels: raise RuntimeError("Some matrix channels are still closed, " \ f"please verify the situation and open closed channels. Closed channels: {closed_channels}") if matrix_channels: matrix.channel.close(matrix_channels) closed_channels = matrix.channel.getclose() if sorted(closed_channels) != sorted(matrix_channels): raise RuntimeError( "Matrix mismatch in closed channels") except Exception as exc: raise RuntimeError( f"Failed to close matrix channels {matrix_channels}, {exc.args}" ) from exc