Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

ANT USB2 stick under Linux

Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

Hi everyone,

We just received some ANT USB2 sticks.

I've posted an example of using the ANT USB2 stick under Linux here:

http://opensource.quarq.us/ant_usb2_stick

The code should be cross-platform to Windows and OS X, at least when pyUSB's known bug on OS X is fixed.      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Is the Garmin USB ANT Stick simply a USB2 Stick-OEM with a Garmin logo? Is the Garmin stick limited to use with Garmin products?      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Hi Mark,

Question about the python scripts you wrote.

Have installed them on OSX, you said that there is a problem. what is that?
Also the quarqd_config file, what should that look like?

If I run the ap2.py script, i get numbers back (sometimes), the ap2s, returns with errors.
See below.

Traceback (most recent call last):
File "ap2s.py", line 40, in <module>
print " ".join(("x"%x for x in ep_in.read(64)))
File "/Library/Python/2.6/site-packages/usb/core.py", line 273, in read
return self.device.read(self.bEndpointAddress, size, self.interface, timeout)
File "/Library/Python/2.6/site-packages/usb/core.py", line 624, in read
self.__get_timeout(timeout)
File "/Library/Python/2.6/site-packages/usb/_debug.py", line 53, in do_trace
return f(*args, **named_args)
File "/Library/Python/2.6/site-packages/usb/backend/libusb10.py", line 483, in bulk_read
timeout)
File "/Library/Python/2.6/site-packages/usb/backend/libusb10.py", line 581, in __read
timeout))
File "/Library/Python/2.6/site-packages/usb/backend/libusb10.py", line 353, in _check
raise USBError(_str_error[retval.value])
usb.core.USBError: Operation timed out


Erik      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Hi,

thanks for your examples!

I'm writing a program in C using libusb1 to access ANT USB2 sticks.
I managed to write the link layer messages to the device and get messages for a successful configuration back.
If i try to receive messages sent from a second device, the thread with libusb_bulk_read does not return any data.

How can i read the transmitted messages from the USB2 stick?

Many thanks in advance!      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Hi Mark,

I am facing some error in "ap2.py" & "ap2s.py". I have updated my system environment as per required like libusb 1.0 ,pyusb 1.0 and python 2.6.6

but getting the below error.

Error:
File "ap2.py", line 21, in <module> dev.get_interface_altsetting(), # first interface
AttributeError: 'Device' object has no attribute 'get_interface_altsetting

In forums, somewhere I read that "get_interface_altsetting()" is deprecated ,if it so then please suggest what are the others methods that I can use in place of it "get_interface_altsetting()".

Please let me know how to fix this issues.      
Rank

Total Posts: 1

Joined 2011-03-08

PM

Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

pb wrote:
Is the Garmin USB ANT Stick simply a USB2 Stick-OEM with a Garmin logo? Is the Garmin stick limited to use with Garmin products?


As far as I can tell, all the USB2 sticks are the same inside.      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Hi

I done the suggested changes in "ap2.py" but again facing the some issues.

cfg = dev.get_active_configuration() giving me Segmentation fault error in "ap2.py".

Please help me out if any one have solution for this issues.      
Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

shailendra wrote:
Hi

I done the suggested changes in "ap2.py" but again facing the some issues.

cfg = dev.get_active_configuration() giving me Segmentation fault error in "ap2.py".

Please help me out if any one have solution for this issues.


"Segmentation fault" means the Python interpreter has crashed. It should never happen in Python. It is a library bug, and you should ask on the pyusb forum, mailing list, or bug tracker.      
Rank

Total Posts: 1

Joined 0

PM

It's segfaulting because it's trying to get the configuration, even though it hasn't been set yet. This is a pyusb issue, because it's passing None to get_configuration, which is what causes the crash (it should throw an error to warn you to set configuration first). However, this can be worked around by simply calling dev.set_configuration() after opening the device, before getting the endpoints. I tried this on ubuntu 10.10 (along with updating the endpoint find calls), works fine now.

BTW, I've got an abstracted ANT/ANT+ python library I'm working on now, it's a little more full featured than what you've got there, just to cover the specifics of the protocol. It's currently bundled in with my fitbit library, but I'll be dividing them out soon:

http://www.github.com/qdot/libfitbit/

Just look in the python directory.      
Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

from the Wattage mailing list:

It has been reported for Ubuntu that running the following command
sudo modprobe usbserial vendor=0x0fcf product=0x1008 
will make the Antstick show up as ttyUSB0 and you can run quarqd


To make the change permanentyou can do 

echo 
"options usbserial vendor=0x0fcf product=0x1008" > /etc/modprobe.d/ant-usb2.conf 

(do it as rootsudo -s makes you root

If, 
like meyou have a bunch of different USB->serial devicesyou might want to give the stick a consistent filename

echo 
'SUBSYSTEM=="tty" ACTION=="add" ATTRS{idProduct}=="1008" ATTRS{idVendor}=="0fcf" SYMLINK+="ttyANT"' > /etc/udev/rules.d/10-antstick.rules 

(do it as rootall on a line). 

Then use "/dev/ttyANT" for $ANT_TTY instead of "/dev/ttyUSB0" or whatever
     
Rank

Total Posts: 3

Joined 2013-09-23

PM

Hi markrages ,
When I execute the file ap2s.py, error occurs: "ImportError: no module named usb.core". The os is Ubuntu 12.04.
Please give me one hand. Thank you very much.      
Avatar
RankRank

Total Posts: 40

Joined 2009-03-20

PM

To get Ant sticks working under Linux, you will need some udev rules.

You can take the script at http://opensource.quarq.us/headunit_test/99-antstick.rules and copy it into /etc/udev/rules.d.

This gives the Ant sticks a consistent naming, so the first Ant stick will be /dev/ttyANT0, etc.

The stick can be opened as a normal serial port, so in Python you would say:

import serial
  ant_fd
=serial.Serial('/dev/ttyANT0'


Then read/write Ant packets from ant_fd.

This is better than dealing with linking libusb or dealing with vendor drivers.

I have tested this with:

Original (ca. 2006) Ant dev box
Smaller Ant devkit.
Original Garmin USB stick.
Suunto Movestick (nRF24AP2-USB based)
Dynastream USB-M stick
Homemade USB stick with AT3 baseband and 20 dBm power amplifer.
Garmin USB2 stick

edit:

This udev rule is all you need. Nothing in /etc/modprobe.d, or manually loading modules or anything.