Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Background scanning under python3 via openant

Rank

Total Posts: 27

Joined 2020-01-26

PM

Hi,
I want to scan for Ant+ device numbers under python3. I was able to adapt the python package openant ( https://github.com/Tigge/openant/tree/b6125d1bd4b3f76daa8acac173d9d79b8d364e5f ) by the functionality "enable_extended_messages" and to test it accordingly (see my fork https://gitlab.com/pirower/openant/ ).
Unfortunately I wasn't able to enable background scanning via
channel node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE,0x01
as I always run into a timed out error.

Here is a part of my code for the script: https://gitlab.com/pirower/openant/-/blob/master/examples/scan.py

In the log file, I discovered that with
DEBUG:ant.base.ant:Write data[a4 03 42 00 00 01 e4] 
I should have set up the channel as a background scanning channel.      
Rank

Total Posts: 27

Joined 2020-01-26

PM

Here is the terminal output

sudo python3 scan.py
Driver available: [<class 'ant.base.driver.SerialDriver'>, <class 'ant.base.driver.USB2Driver'>, <class 'ant.base.driver.USB3Driver'>]
- Using: <class 'ant.base.driver.USB2Driver'>      
Rank

Total Posts: 27

Joined 2020-01-26

PM

And the corresponding log file

DEBUG:ant.base.driver:USB Find device, vendor 0xfcf, product 0x1008
DEBUG:ant.base.driver:USB Config values:
DEBUG:ant.base.driver: Config 1
DEBUG:ant.base.driver: Interface 0, Alt 0
DEBUG:ant.base.driver: Endpoint 129
DEBUG:ant.base.driver: Endpoint 1
DEBUG:ant.base.driver:No kernel driver active
DEBUG:ant.base.driver:UBS Endpoint out: ENDPOINT 0x1: Bulk OUT ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x1 OUT
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0x1, 1
DEBUG:ant.base.driver:UBS Endpoint in: ENDPOINT 0x81: Bulk IN ===============================
bLength : 0x7 (7 bytes)
bDescriptorType : 0x5 Endpoint
bEndpointAddress : 0x81 IN
bmAttributes : 0x2 Bulk
wMaxPacketSize : 0x40 (64 bytes)
bInterval : 0x1, 129
DEBUG:ant.base.ant:Ant runner started
DEBUG:ant.base.ant:Write data: [a4 01 4a 00 ef]
DEBUG:ant.base.ant:Read data: [a4 01 6f 20 ea] (now have [a4 01 6f 20 ea] in buffer)
DEBUG:ant.base.ant:Write data: [a4 09 46 00 b9 a5 21 fb bd 72 c3 45 64]
DEBUG:ant.base.ant:Read data: [a4 03 40 00 46 00 a1] (now have [a4 03 40 00 46 00 a1] in buffer)
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a18a0>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 70, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 70, array('B', [0]))
DEBUG:ant.base.ant:Read data: [a4 03 40 00 42 00 a5] (now have [a4 03 40 00 42 00 a5] in buffer)
DEBUG:ant.base.ant:Write data: [a4 03 42 00 00 01 e4]
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a18a0>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 66, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 66, array('B', [0]))
DEBUG:ant.base.ant:Write data: [a4 05 51 00 00 00 78 00 88]
DEBUG:ant.base.ant:Read data: [a4 03 40 00 51 00 b6] (now have [a4 03 40 00 51 00 b6] in buffer)
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a1858>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 81, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 81, array('B', [0]))
DEBUG:ant.base.ant:Write data: [a4 02 66 00 01 c1]
DEBUG:ant.base.ant:Read data: [a4 03 40 00 66 00 81] (now have [a4 03 40 00 66 00 81] in buffer)
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a18a0>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 102, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 102, array('B', [0]))
DEBUG:ant.base.ant:Write data: [a4 02 44 00 ff 1d]
DEBUG:ant.base.ant:Read data: [a4 03 40 00 44 00 a3] (now have [a4 03 40 00 44 00 a3] in buffer)
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a1858>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 68, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 68, array('B', [0]))
DEBUG:ant.base.ant:Write data: [a4 03 43 00 86 1f 7d]
DEBUG:ant.base.ant:Read data: [a4 03 40 00 43 00 a4] (now have [a4 03 40 00 43 00 a4] in buffer)
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a18a0>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 67, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 67, array('B', [0]))
DEBUG:ant.base.ant:Write data: [a4 02 45 00 39 da]
DEBUG:ant.base.ant:Read data: [a4 03 40 00 45 00 a2] (now have [a4 03 40 00 45 00 a2] in buffer)
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a1858>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 69, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 69, array('B', [0]))
DEBUG:ant.base.ant:Write data: [a4 01 4b 00 ee]
DEBUG:ant.base.ant:Read data: [a4 03 40 00 4b 00 ac] (now have [a4 03 40 00 4b 00 ac] in buffer)
DEBUG:ant.easy.filter:wait for message matching <function wait_for_response.<locals>.match at 0xb67a18a0>
DEBUG:ant.easy.filter:looking for matching message in deque([(None, 111, array('B', [32])), (0, 75, array('B', [0]))])
DEBUG:ant.easy.filter: - response found (0, 75, array('B', [0]))
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')
WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, 'Operation timed out')      
Rank

Total Posts: 27

Joined 2020-01-26

PM

I found the error, it has to be:

DEBUG:ant.base.ant:Write data: [a4 04 42 00 00 00 01 e3]

instead of

DEBUG:ant.base.ant:Write data: [a4 03 42 00 00 01 e4]

as the background scanning is set by an optional argument (see 9.5.2.2 Assign Channel of Protocol and Usage Document) (therefore also length = 4 instead of 3)