Add a Linux-specific serial port scanner that can detect EiBotBoards.

git-svn-id: https://eggbotcode.googlecode.com/svn/trunk@105 72233254-1b6c-9e9c-5072-401df62706fb
pull/47/head
craig.trader@gmail.com 2010-09-13 03:53:46 +00:00
rodzic 653adb9e3e
commit 6bf570e48f
3 zmienionych plików z 42 dodań i 2 usunięć

Wyświetl plik

@ -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 *

Wyświetl plik

@ -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

Wyświetl plik

@ -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 )