Skip to content

Commit

Permalink
Check to see if printer is valid before allowing connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
fishbigger committed Dec 16, 2021
1 parent 304c694 commit 42c16f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/apiController.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setPort():
return jsonify({'status': 'success'}), 202
except Exception as e:
print(e)
return abort(500, 'Failed to connect to port. Please check if you printer is connected')
return abort(500, 'Failed to connect to port. Please check if your printer is connected')
else:
return abort(400, 'Please provide a port')

Expand Down
1 change: 1 addition & 0 deletions src/frontend/js/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function reconnect(){
} else {
document.body.style.cursor = "default";
document.getElementById('again').disabled = false;
document.getElementById('refresh').disabled = false;
}
}
)
Expand Down
19 changes: 19 additions & 0 deletions src/printerSerial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,28 @@ def __init__(self, port, baudrate, logname='PRINTER'):
self.ser = serial.Serial(port)
self.ser.baudrate = baudrate
self.ser.timeout = 5
self.ser.write_timeout = 5
time.sleep(0.5)
self.readFromSerial()

try:
self.ser.write(b'M115 \n')
fullOut = ""
for i in range(30):
out = self.ser.readline()
fullOut += str(out)
self.logger.info (out)
if out == b'ok\n':
self.logger.info (f'Printer responded to M115')
break
except Exception as e:
self.logger.error (f'Printer failed to respond to M115')
raise Exception ('Not a printer')

if len(fullOut) < 0:
self.logger.error (f'Printer failed to respond to M115')
raise Exception ('Not a printer')

def readFromSerial(self, forever=False):
while True:
output = self.ser.read_until('\n', 1000)
Expand Down

0 comments on commit 42c16f4

Please sign in to comment.