Skip to content
Open
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
21 changes: 17 additions & 4 deletions axi/device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import division, print_function

import time
import re

from math import modf
from serial import Serial
Expand Down Expand Up @@ -33,11 +34,23 @@
JOG_ACCELERATION = 16
JOG_MAX_VELOCITY = 8

VID_PID = '04D8:FD92'
VID = 0x04D8
PID = 0xFD92

def get_vid_pid(port):
if hasattr(port, 'vid'):
return (port.vid, port.pid)

match = re.search(r'VID:PID=([0-9A-Fa-f]+):([0-9A-Fa-f]+)', port[2])
if match:
return tuple(int(m, 16) for m in match.groups())

return (None, None)


def find_port():
for port in comports():
if VID_PID in port[2]:
if (VID, PID) == get_vid_pid(port):
return port[0]
return None

Expand Down Expand Up @@ -97,8 +110,8 @@ def readline(self):
return self.serial.readline().strip()

def command(self, *args):
line = ','.join(map(str, args))
self.serial.write(line + '\r')
line = ','.join(map(str, args)) + '\r'
self.serial.write(line.encode())
return self.readline()

# higher level functions
Expand Down
7 changes: 5 additions & 2 deletions axi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ def draw(drawing, progress=True):
# TODO: support drawing, list of paths, or single path
d = Device()
d.enable_motors()
d.run_drawing(drawing, progress)
d.disable_motors()
try:
d.run_drawing(drawing, progress)
finally:
d.disable_motors()
d.pen_up()