diff --git a/inkscape_driver/eggbot_scan.py b/inkscape_driver/eggbot_scan.py index 27b81cf..491e616 100644 --- a/inkscape_driver/eggbot_scan.py +++ b/inkscape_driver/eggbot_scan.py @@ -6,5 +6,7 @@ if platform == 'win32': from eggbot_scanwin32 import * elif platform == 'darwin': from eggbot_scanosx import * +elif platform == 'linux2': + from eggbot_scanlinux import * else: from eggbot_scanposix import * diff --git a/inkscape_driver/eggbot_scanlinux.py b/inkscape_driver/eggbot_scanlinux.py new file mode 100644 index 0000000..c9346a5 --- /dev/null +++ b/inkscape_driver/eggbot_scanlinux.py @@ -0,0 +1,39 @@ +import os + +DEV_TREE = '/dev' +USB_DEVICE_TREE = '/sys/bus/usb/devices' + +def findEiBotBoards(): + """Find only those USB devices that declare themselves to be EiBotBoards""" + + # find all USB devices whose product name is 'EiBotBoard' + with os.popen( 'fgrep -l EiBotBoard %s/*/product' % USB_DEVICE_TREE ) as pipe: + for path in [ os.path.split( path )[0] for path in pipe.readlines()]: + device = os.path.split( path )[1] + + # for each device endpoint ... + for dir in os.listdir( path ): + if dir.startswith( device ): + + # find the endpoint that supports tty access + ttydir = os.path.join( USB_DEVICE_TREE, device, dir, 'tty' ) + if os.path.exists( ttydir ): + + # And emit each (the) interface name + for ttyname in os.listdir( ttydir ): + yield os.path.join( DEV_TREE, ttyname ) + +def findPorts(): + for device in os.listdir( DEV_TREE ): + if not device.startswith( 'ttyACM' ): + continue + yield os.path.join( DEV_TREE , device ) + +if __name__ == '__main__': + print "Looking for EiBotBoards" + for port in findEiBotBoards(): + print " ", port + + print "Looking for COM ports" + for port in findPorts(): + print " ", port diff --git a/inkscape_driver/eggbot_scanosx.py b/inkscape_driver/eggbot_scanosx.py index 5c01565..b8f0ad4 100644 --- a/inkscape_driver/eggbot_scanosx.py +++ b/inkscape_driver/eggbot_scanosx.py @@ -4,8 +4,7 @@ def findEiBotBoards(): usbdata = os.popen( '/usr/sbin/system_profiler SPUSBDataType' ).read() tokens = re.split( 'EiBotBoard', usbdata ) for t in tokens[1:]: - match = re.match( '.*?Location ID: 0x([0-9a-fA-F]+).*', t, - re.M | re.S ) + match = re.match( '.*?Location ID: 0x([0-9a-fA-F]+).*', t, re.M | re.S ) if match != None: locid = int( match.group( 1 ), 16 ) yield '/dev/cu.usbmodem%x' % ( ( locid >> 16 ) + 1 )