Skip to content

Commit

Permalink
Merged second commit of pull request #25 from Alexander Wenger.
Browse files Browse the repository at this point in the history
Comment from the author:
The Cameo will get lost in communication if any new data is send while the machine is busy cutting. Also data chunk size in Silhouette Studio is limited to 3k chars at most and 1k is standard. In response a method "safe_write" was added as a wrapper for the write method to further split large data words (from plot commands) into more digestible chunks. Also inkscape-silhouette will now wait for the cutter to be ready before sending new data.

This results in the cutter returning to the main menu after the complete job is finished (e.g. the nifty option to advance the media into a position where the very handy cross-cutter can be used is offered). Without waiting the machine will only offer to eject the media after cutting.
  • Loading branch information
EtherGraf committed Jan 16, 2017
2 parents d35dfa1 + cd1ef0c commit e002344
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion silhouette/Graphtec.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@ def write(s, string, timeout=10000):
if o != len(string):
raise ValueError('write all %d bytes failed: o=%d' % (len(string), o))

def safe_write(s, string):
"""wrapper for write with special emphasis on not to over-load the cutter with long commands."""
if s.dev is None: return None
# Silhouette Studio uses packet size of maximal 3k, 1k is default
safemaxchunksz = 1024
so = 0
delimiter = "\x03"
while so < len(string):
safechunksz = min(safemaxchunksz, len(string)-so)
candidate = string[so:so+safechunksz]
# strip string candidate of unfinished command at its end
safechunk = candidate[0:(candidate.rfind(delimiter) + 1)]
s.write(string = safechunk)
# wait for cutter to finish current chunk, otherwise blocking might occur
while not s.status() == "ready":
time.sleep(0.05)
so += len(safechunk)

def read(s, size=64, timeout=5000):
"""Low level read method"""
if s.dev is None: return None
Expand Down Expand Up @@ -823,8 +841,9 @@ def plot(s, mediawidth=210.0, mediaheight=297.0, margintop=None,
if not 'ury' in bbox: bbox['ury'] = 0
new_home = "M%d,%d\x03SO0\x03" % (int(0.5+bbox['lly']+end_paper_offset*20.), 0)

# potentially long command string needs extra care
s.safe_write(p)

s.write(p)
s.write(new_home)

return {
Expand Down

0 comments on commit e002344

Please sign in to comment.