Skip to content

Commit

Permalink
Put exception protection in setDTR() to avoid fake serial connections
Browse files Browse the repository at this point in the history
  • Loading branch information
vlachoudis committed Jun 23, 2016
1 parent cf01eb7 commit 04d5a64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ def open(self, device, baudrate):
xonxoff=False,
rtscts=False)
# Toggle DTR to reset Arduino
self.serial.setDTR(0)
try:
self.serial.setDTR(0)
except IOError:
pass
time.sleep(1)
CNC.vars["state"] = CONNECTED
CNC.vars["color"] = STATECOLOR[CNC.vars["state"]]
Expand All @@ -437,7 +440,10 @@ def open(self, device, baudrate):
# toss any data already received, see
# http://pyserial.sourceforge.net/pyserial_api.html#serial.Serial.flushInput
self.serial.flushInput()
self.serial.setDTR(1)
try:
self.serial.setDTR(1)
except IOError:
pass
time.sleep(1)
self.serial.write(b"\r\n\r\n")
self._gcount = 0
Expand Down Expand Up @@ -665,7 +671,7 @@ def runEnded(self):
#----------------------------------------------------------------------
# Purge the buffer of the controller. Unfortunately we have to perform
# a reset to clear the buffer of the controller
#----------------------------------------------------------------------
#---------------------------------------------------------------------
def purgeController(self):
time.sleep(1)
# remember and send all G commands
Expand Down
8 changes: 8 additions & 0 deletions bCNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,13 @@ def run(self, lines=None):
# return
self.statusbar.setLimits(0, 9999)
self.statusbar.setProgress(0,0)

#class MyQueue:
# def put(self,line):
# print ">>>",line
#self._paths = self.gcode.compile(MyQueue(), self.checkStop)
#return

self._paths = self.gcode.compile(self.queue, self.checkStop)
if self._paths is None:
self.emptyQueue()
Expand All @@ -2061,6 +2068,7 @@ def run(self, lines=None):
_("Not gcode file was loaded"),
parent=self)
return

# reset colors
for ij in self._paths:
if not ij: continue
Expand Down

0 comments on commit 04d5a64

Please sign in to comment.