def process(self, message): logging.debug("Received from Kramer VP-88: " + SerialDevice.byteArrayToString(message).encode('hex_codec')) if (message[3] == 0x80 + self.machineNumber): if (message[0] == 0x41) or (message[0] == 0x45): # Notification of video switch or response to query inp = message[1] - 0x80 outp = message[2] - 0x80 return {outp: inp} return {}
def process(self, message): logging.debug("Received from Kramer 602: " + SerialDevice.byteArrayToString(message).encode('hex_codec')) if ((message[0] & 0x7) == (self.machineNumber - 1)): if message[1] == 0xff: # Occasionally on startup we seem to receive a three-byte packet with the middle byte 0xFF. So ignore that middle. message[1] = self.parentDevice.port.read(1) if (message[1] & 0x20) == 0: # Not just a "I switched successfully" message outp = (((message[1] & 0x1F) - 1) % 2) + 1 inp = (((message[1] & 0x1F) - outp) / 2) + 1 # int(math.ceil((message[1] & 0x1F) + (2 / 2)) - 1) return {outp: inp} else: self.parentDevice.requestStatus() # Request device to send current status so listener can intercept return {}
def initialise(self): SerialDevice.initialise(self) self.port.flushInput() self.requestStatus()
def sendInputToOutput(self, inChannel, outChannel): if outChannel > 2: logging.error("Output channel " + str(outChannel) + " does not exist on switcher " + self.deviceID) else: code = [0, 0x80 + (2 * inChannel) - (2 - outChannel)] self.sendCommand(SerialDevice.byteArrayToString(code))
def execute(self, command): if isinstance(command, VISCACommand): return self.sendCommand(SerialDevice.byteArrayToString(command.getBytes(self.cameraID)))
def sendVISCA(self, commandBytes): return self.sendCommand(SerialDevice.byteArrayToString([0x80 + self.cameraID] + commandBytes + [0xFF]))
def requestStatus(self): for i in range(1, 9): self.sendCommand(SerialDevice.byteArrayToString([0x05, 0x80, 0x80 + i, 0x80 + self.machineNumber]))
def sendInputToOutput(self, inChannel, outChannel): toSend = [0x01, 0x80 + inChannel, 0x80 + outChannel, 0x80 + self.machineNumber] return self.sendCommand(SerialDevice.byteArrayToString(toSend))
def off(self, channel): result = self.sendCommand(SerialDevice.byteArrayToString([0x31 + 2 * channel])) time.sleep(self.sendDelay) return result
def off(self, channel): return self.sendCommand(SerialDevice.byteArrayToString([0xFF, channel, 0x00]))
def __init__(self, deviceID, serialDevice, **others): SerialDevice.__init__(self, deviceID, serialDevice, **others)