Merge pull request #249 from ajd4096/experimental-send-wait-timeout
Add optional wait timeout in milliseconds to printcore send, send_nowmaster
commit
510b7db655
19
printcore.py
19
printcore.py
|
@ -48,6 +48,7 @@ class printcore():
|
||||||
self.onlinecb=None#impl ()
|
self.onlinecb=None#impl ()
|
||||||
self.loud=False#emit sent and received lines to terminal
|
self.loud=False#emit sent and received lines to terminal
|
||||||
self.greetings=['start','Grbl ']
|
self.greetings=['start','Grbl ']
|
||||||
|
self.wait=0# default wait period for send(), send_now()
|
||||||
if port is not None and baud is not None:
|
if port is not None and baud is not None:
|
||||||
#print port, baud
|
#print port, baud
|
||||||
self.connect(port, baud)
|
self.connect(port, baud)
|
||||||
|
@ -193,7 +194,7 @@ class printcore():
|
||||||
self.printing=True
|
self.printing=True
|
||||||
Thread(target=self._print).start()
|
Thread(target=self._print).start()
|
||||||
|
|
||||||
def send(self,command):
|
def send(self,command,wait=0):
|
||||||
"""Adds a command to the checksummed main command queue if printing, or sends the command immediately if not printing
|
"""Adds a command to the checksummed main command queue if printing, or sends the command immediately if not printing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -202,11 +203,18 @@ class printcore():
|
||||||
else:
|
else:
|
||||||
while not self.clear:
|
while not self.clear:
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
if (wait == 0 and self.wait > 0):
|
||||||
|
wait = self.wait
|
||||||
|
if (wait > 0)
|
||||||
|
self.clear=False
|
||||||
self._send(command,self.lineno,True)
|
self._send(command,self.lineno,True)
|
||||||
self.lineno+=1
|
self.lineno+=1
|
||||||
|
while ((wait > 0) and not self.clear):
|
||||||
|
time.sleep(0.001)
|
||||||
|
wait-=1
|
||||||
|
|
||||||
|
|
||||||
def send_now(self,command):
|
def send_now(self,command,wait=0):
|
||||||
"""Sends a command to the printer ahead of the command queue, without a checksum
|
"""Sends a command to the printer ahead of the command queue, without a checksum
|
||||||
"""
|
"""
|
||||||
if(self.online):
|
if(self.online):
|
||||||
|
@ -215,7 +223,14 @@ class printcore():
|
||||||
else:
|
else:
|
||||||
while not self.clear:
|
while not self.clear:
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
if (wait == 0 and self.wait > 0):
|
||||||
|
wait = self.wait
|
||||||
|
if (wait > 0)
|
||||||
|
self.clear=False
|
||||||
self._send(command)
|
self._send(command)
|
||||||
|
while ((wait > 0) and not self.clear):
|
||||||
|
time.sleep(0.001)
|
||||||
|
wait-=1
|
||||||
#callback for command sent
|
#callback for command sent
|
||||||
else:
|
else:
|
||||||
print "Not connected to printer."
|
print "Not connected to printer."
|
||||||
|
|
Loading…
Reference in New Issue