Exemplo n.º 1
0
    def testSerialDevice(self):
        port = MockSerialPort()
        port.portstr = "TESTPORT"
        device = SerialDevice("Test", port)

        port.write = MagicMock(side_effect=SerialException("Test serial exception"))

        device.sendCommand("\x01")

        self.assertEqual(port.write.call_count, 2)
Exemplo n.º 2
0
    def testSerialDevice(self):
        port = MockSerialPort()
        port.portstr = "TESTPORT"
        device = SerialDevice("Test", port)

        port.write = MagicMock(
            side_effect=SerialException("Test serial exception"))

        device.sendCommand("\x01")

        self.assertEqual(port.write.call_count, 2)
Exemplo n.º 3
0
 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 {}
Exemplo n.º 4
0
 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
             for d in self.dispatchers:
                 d.updateOutputMappings({self.parentDevice.deviceID: {outp: inp}})
Exemplo n.º 5
0
 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 {}
Exemplo n.º 6
0
 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 {}
Exemplo n.º 7
0
 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)
             for d in self.dispatchers:
                 d.updateOutputMappings({self.parentDevice.deviceID: {outp: inp}})
         else:
             self.parentDevice.requestStatus()  # Request device to send current status so listener can intercept
Exemplo n.º 8
0
 def initialise(self):
     SerialDevice.initialise(self)
     self.port.flushInput()
     self.requestStatus()
Exemplo n.º 9
0
 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))
Exemplo n.º 10
0
 def __sendStateCommand(self):
     result = self.sendCommand(SerialDevice.byteArrayToString([self.__createStateByte()]))
     return result
Exemplo n.º 11
0
 def off(self, channel):
     result = self.sendCommand(SerialDevice.byteArrayToString([0x31 + 2 * channel]))
     time.sleep(self.sendDelay)
     return result
Exemplo n.º 12
0
 def off(self, channel):
     return self.sendCommand(SerialDevice.byteArrayToString([0xFF, channel, 0x00]))
Exemplo n.º 13
0
 def __init__(self, deviceID, serialDevice, **others):
     SerialDevice.__init__(self, deviceID, serialDevice, **others)
Exemplo n.º 14
0
 def execute(self, command):
     if isinstance(command, VISCACommand):
         return self.sendCommand(SerialDevice.byteArrayToString(command.getBytes(self.cameraID)))
Exemplo n.º 15
0
 def requestStatus(self):
     for i in range(1, 9):
         self.sendCommand(SerialDevice.byteArrayToString([0x05, 0x80, 0x80 + i, 0x80 + self.machineNumber]))
Exemplo n.º 16
0
 def sendInputToOutput(self, inChannel, outChannel):
     toSend = [0x01, 0x80 + int(inChannel), 0x80 + int(outChannel), 0x80 + self.machineNumber]
     return self.sendCommand(SerialDevice.byteArrayToString(toSend))
Exemplo n.º 17
0
 def execute(self, command):
     if isinstance(command, VISCACommand):
         return self.sendCommand(
             SerialDevice.byteArrayToString(command.getBytes(
                 self.cameraID)))
Exemplo n.º 18
0
 def requestStatus(self):
     for i in range(1, 9):
         self.sendCommand(
             SerialDevice.byteArrayToString(
                 [0x05, 0x80, 0x80 + i, 0x80 + self.machineNumber]))
Exemplo n.º 19
0
 def initialise(self):
     SerialDevice.initialise(self)
     self.port.flushInput()
     self.requestStatus()
Exemplo n.º 20
0
 def sendInputToOutput(self, inChannel, outChannel):
     toSend = [
         0x01, 0x80 + int(inChannel), 0x80 + int(outChannel),
         0x80 + self.machineNumber
     ]
     return self.sendCommand(SerialDevice.byteArrayToString(toSend))
Exemplo n.º 21
0
 def sendVISCA(self, commandBytes):
     return self.sendCommand(SerialDevice.byteArrayToString([0x80 + self.cameraID] + commandBytes + [0xFF]))
Exemplo n.º 22
0
 def sendVISCA(self, commandBytes):
     return self.sendCommand(
         SerialDevice.byteArrayToString([0x80 + self.cameraID] +
                                        commandBytes + [0xFF]))
Exemplo n.º 23
0
 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))