Skip to content

Commit

Permalink
Check if device is available
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Dec 21, 2020
1 parent 07dce0c commit e734eac
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 29 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Supported devices:
* [ANTUSB2 Stick](http://www.thisisant.com/developer/components/antusb2/) (0fcf:1008: Dynastream Innovations, Inc.)
* [ANTUSB-m Stick](http://www.thisisant.com/developer/components/antusb-m/) (0fcf:1009: Dynastream Innovations, Inc.)

Warning: the [Cycplus ANT Stick](https://www.cycplus.com/products/ant-usb-stick-u1) is not compatible, even though it uses the same VID/PID as the ANTUSB2 Stick.

## Running on Windows

* Download the [standalone executable](https://github.com/oldnapalm/vpower/releases/latest)
Expand All @@ -55,12 +57,4 @@ Supported devices:
* Open Command Prompt, CD to the python-ant repo directory and run ``python setup.py install``
* Run ``pip install configparser pywin32``
* Clone or download this repo
* CD to the repo directory and run ``python vpower.py``

## Troubleshooting

* USBError: could not claim interface
* Make sure the device is not in use by other app
* Unplug and replug the ANT+ stick
* Stuck on "Starting ANT node"
* Unplug and replug the ANT+ stick
* CD to the repo directory and run ``python vpower.py`` (or double click `vpower.py` if you installed the Python Launcher)
14 changes: 10 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ def disable_event():
pass

try:
devs = find(find_all=True)
devs = find(find_all=True, idVendor=0x0fcf)
for dev in devs:
if dev.idVendor == 0x0fcf and dev.idProduct in [0x1008, 0x1009]:
if dev.idProduct in [0x1008, 0x1009]:
stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct, address=dev.address)
try:
stick.open()
except:
print("ANT device %s not available" % dev.address)
continue
stick.close()
break
else:
print("No ANT device found")
print("No ANT devices available")
if getattr(sys, 'frozen', False):
input()
sys.exit()

stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct)
antnode = node.Node(stick)
print("Starting ANT node")
antnode.start()
Expand Down
14 changes: 10 additions & 4 deletions cadence.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,23 @@ def on_exit(sig, func=None):
win32api.SetConsoleCtrlHandler(on_exit, True)

try:
devs = find(find_all=True)
devs = find(find_all=True, idVendor=0x0fcf)
for dev in devs:
if dev.idVendor == 0x0fcf and dev.idProduct in [0x1008, 0x1009]:
if dev.idProduct in [0x1008, 0x1009]:
stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct, address=dev.address)
try:
stick.open()
except:
print("ANT device %s not available" % dev.address)
continue
stick.close()
break
else:
print("No ANT device found")
print("No ANT devices available")
if getattr(sys, 'frozen', False):
input()
sys.exit()

stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct)
antnode = node.Node(stick)
print("Starting ANT node")
antnode.start()
Expand Down
14 changes: 10 additions & 4 deletions heartrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,23 @@ def heart_rate_data(computed_heartrate, event_time_ms, rr_interval_ms):
last = t

try:
devs = find(find_all=True)
devs = find(find_all=True, idVendor=0x0fcf)
for dev in devs:
if dev.idVendor == 0x0fcf and dev.idProduct in [0x1008, 0x1009]:
if dev.idProduct in [0x1008, 0x1009]:
stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct, address=dev.address)
try:
stick.open()
except:
print("ANT device %s not available" % dev.address)
continue
stick.close()
break
else:
print("No ANT device found")
print("No ANT devices available")
if getattr(sys, 'frozen', False):
input()
sys.exit()

stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct)
antnode = node.Node(stick)
print("Starting ANT node")
antnode.start()
Expand Down
14 changes: 10 additions & 4 deletions row.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,23 @@ def on_exit(sig, func=None):
print("Connected to erg")

# Starting ANT node
devs = find(find_all=True)
devs = find(find_all=True, idVendor=0x0fcf)
for dev in devs:
if dev.idVendor == 0x0fcf and dev.idProduct in [0x1008, 0x1009]:
if dev.idProduct in [0x1008, 0x1009]:
stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct, address=dev.address)
try:
stick.open()
except:
print("ANT device %s not available" % dev.address)
continue
stick.close()
break
else:
print("No ANT device found")
print("No ANT devices available")
if getattr(sys, 'frozen', False):
input()
sys.exit()

stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct)
antnode = node.Node(stick)
print("Starting ANT node")
antnode.start()
Expand Down
14 changes: 10 additions & 4 deletions vpower.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,23 @@ def on_exit(sig, func=None):
try:
print("Using " + POWER_CALCULATOR.__class__.__name__)

devs = find(find_all=True)
devs = find(find_all=True, idVendor=0x0fcf)
for dev in devs:
if dev.idVendor == 0x0fcf and dev.idProduct in [0x1008, 0x1009]:
if dev.idProduct in [0x1008, 0x1009]:
stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct, address=dev.address)
try:
stick.open()
except:
print("ANT device %s not available" % dev.address)
continue
stick.close()
break
else:
print("No ANT device found")
print("No ANT devices available")
if getattr(sys, 'frozen', False):
input()
sys.exit()

stick = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=dev.idProduct)
antnode = node.Node(stick)
print("Starting ANT node")
antnode.start()
Expand Down

0 comments on commit e734eac

Please sign in to comment.