PymateIO-CAN-Scan

From pymate.io wiki
Jump to navigation Jump to search


Introduction

When using the Pymate Core board, the pymate.tools library expose the scan_can() function.

The scan_can() function can query the Pymate Expansions through the CAN bus to grab their configuration.

The scan result is printed to the standard output (so visible in the REPL session).

Scan everything

The simplest is to scan the entire board_id space (1..127).

The following example shows the only expansion that responded on the bus.

>>> from pymate.tool import scan_can
>>> scan_can()
--- Pymate CAN scanner ---
scan 1...
----------------------------------------
Board_ID          : 0x4 (4)
CanIO API version : 4
CanServer version : 0.2.1
machine uname     : PYMATE 16ADI16DO V0.1.0a with STM32F411RE
#CANIO_IN        : 16 (alternate: 0)
#CANIO_ADC       : 16 (alternate: 0)
#CANIO_OUT_PP    : 16 (alternate: 2)
----------------------------------------
scan 10...
scan 20...
scan 30...
scan 40...
scan 50...
scan 60...
scan 70...
scan 80...
scan 90...
scan 100...
scan 110...
scan 120...
scan 127...

Scan a range

Is is also possible to scan a smaller board_id range. This is done by adding parameter scan_can(from_id, to_id) to the call.

The following example scans from_id=4 to to_id=4

>>> from pymate.tool import scan_can
>>> scan_can(4,4)
--- Pymate CAN scanner ---
----------------------------------------
Board_ID          : 0x4 (4)
CanIO API version : 4
CanServer version : 0.2.1
machine uname     : PYMATE 16ADI16DO V0.1.0a with STM32F411RE
#CANIO_IN        : 16 (alternate: 0)
#CANIO_ADC       : 16 (alternate: 0)
#CANIO_OUT_PP    : 16 (alternate: 2)
----------------------------------------
>>>

Errors

Errors may occurs while scanning the CAN bus.

The kind of error may provide useful information

OSError 110

This error occurs when the CAN is an open loop.

>>> from pymate.tool import scan_can
>>> scan_can()
--- Pymate CAN scanner ---
scan 1...
Oups! Getting error while querying 1! OSError(110,)
Oups! Getting error while querying 2! OSError(110,)
Oups! Getting error while querying 3! OSError(110,)
Oups! Getting error while querying 4! OSError(110,)
Oups! Getting error while querying 5! OSError(110,)
Oups! Getting error while querying 6! OSError(110,)
Oups! Getting error while querying 7! OSError(110,)
Oups! Getting error while querying 8! OSError(110,)
Oups! Getting error while querying 9! OSError(110,)
scan 10...
Oups! Getting error while querying 10! OSError(110,)
....
....
....
Oups! Getting error while querying 125! OSError(110,)
Oups! Getting error while querying 126! OSError(110,)
scan 127...
Oups! Getting error while querying 127! OSError(110,)


PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO