예제 #1
0
    def _readline(self):
        try:
            try:
                line = self.printer.readline()
                if self.printer_tcp and not line:
                    raise OSError(-1, "Read EOF from socket")
            except socket.timeout:
                return ""

            if len(line) > 1:
                self.log.append(line)
                if self.recvcb:
                    try: self.recvcb(line)
                    except: pass
                if self.loud: print "RECV:", line.rstrip()
            return line
        except SelectError as e:
            if 'Bad file descriptor' in e.args[1]:
                print _(u"Can't read from printer (disconnected?) (SelectError {0}): {1}").format(e.errno, decode_utf8(e.strerror))
                return None
            else:
                print _(u"SelectError ({0}): {1}").format(e.errno, decode_utf8(e.strerror))
                raise
        except SerialException as e:
            print _(u"Can't read from printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e)))
            return None
        except socket.error as e:
            print _(u"Can't read from printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror))
            return None
        except OSError as e:
            if e.errno == errno.EAGAIN:  # Not a real error, no data was available
                return ""
            print _(u"Can't read from printer (disconnected?) (OS Error {0}): {1}").format(e.errno, e.strerror)
            return None
예제 #2
0
    def _readline(self):
        try:
            try:
                line = self.printer.readline()
                if self.printer_tcp and not line:
                    raise OSError(-1, "Read EOF from socket")
            except socket.timeout:
                return ""

            if len(line) > 1:
                self.log.append(line)
                if self.recvcb:
                    try: self.recvcb(line)
                    except: pass
                if self.loud: logging.info("RECV: %s" % line.rstrip())
            return line
        except SelectError as e:
            if 'Bad file descriptor' in e.args[1]:
                self.logError(_(u"Can't read from printer (disconnected?) (SelectError {0}): {1}").format(e.errno, decode_utf8(e.strerror)))
                return None
            else:
                self.logError(_(u"SelectError ({0}): {1}").format(e.errno, decode_utf8(e.strerror)))
                raise
        except SerialException as e:
            self.logError(_(u"Can't read from printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e))))
            return None
        except socket.error as e:
            self.logError(_(u"Can't read from printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror)))
            return None
        except OSError as e:
            if e.errno == errno.EAGAIN:  # Not a real error, no data was available
                return ""
            self.logError(_(u"Can't read from printer (disconnected?) (OS Error {0}): {1}").format(e.errno, e.strerror))
            return None
예제 #3
0
 def _send(self, command, lineno=0, calcchecksum=False):
     # Only add checksums if over serial (tcp does the flow control itself)
     if calcchecksum and not self.printer_tcp:
         prefix = "N" + str(lineno) + " " + command
         command = prefix + "*" + str(self._checksum(prefix))
         if "M110" not in command:
             self.sentlines[lineno] = command
     if self.printer:
         self.sent.append(command)
         # run the command through the analyzer
         gline = None
         try:
             gline = self.analyzer.append(command, store=False)
         except:
             logging.warning(
                 _("Could not analyze command %s:") % command + "\n" +
                 traceback.format_exc())
         if self.loud:
             logging.info("SENT: %s" % command)
         if self.sendcb:
             try:
                 self.sendcb(command, gline)
             except:
                 pass
         try:
             self.printer.write(str(command + "\n"))
             if self.printer_tcp: self.printer.flush()
             self.writefailures = 0
         except socket.error as e:
             self.logError(
                 _(u"Can't write to printer (disconnected?) (Socket error {0}): {1}"
                   ).format(e.errno, decode_utf8(e.strerror)))
             self.writefailures += 1
         except SerialException as e:
             self.logError(
                 _(u"Can't write to printer (disconnected?) (SerialException): {0}"
                   ).format(decode_utf8(str(e))))
             self.writefailures += 1
         except RuntimeError as e:
             self.logError(
                 _(u"Socket connection broken, disconnected. ({0}): {1}").
                 format(e.errno, decode_utf8(e.strerror)))
             self.writefailures += 1
예제 #4
0
 def _send(self, command, lineno=0, calcchecksum=False):
     if calcchecksum:
         prefix = "N" + str(lineno) + " " + command
         command = prefix + "*" + str(self._checksum(prefix))
         if "M110" not in command:
             self.sentlines[lineno] = command
     if self.printer:
         self.sent.append(command)
         # run the command through the analyzer
         try:
             self.analyzer.Analyze(command)
         except:
             print "Warning: could not analyze command %s:" % command
             traceback.print_exc(file=sys.stdout)
         if self.loud:
             print "SENT:", command
         if self.sendcb:
             try:
                 self.sendcb(command)
             except:
                 pass
         try:
             self.printer.write(str(command + "\n"))
             if self.printer_tcp: self.printer.flush()
             self.writefailures = 0
         except socket.error as e:
             print _(
                 u"Can't write to printer (disconnected?) (Socket error {0}): {1}"
             ).format(e.errno, decode_utf8(e.strerror))
             self.writefailures += 1
         except SerialException as e:
             print _(
                 u"Can't write to printer (disconnected?) (SerialException): {0}"
             ).format(decode_utf8(str(e)))
             self.writefailures += 1
         except RuntimeError as e:
             print _(u"Socket connection broken, disconnected. ({0}): {1}"
                     ).format(e.errno, decode_utf8(e.strerror))
             self.writefailures += 1
예제 #5
0
 def _send(self, command, lineno=0, calcchecksum=False):
     if calcchecksum:
         prefix = "N" + str(lineno) + " " + command
         command = prefix + "*" + str(self._checksum(prefix))
         if "M110" not in command:
             self.sentlines[lineno] = command
     if self.printer:
         self.sent.append(command)
         # run the command through the analyzer
         try:
             self.analyzer.Analyze(command)
         except:
             print "Warning: could not analyze command %s:" % command
             traceback.print_exc(file=sys.stdout)
         if self.loud:
             print "SENT:", command
         if self.sendcb:
             try:
                 self.sendcb(command)
             except:
                 pass
         try:
             self.printer.write(str(command + "\n"))
             if self.printer_tcp:
                 self.printer.flush()
             self.writefailures = 0
         except socket.error as e:
             print _(u"Can't write to printer (disconnected?) (Socket error {0}): {1}").format(
                 e.errno, decode_utf8(e.strerror)
             )
             self.writefailures += 1
         except SerialException as e:
             print _(u"Can't write to printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e)))
             self.writefailures += 1
         except RuntimeError as e:
             print _(u"Socket connection broken, disconnected. ({0}): {1}").format(e.errno, decode_utf8(e.strerror))
             self.writefailures += 1
예제 #6
0
 def _send(self, command, lineno = 0, calcchecksum = False):
     # Only add checksums if over serial (tcp does the flow control itself)
     if calcchecksum and not self.printer_tcp:
         prefix = "N" + str(lineno) + " " + command
         command = prefix + "*" + str(self._checksum(prefix))
         if "M110" not in command:
             self.sentlines[lineno] = command
     if self.printer:
         self.sent.append(command)
         # run the command through the analyzer
         gline = None
         try:
             gline = self.analyzer.append(command, store = False)
         except:
             logging.warning(_("Could not analyze command %s:") % command +
                             "\n" + traceback.format_exc())
         if self.loud:
             logging.info("SENT: %s" % command)
         if self.sendcb:
             try: self.sendcb(command, gline)
             except: pass
         try:
             self.printer.write(str(command + "\n"))
             if self.printer_tcp: self.printer.flush()
             self.writefailures = 0
         except socket.error as e:
             self.logError(_(u"Can't write to printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror)))
             self.writefailures += 1
         except SerialException as e:
             self.logError(_(u"Can't write to printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e))))
             self.writefailures += 1
         except RuntimeError as e:
             self.logError(_(u"Socket connection broken, disconnected. ({0}): {1}").format(e.errno, decode_utf8(e.strerror)))
             self.writefailures += 1