Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC ADC 100M 14b 4cha - Testing
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC ADC 100M 14b 4cha - Testing
Commits
a6e17fb6
Commit
a6e17fb6
authored
Jan 10, 2012
by
Matthieu Cattin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto detection of ttyUSB devices based on vendor id and product id module.
parent
1ddf74bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
find_usb_tty.py
test/fmcadc100m14b4cha/python/find_usb_tty.py
+41
-0
No files found.
test/fmcadc100m14b4cha/python/find_usb_tty.py
0 → 100755
View file @
a6e17fb6
#! /usr/bin/env python
# coding: utf8
import
glob
import
os
import
re
class
CttyUSB
:
def
__init__
(
self
):
pass
def
find_usb_tty
(
self
,
vendor_id
=
None
,
product_id
=
None
)
:
tty_devs
=
[]
for
dn
in
glob
.
glob
(
'/sys/bus/usb/devices/*'
)
:
try
:
vid
=
int
(
open
(
os
.
path
.
join
(
dn
,
"idVendor"
))
.
read
()
.
strip
(),
16
)
pid
=
int
(
open
(
os
.
path
.
join
(
dn
,
"idProduct"
))
.
read
()
.
strip
(),
16
)
#print "dn:%s vid:%s pid:%s" % (dn,vid,pid)
if
((
vendor_id
is
None
)
or
(
vid
==
vendor_id
))
and
((
product_id
is
None
)
or
(
pid
==
product_id
))
:
dns
=
glob
.
glob
(
os
.
path
.
join
(
dn
,
os
.
path
.
basename
(
dn
)
+
"*"
))
for
sdn
in
dns
:
for
fn
in
glob
.
glob
(
os
.
path
.
join
(
sdn
,
"*"
))
:
if
re
.
search
(
r"\/ttyUSB[0-9]+$"
,
fn
)
:
tty_devs
.
append
(
"/dev/"
+
os
.
path
.
basename
(
fn
))
pass
pass
pass
pass
except
(
ValueError
,
TypeError
,
AttributeError
,
OSError
,
IOError
)
:
pass
pass
return
tty_devs
#print find_usb_tty()
#print find_usb_tty(0x10c4,0xea60)
#print find_usb_tty(0x0403,0x6001)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment