当前位置: 首页>>代码示例>>Python>>正文


Python virtual.VirtualPrinter类代码示例

本文整理汇总了Python中octoprint.util.virtual.VirtualPrinter的典型用法代码示例。如果您正苦于以下问题:Python VirtualPrinter类的具体用法?Python VirtualPrinter怎么用?Python VirtualPrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了VirtualPrinter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _connect

	def _connect(self):
		self.changeState(State.OPENING_CONNECTION)
		if self._port == "VIRTUAL":
			self._serial = VirtualPrinter(read_timeout=self._readTimeout, write_timeout=self._writeTimeout)
			self.changeState(State.CONNECTED)
			self._transport_logger.debug("Connected to %s" % self._serial)
		else:
			try:
				self._serial = serial.Serial(self._port, self._baudrate, timeout=self._readTimeout, writeTimeout=self._writeTimeout)
				self.changeState(State.CONNECTED)
				self._transport_logger.debug("Connected to %s" % self._serial)
			except:
				self.logError("Unexpected error while connecting to serial port: %s %s" % (self._port, getExceptionString()))
				self.onError("Failed to open serial port, permissions correct?")
				return False
		eventManager().fire(Events.CONNECTED, {"port": self._port, "baudrate": self._baudrate})
		return True
开发者ID:SHINOTECH,项目名称:Octoprint-1,代码行数:17,代码来源:serialTransport.py

示例2: _openSerial

	def _openSerial(self):
		if self._port == 'AUTO':
			self._changeState(self.STATE_DETECT_SERIAL)
			programmer = stk500v2.Stk500v2()
			self._log("Serial port list: %s" % (str(self._callback.serialList())))
			for p in self._callback.serialList():
				try:
					self._log("Connecting to: %s" % (p))
					programmer.connect(p)
					self._serial = programmer.leaveISP()
					break
				except ispBase.IspError as (e):
					self._log("Error while connecting to %s: %s" % (p, str(e)))
					pass
				except:
					self._log("Unexpected error while connecting to serial port: %s %s" % (p, getExceptionString()))
				programmer.close()
			if self._serial is None:
				self._log("Failed to autodetect serial port")
				self._errorValue = 'Failed to autodetect serial port.'
				self._changeState(self.STATE_ERROR)
				eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
				return False
		elif self._port == 'VIRTUAL':
			self._changeState(self.STATE_OPEN_SERIAL)
			self._serial = VirtualPrinter()
		else:
			self._changeState(self.STATE_OPEN_SERIAL)
			try:
				self._log("Connecting to: %s" % self._port)
				if self._baudrate == 0:
					self._serial = serial.Serial(str(self._port), 115200, timeout=0.1, writeTimeout=10000)
				else:
					self._serial = serial.Serial(str(self._port), self._baudrate, timeout=settings().getFloat(["serial", "timeout", "connection"]), writeTimeout=10000)
			except:
				self._log("Unexpected error while connecting to serial port: %s %s" % (self._port, getExceptionString()))
				self._errorValue = "Failed to open serial port, permissions correct?"
				self._changeState(self.STATE_ERROR)
				eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
				return False
		return True
开发者ID:TramALot,项目名称:AstroBox,代码行数:41,代码来源:comm.py

示例3: MachineCom


#.........这里部分代码省略.........
				errorMsg = "See astrobox.log for details"
				self._log(errorMsg)
				self._errorValue = errorMsg
				self._changeState(self.STATE_ERROR)
				eventManager().fire(Events.ERROR, {"error": self.getErrorString()})

		self._log("Connection closed, closing down monitor")

	def _openSerial(self):
		if self._port == 'AUTO':
			self._changeState(self.STATE_DETECT_SERIAL)
			programmer = stk500v2.Stk500v2()
			self._log("Serial port list: %s" % (str(self._callback.serialList())))
			for p in self._callback.serialList():
				try:
					self._log("Connecting to: %s" % (p))
					programmer.connect(p)
					self._serial = programmer.leaveISP()
					break
				except ispBase.IspError as (e):
					self._log("Error while connecting to %s: %s" % (p, str(e)))
					pass
				except:
					self._log("Unexpected error while connecting to serial port: %s %s" % (p, getExceptionString()))
				programmer.close()
			if self._serial is None:
				self._log("Failed to autodetect serial port")
				self._errorValue = 'Failed to autodetect serial port.'
				self._changeState(self.STATE_ERROR)
				eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
				return False
		elif self._port == 'VIRTUAL':
			self._changeState(self.STATE_OPEN_SERIAL)
			self._serial = VirtualPrinter()
		else:
			self._changeState(self.STATE_OPEN_SERIAL)
			try:
				self._log("Connecting to: %s" % self._port)
				if self._baudrate == 0:
					self._serial = serial.Serial(str(self._port), 115200, timeout=0.1, writeTimeout=10000)
				else:
					self._serial = serial.Serial(str(self._port), self._baudrate, timeout=settings().getFloat(["serial", "timeout", "connection"]), writeTimeout=10000)
			except:
				self._log("Unexpected error while connecting to serial port: %s %s" % (self._port, getExceptionString()))
				self._errorValue = "Failed to open serial port, permissions correct?"
				self._changeState(self.STATE_ERROR)
				eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
				return False
		return True

	def _handleErrors(self, line):
		# No matter the state, if we see an error, goto the error state and store the error for reference.
		if line.startswith('Error:'):
			#Oh YEAH, consistency.
			# Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n"
			#	But a bed temp error is reported as "Error: Temperature heated bed switched off. MAXTEMP triggered !!"
			#	So we can have an extra newline in the most common case. Awesome work people.
			if self._regex_minMaxError.match(line):
				line = line.rstrip() + self._readline()
			#Skip the communication errors, as those get corrected.
			if 'checksum mismatch' in line \
				or 'Wrong checksum' in line \
				or 'Line Number is not Last Line Number' in line \
				or 'expected line' in line \
				or 'No Line Number with checksum' in line \
				or 'No Checksum with line number' in line \
开发者ID:TramALot,项目名称:AstroBox,代码行数:67,代码来源:comm.py

示例4: MachineCom


#.........这里部分代码省略.........

				errorMsg = "See octoprint.log for details"
				self._log(errorMsg)
				self._errorValue = errorMsg
				self._changeState(self.STATE_ERROR)
				eventManager().fire("Error", self.getErrorString())
		self._log("Connection closed, closing down monitor")

	def _openSerial(self):
		if self._port == 'AUTO':
			self._changeState(self.STATE_DETECT_SERIAL)
			programmer = stk500v2.Stk500v2()
			self._log("Serial port list: %s" % (str(serialList())))
			for p in serialList():
				try:
					self._log("Connecting to: %s" % (p))
					programmer.connect(p)
					self._serial = programmer.leaveISP()
					break
				except ispBase.IspError as (e):
					self._log("Error while connecting to %s: %s" % (p, str(e)))
					pass
				except:
					self._log("Unexpected error while connecting to serial port: %s %s" % (p, getExceptionString()))
				programmer.close()
			if self._serial is None:
				self._log("Failed to autodetect serial port")
				self._errorValue = 'Failed to autodetect serial port.'
				self._changeState(self.STATE_ERROR)
				eventManager().fire("Error", self.getErrorString())
				return False
		elif self._port == 'VIRTUAL':
			self._changeState(self.STATE_OPEN_SERIAL)
			self._serial = VirtualPrinter()
		else:
			self._changeState(self.STATE_OPEN_SERIAL)
			try:
				self._log("Connecting to: %s" % self._port)
				if self._baudrate == 0:
					self._serial = serial.Serial(str(self._port), 115200, timeout=0.1, writeTimeout=10000)
				else:
					self._serial = serial.Serial(str(self._port), self._baudrate, timeout=settings().getFloat(["serial", "timeout", "connection"]), writeTimeout=10000)
			except:
				self._log("Unexpected error while connecting to serial port: %s %s" % (self._port, getExceptionString()))
				self._errorValue = "Failed to open serial port, permissions correct?"
				self._changeState(self.STATE_ERROR)
				eventManager().fire("Error", self.getErrorString())
				return False
		return True

	def _handleErrors(self, line):
		# No matter the state, if we see an error, goto the error state and store the error for reference.
		if line.startswith('Error:'):
			#Oh YEAH, consistency.
			# Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n"
			#	But a bed temp error is reported as "Error: Temperature heated bed switched off. MAXTEMP triggered !!"
			#	So we can have an extra newline in the most common case. Awesome work people.
			if self._regex_minMaxError.match(line):
				line = line.rstrip() + self._readline()
			#Skip the communication errors, as those get corrected.
			if 'checksum mismatch' in line \
				or 'Wrong checksum' in line \
				or 'Line Number is not Last Line Number' in line \
				or 'expected line' in line \
				or 'No Line Number with checksum' in line \
				or 'No Checksum with line number' in line \
开发者ID:NeighborGeek,项目名称:OctoPrint,代码行数:67,代码来源:comm.py

示例5: _monitor

	def _monitor(self):
		feedbackControls = settings().getFeedbackControls()
		pauseTriggers = settings().getPauseTriggers()
		feedbackErrors = []

		#Open the serial port.
		if self._port == 'AUTO':
			self._changeState(self.STATE_DETECT_SERIAL)
			programmer = stk500v2.Stk500v2()
			self._log("Serial port list: %s" % (str(serialList())))
			for p in serialList():
				try:
					self._log("Connecting to: %s" % (p))
					programmer.connect(p)
					self._serial = programmer.leaveISP()
					break
				except ispBase.IspError as (e):
					self._log("Error while connecting to %s: %s" % (p, str(e)))
					pass
				except:
					self._log("Unexpected error while connecting to serial port: %s %s" % (p, getExceptionString()))
				programmer.close()
		elif self._port == 'VIRTUAL':
			self._changeState(self.STATE_OPEN_SERIAL)
			self._serial = VirtualPrinter()
		else:
			self._changeState(self.STATE_OPEN_SERIAL)
			try:
				self._log("Connecting to: %s" % (self._port))
				if self._baudrate == 0:
					self._serial = serial.Serial(str(self._port), 115200, timeout=0.1, writeTimeout=10000)
				else:
					self._serial = serial.Serial(str(self._port), self._baudrate, timeout=settings().getFloat(["serial", "timeout", "connection"]), writeTimeout=10000)
			except:
				self._log("Unexpected error while connecting to serial port: %s %s" % (self._port, getExceptionString()))
		if self._serial == None:
			self._log("Failed to open serial port (%s)" % (self._port))
			self._errorValue = 'Failed to autodetect serial port.'
			self._changeState(self.STATE_ERROR)
			eventManager().fire("Error", self.getErrorString())
			return
		self._log("Connected to: %s, starting monitor" % (self._serial))
		if self._baudrate == 0:
			self._changeState(self.STATE_DETECT_BAUDRATE)
		else:
			self._changeState(self.STATE_CONNECTING)

		#Start monitoring the serial port.
		timeout = getNewTimeout("communication")
		tempRequestTimeout = timeout
		sdStatusRequestTimeout = timeout
		startSeen = not settings().getBoolean(["feature", "waitForStartOnConnect"])
		heatingUp = False
		swallowOk = False
		while True:
			try:
				line = self._readline()
				if line == None:
					break

				##~~ Error handling
				# No matter the state, if we see an error, goto the error state and store the error for reference.
				if line.startswith('Error:'):
					#Oh YEAH, consistency.
					# Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n"
					#	But a bed temp error is reported as "Error: Temperature heated bed switched off. MAXTEMP triggered !!"
					#	So we can have an extra newline in the most common case. Awesome work people.
					if re.match('Error:[0-9]\n', line):
						line = line.rstrip() + self._readline()
					#Skip the communication errors, as those get corrected.
					if 'checksum mismatch' in line \
							or 'Wrong checksum' in line \
							or 'Line Number is not Last Line Number' in line \
							or 'expected line' in line \
							or 'No Line Number with checksum' in line \
							or 'No Checksum with line number' in line \
							or 'Missing checksum' in line:
						pass
					elif not self.isError():
						self._errorValue = line[6:]
						self._changeState(self.STATE_ERROR)
						eventManager().fire("Error", self.getErrorString())

				##~~ SD file list
				# if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing
				if self._sdFileList and not 'End file list' in line:
					self._sdFiles.append(line.strip().lower())
					continue

				##~~ Temperature processing
				if ' T:' in line or line.startswith('T:'):
					try:
						self._temp = float(re.search("-?[0-9\.]*", line.split('T:')[1]).group(0))
						if ' B:' in line:
							self._bedTemp = float(re.search("-?[0-9\.]*", line.split(' B:')[1]).group(0))

						self._callback.mcTempUpdate(self._temp, self._bedTemp, self._targetTemp, self._bedTargetTemp)
					except ValueError:
						# catch conversion issues, we'll rather just not get the temperature update instead of killing the connection
						pass
#.........这里部分代码省略.........
开发者ID:StbLinux,项目名称:OctoPrint,代码行数:101,代码来源:comm.py

示例6: SerialTransport

class SerialTransport(Transport):

	__transportinfo__ = ("serial", "Serial", False)

	def __init__(self, messageReceiver, stateReceiver, logReceiver):
		Transport.__init__(self, messageReceiver, stateReceiver, logReceiver)

		self._serial = None
		self._port = None
		self._baudrate = None
		self._connectionTimeout = None
		self._writeTimeout = None
		self._readTimeout = None

		self._timeoutCounter = 0
		self._maxTimeouts = 20

		self._thread = None

	def get_properties(self):
		return {
			TransportProperties.FLOWCONTROL: False
		}

	def get_connection_options(self):
		return {
			"port": self.__getSerialList(),
			"baudrate": self.__getBaudrateList()
		}

	def connect(self, opt):
		Transport.connect(self, opt)

		self._port = opt["port"] if "port" in opt else None
		self._baudrate = opt["baudrate"] if "baudrate" in opt else None

		self._readTimeout = opt["timeout"]["read"] if "timeout" in opt and "read" in opt["timeout"] else 5.0
		self._writeTimeout = opt["timeout"]["write"] if "timeout" in opt and "write" in opt["timeout"] else 0.5

		if self._connect():
			self._thread = threading.Thread(target=self._monitor, name="SerialTransportMonitor")
			self._thread.daemon = True
			self._thread.start()

	def disconnect(self, onError=False):
		try:
			if self._serial is not None:
				self._serial.close()
		finally:
			self._serial = None
		self._thread = None
		Transport.disconnect(self, onError)

	def send(self, command):
		commandToSend = command + "\n"
		try:
			self._serial.write(commandToSend)
			self._transport_logger.info("Send: %s" % command)
			self.logTx(command)
		except serial.SerialTimeoutException:
			self._transport_logger.warn("Timeout while sending: %s" % command)
			self.logError("Serial timeout while writing to serial port, try again later.")
			raise SendTimeout()
		except:
			exceptionString = getExceptionString()
			self.logError("Unexpected error while writing serial port: %s" % exceptionString)
			self.onError(exceptionString)
			self.disconnect(True)
			raise TransportError()

	def receive(self):
		return self._readline()

	def _monitor(self):
		error = None
		while True:
			line = self._readline()
			if line is None:
				error = "Serial connection closed unexpectedly"
				break
			if line == "":
				self._timeoutCounter += 1
				self.onTimeout()
				if self._maxTimeouts and self._timeoutCounter > self._maxTimeouts:
					error = "Printer did not respond at all over %d retries, considering it dead" % self._maxTimeouts
					break
			else:
				self._timeoutCounter = 0
			self.onMessageReceived(line.strip())

		if error is not None:
			self._transport_logger.error(error)
			self.logError(error)
			self.onError(error)
			# TODO further error handling

	def _connect(self):
		self.changeState(State.OPENING_CONNECTION)
		if self._port == "VIRTUAL":
			self._serial = VirtualPrinter(read_timeout=self._readTimeout, write_timeout=self._writeTimeout)
#.........这里部分代码省略.........
开发者ID:SHINOTECH,项目名称:Octoprint-1,代码行数:101,代码来源:serialTransport.py


注:本文中的octoprint.util.virtual.VirtualPrinter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。