Commit 1bad79fd authored by Kliment Yanev's avatar Kliment Yanev

Made IP connection errors emit the same kind of error as serial connection errors.

parent b99aa3a7
...@@ -451,21 +451,22 @@ class printcore(): ...@@ -451,21 +451,22 @@ class printcore():
if self.sendcb: if self.sendcb:
try: self.sendcb(command) try: self.sendcb(command)
except: pass except: pass
try:
# If the printer is connected via Ethernet, use send # If the printer is connected via Ethernet, use send
if is_socket(self.printer): if is_socket(self.printer):
msg = str(command+"\n") msg = str(command+"\n")
totalsent = 0 totalsent = 0
while totalsent < len(msg): while totalsent < len(msg):
sent = self.printer.send(msg[totalsent:]) sent = self.printer.send(msg[totalsent:])
if sent == 0: if sent == 0:
raise RuntimeError("socket connection broken") raise RuntimeError("socket connection broken")
totalsent = totalsent + sent totalsent = totalsent + sent
else: else:
try:
self.printer.write(str(command+"\n")) self.printer.write(str(command+"\n"))
except SerialException, e: except SerialException, e:
print "Can't write to printer (disconnected?)." print "Can't write to printer (disconnected?)."
except RuntimeError, e:
print "Socket connection broken, disconnected."
if __name__ == '__main__': if __name__ == '__main__':
baud = 115200 baud = 115200
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment