本文整理匯總了Python中octoprint.util.virtual.VirtualPrinter.readline方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualPrinter.readline方法的具體用法?Python VirtualPrinter.readline怎麽用?Python VirtualPrinter.readline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類octoprint.util.virtual.VirtualPrinter
的用法示例。
在下文中一共展示了VirtualPrinter.readline方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MachineCom
# 需要導入模塊: from octoprint.util.virtual import VirtualPrinter [as 別名]
# 或者: from octoprint.util.virtual.VirtualPrinter import readline [as 別名]
#.........這裏部分代碼省略.........
self._sdAvailable = False
self._sdFiles = []
self._callback.mcSdStateChange(self._sdAvailable)
self._callback.mcSdFiles(self._sdFiles)
##~~ communication monitoring and handling
def _monitor(self):
feedbackControls = settings().getFeedbackControls()
pauseTriggers = settings().getPauseTriggers()
feedbackErrors = []
#Open the serial port.
if not self._openSerial():
return
self._log("Connected to: %s, starting monitor" % self._serial)
if self._baudrate == 0:
self._log("Starting baud rate detection")
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 is None:
break
##~~ Error handling
line = self._handleErrors(line)
##~~ 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 isGcodeFileName(line.strip().lower()) and not 'End file list' in line:
filename = line.strip().lower()
if filterNonAscii(filename):
self._logger.warn("Got a file from printer's SD that has a non-ascii filename (%s), that shouldn't happen according to the protocol" % filename)
else:
self._sdFiles.append(filename)
continue
##~~ Temperature processing
if ' T:' in line or line.startswith('T:'):
try:
self._temp = float(self._regex_float.search(line.split('T:')[1]).group(0))
if ' B:' in line:
self._bedTemp = float(self._regex_float.search(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
#If we are waiting for an M109 or M190 then measure the time we lost during heatup, so we can remove that time from our printing time estimate.
if not 'ok' in line:
heatingUp = True
if self._heatupWaitStartTime != 0:
示例2: MachineCom
# 需要導入模塊: from octoprint.util.virtual import VirtualPrinter [as 別名]
# 或者: from octoprint.util.virtual.VirtualPrinter import readline [as 別名]
#.........這裏部分代碼省略.........
elif self._bedTemp is not None and isinstance(self._bedTemp, tuple):
(oldActual, oldTarget) = self._bedTemp
self._bedTemp = (actual, oldTarget)
else:
self._bedTemp = (actual, None)
def _monitor(self):
feedbackControls = settings().getFeedbackControls()
pauseTriggers = settings().getPauseTriggers()
feedbackErrors = []
#Open the serial port.
if not self._openSerial():
return
self._log("Connected to: %s, starting monitor" % self._serial)
if self._baudrate == 0:
self._log("Starting baud rate detection")
self._changeState(self.STATE_DETECT_BAUDRATE)
else:
self._changeState(self.STATE_CONNECTING)
#Start monitoring the serial port.
timeout = getNewTimeout("communication")
tempRequestTimeout = getNewTimeout("temperature")
sdStatusRequestTimeout = getNewTimeout("sdStatus")
startSeen = not settings().getBoolean(["feature", "waitForStartOnConnect"])
self._heatingUp = False
swallowOk = False
supportRepetierTargetTemp = settings().getBoolean(["feature", "repetierTargetTemp"])
while True:
try:
line = self._readline()
if line is None:
break
if line.strip() is not "" and line.isalnum():
timeout = getNewTimeout("communication")
##~~ Error handling
line = self._handleErrors(line)
##~~ 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:
fileinfo = line.strip().split(None, 2)
if len(fileinfo) > 1:
# we got extended file information here, so let's split filename and size and try to make them a bit nicer
filename, size = fileinfo
filename = filename.lower()
try:
size = int(size)
except ValueError:
# whatever that was, it was not an integer, so we'll just ignore it and set size to None
size = None
else:
# no extended file information, so only the filename is there and we set size to None
filename = fileinfo[0].lower()
size = None
if self._callback.fileManager.isValidFilename(filename):
if filterNonAscii(filename):
self._logger.warn("Got a file from printer's SD that has a non-ascii filename (%s), that shouldn't happen according to the protocol" % filename)
else:
self._sdFiles.append((filename, size))
continue
示例3: SerialTransport
# 需要導入模塊: from octoprint.util.virtual import VirtualPrinter [as 別名]
# 或者: from octoprint.util.virtual.VirtualPrinter import readline [as 別名]
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)
#.........這裏部分代碼省略.........