Beispiel #1
0
	def readline(self):
		if self._debug_drop_connection:
			raise SerialTimeoutException()

		try:
			line = self.outgoing.get(timeout=self._read_timeout)
			return line
		except Queue.Empty:
			return ""
Beispiel #2
0
	def write(self, data):
		if self._debug_drop_connection:
			self._logger.info("Debug drop of connection requested, raising SerialTimeoutException")
			raise SerialTimeoutException()

		with self._incoming_lock:
			if self.incoming is None or self.outgoing is None:
				return

			if "M112" in data and self._supportM112:
				self._kill()
				return

			try:
				self.incoming.put(data, timeout=self._write_timeout)
			except Queue.Full:
				self._logger.info("Incoming queue is full, raising SerialTimeoutException")
				raise SerialTimeoutException()
Beispiel #3
0
	def readline(self):
		if self._debug_drop_connection:
			raise SerialTimeoutException()

		try:
			line = self.outgoing.get(timeout=self._read_timeout)
			time.sleep(settings().getFloat(["devel", "virtualPrinter", "throttle"]))
			return line
		except Queue.Empty:
			return ""
Beispiel #4
0
    def test_serial_controllers_are_purged_on_write_failure(
            self, serial_port_mock: Mock) -> None:
        serial_port_mock.write.side_effect = SerialTimeoutException("Timeout")

        self.assertEqual(len(SERIAL_CONTROLLERS), 0)

        with TestSerialPowerSupply("/dev/ttyUSB0", 9600) as power_supply:
            self.assertEqual(len(SERIAL_CONTROLLERS), 1)
            self.assertIn("/dev/ttyUSB0", SERIAL_CONTROLLERS.keys())
            with self.assertRaises(SerialTimeoutException):
                power_supply.get_mode()
            self.assertEqual(len(SERIAL_CONTROLLERS), 1)

        self.assertEqual(len(SERIAL_CONTROLLERS), 0)
Beispiel #5
0
	def write(self, data):
		if self._debug_awol:
			return len(data)

		if self._debug_drop_connection:
			self._logger.info("Debug drop of connection requested, raising SerialTimeoutException")
			raise SerialTimeoutException()

		with self._incoming_lock:
			if self.incoming is None or self.outgoing is None:
				return 0

			if "M112" in data and self._supportM112:
				self._seriallog.info("<<< {}".format(data.strip()))
				self._kill()
				return len(data)

			try:
				written = self.incoming.put(data, timeout=self._write_timeout, partial=True)
				self._seriallog.info("<<< {}".format(data.strip()))
				return written
			except queue.Full:
				self._logger.info("Incoming queue is full, raising SerialTimeoutException")
				raise SerialTimeoutException()
Beispiel #6
0
    def readline(self):
        if self._debug_awol:
            time.sleep(self._read_timeout)
            return ""

        if self._debug_drop_connection:
            raise SerialTimeoutException()

        if self._debug_sleep > 0:
            # if we are supposed to sleep, we sleep not longer than the read timeout
            # (and then on the next call sleep again if there's time to sleep left)
            sleep_for = min(self._debug_sleep, self._read_timeout)
            self._debug_sleep -= sleep_for
            time.sleep(sleep_for)

            if self._debug_sleep > 0:
                # we slept the full read timeout, return an empty line
                return ""

            # otherwise our left over timeout is the read timeout minus what we already
            # slept for
            timeout = self._read_timeout - sleep_for

        else:
            # use the full read timeout as timeout
            timeout = self._read_timeout

        try:
            # fetch a line from the queue, wait no longer than timeout
            line = self.outgoing.get(timeout=timeout)
            self._seriallog.info(">>> {}".format(line.strip()))
            self.outgoing.task_done()
            return line
        except queue.Empty:
            # queue empty? return empty line
            return ""
Beispiel #7
0
 def write(self, data: bytes) -> int:
     """Write the data to the serial port."""
     raise SerialTimeoutException()
 def write(self, data):
     try:
         return os.write(self.fd, data)
     except Exception as e:
         sleep(0.1)
         raise SerialTimeoutException(e)
Beispiel #9
0
def raise_serial_timeout() -> None:
    """A test function."""
    raise SerialTimeoutException()
Beispiel #10
0
 def test_write_timeout(self, serial_port_mock: Mock) -> None:
     serial_port_mock.write.side_effect = SerialTimeoutException("Timeout")
     with self.assertRaises(SerialTimeoutException):
         with TestSerialPowerSupply("/dev/ttyUSB0", 9600) as power_supply:
             power_supply.get_mode()