Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Machine is Ready; Log Inc Messages Immediately #498

Merged
merged 2 commits into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Connection/serialPortThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SerialPortThread(MakesmithInitFuncs):

'''

machineIsReadyForData = False
machineIsReadyForData = False # Tracks whether last command was acked
lastWriteTime = time.time()
bufferSpace = 256
lengthOfLastLineStack = Queue.Queue()
Expand All @@ -39,6 +39,7 @@ def _write (self, message):

self.bufferSpace = self.bufferSpace - len(message)
self.lengthOfLastLineStack.put(len(message))
self.machineIsReadyForData = False

message = message.encode()
try:
Expand Down Expand Up @@ -90,7 +91,6 @@ def getmessage (self):
#print "port open?:"
#print self.serialInstance.isOpen()
self.lastMessageTime = time.time()
self.data.gcode_queue.put(' ') # send a blank line on startup
self.data.connectionStatus = 1

self._getFirmwareVersion()
Expand All @@ -113,6 +113,7 @@ def getmessage (self):

#Check if a line has been completed
if lineFromMachine == "ok\r\n":
self.machineIsReadyForData = True
if self.lengthOfLastLineStack.empty() != True: #if we've sent lines to the machine
self.bufferSpace = self.bufferSpace + self.lengthOfLastLineStack.get_nowait() #free up that space in the buffer

Expand All @@ -128,14 +129,13 @@ def getmessage (self):
self._write(command)

#send regular instructions to the machine if there are any
if self.bufferSpace == 256:

if self.bufferSpace == 256 and self.machineIsReadyForData:
if self.data.gcode_queue.empty() != True:
command = self.data.gcode_queue.get_nowait() + " "
self._write(command)

#Send the next line of gcode to the machine if we're running a program
if self.bufferSpace == 256:#> len(self.data.gcode[self.data.gcodeIndex]):
if self.bufferSpace == 256 and self.machineIsReadyForData: #> len(self.data.gcode[self.data.gcodeIndex]):
if self.data.uploadFlag:
self._write(self.data.gcode[self.data.gcodeIndex])

Expand Down
3 changes: 2 additions & 1 deletion DataStructures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from kivy.properties import NumericProperty
from kivy.event import EventDispatcher
from DataStructures.logger import Logger
from DataStructures.loggingQueue import LoggingQueue
import Queue

class Data(EventDispatcher):
Expand Down Expand Up @@ -75,7 +76,7 @@ class Data(EventDispatcher):
'''
Queues
'''
message_queue = Queue.Queue()
message_queue = LoggingQueue(logger)
gcode_queue = Queue.Queue()
quick_queue = Queue.Queue()

Expand Down
19 changes: 19 additions & 0 deletions DataStructures/loggingQueue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'''

This module provides a simple addition to the Queue, which is that it logs
puts to the Queue immediately.

'''

from Queue import Queue


class LoggingQueue(Queue, object):
def __init__(self, logger):
self.logger = logger
super(LoggingQueue, self).__init__()

def put(self, msg):
self.logger.writeToLog(msg)
return super(LoggingQueue, self).put(msg)

2 changes: 0 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,6 @@ def runPeriodically(self, *args):
while not self.data.message_queue.empty(): #if there is new data to be read
message = self.data.message_queue.get()

self.data.logger.writeToLog(message)

if message[0] == "<":
self.setPosOnScreen(message)
elif message[0] == "[":
Expand Down