Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion can/interfaces/socketcan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def pack_filters(can_filters: Optional[typechecking.CanFilters] = None) -> bytes
return struct.pack(can_filter_fmt, *filter_data)


_PATTERN_CAN_INTERFACE = re.compile(r"v?can\d+")
_PATTERN_CAN_INTERFACE = re.compile(r"(sl|v|vx)?can\d+")


def find_available_interfaces() -> Iterable[str]:
Expand Down
22 changes: 22 additions & 0 deletions doc/interfaces/socketcan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ existing ``can0`` interface with a bitrate of 1MB:

sudo ip link set can0 up type can bitrate 1000000

CAN over Serial / SLCAN
~~~~~~~~~~~~~~~~~~~~~~~

SLCAN adapters can be used directly via :doc:`/interfaces/slcan`, or
via :doc:`/interfaces/socketcan` with some help from the ``slcand`` utility
which can be found in the `can-utils <https://github.com/linux-can/can-utils>`_ package.

To create a socketcan interface for an SLCAN adapter run the following:

.. code-block:: bash

slcand -f -o -c -s5 /dev/ttyAMA0
ip link set up slcan0

Names of the interfaces created by ``slcand`` match the ``slcan\d+`` regex.
If a custom name is required, it can be specified as the last argument. E.g.:

.. code-block:: bash

slcand -f -o -c -s5 /dev/ttyAMA0 can0
ip link set up can0

.. _socketcan-pcan:

PCAN
Expand Down
4 changes: 4 additions & 0 deletions test/open_vcan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
modprobe vcan
ip link add dev vcan0 type vcan
ip link set up vcan0 mtu 72
ip link add dev vxcan0 type vcan
ip link set up vxcan0 mtu 72
ip link add dev slcan0 type vcan
ip link set up slcan0 mtu 72
6 changes: 4 additions & 2 deletions test/test_socketcan_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def test_find_available_interfaces(self):
result = list(find_available_interfaces())
self.assertGreaterEqual(len(result), 0)
for entry in result:
self.assertRegex(entry, r"v?can\d+")
self.assertRegex(entry, r"(sl|v|vx)?can\d+")
if TEST_INTERFACE_SOCKETCAN:
self.assertGreaterEqual(len(result), 1)
self.assertGreaterEqual(len(result), 3)
self.assertIn("vcan0", result)
self.assertIn("vxcan0", result)
self.assertIn("slcan0", result)


if __name__ == "__main__":
Expand Down