File: configuration.rst

package info (click to toggle)
python-can 4.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,372 kB
  • sloc: python: 25,840; makefile: 38; sh: 20
file content (162 lines) | stat: -rw-r--r-- 5,592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
.. _configuration:

Configuration
=============


Usually this library is used with a particular CAN interface, this can be
specified in code, read from configuration files or environment variables.

See :func:`can.util.load_config` for implementation.

In Code
-------

The ``can`` object exposes an ``rc`` dictionary which can be used to set
the **interface** and **channel**.

::

    import can
    can.rc['interface'] = 'socketcan'
    can.rc['channel'] = 'vcan0'
    can.rc['bitrate'] = 500000
    from can.interface import Bus

    bus = Bus()


You can also specify the interface and channel for each Bus instance::

    import can

    bus = can.interface.Bus(interface='socketcan', channel='vcan0', bitrate=500000)


Configuration File
------------------

On Linux and macOS systems the config file is searched in the following paths:

#. ``~/can.conf``
#. ``/etc/can.conf``
#. ``$HOME/.can``
#. ``$HOME/.canrc``

On Windows systems the config file is searched in the following paths:

#. ``%USERPROFILE%/can.conf``
#. ``can.ini`` (current working directory)
#. ``%APPDATA%/can.ini``

The configuration file sets the default interface and channel:

::

    [default]
    interface = <the name of the interface to use>
    channel = <the channel to use by default>
    bitrate = <the bitrate in bits/s to use by default>


The configuration can also contain additional sections (or context):

::

    [default]
    interface = <the name of the interface to use>
    channel = <the channel to use by default>
    bitrate = <the bitrate in bits/s to use by default>

    [HS]
    # All the values from the 'default' section are inherited
    channel = <the channel to use>
    bitrate = <the bitrate in bits/s to use. i.e. 500000>

    [MS]
    # All the values from the 'default' section are inherited
    channel = <the channel to use>
    bitrate = <the bitrate in bits/s to use. i.e. 125000>


::

    from can.interface import Bus

    hs_bus = Bus(config_context='HS')
    ms_bus = Bus(config_context='MS')

Environment Variables
---------------------

Configuration can be pulled from these environmental variables:

    * CAN_INTERFACE
    * CAN_CHANNEL
    * CAN_BITRATE
    * CAN_CONFIG

The ``CAN_CONFIG`` environment variable allows to set any bus configuration using JSON.

For example:

``CAN_INTERFACE=socketcan CAN_CONFIG={"receive_own_messages": true, "fd": true}``

.. _interface names:

Interface Names
---------------

Lookup table of interface names:

+---------------------+-------------------------------------+
| Name                | Documentation                       |
+=====================+=====================================+
| ``"canalystii"``    | :doc:`interfaces/canalystii`        |
+---------------------+-------------------------------------+
| ``"cantact"``       | :doc:`interfaces/cantact`           |
+---------------------+-------------------------------------+
| ``"etas"``          | :doc:`interfaces/etas`              |
+---------------------+-------------------------------------+
| ``"gs_usb"``        | :doc:`interfaces/gs_usb`            |
+---------------------+-------------------------------------+
| ``"iscan"``         | :doc:`interfaces/iscan`             |
+---------------------+-------------------------------------+
| ``"ixxat"``         | :doc:`interfaces/ixxat`             |
+---------------------+-------------------------------------+
| ``"kvaser"``        | :doc:`interfaces/kvaser`            |
+---------------------+-------------------------------------+
| ``"neousys"``       | :doc:`interfaces/neousys`           |
+---------------------+-------------------------------------+
| ``"neovi"``         | :doc:`interfaces/neovi`             |
+---------------------+-------------------------------------+
| ``"nican"``         | :doc:`interfaces/nican`             |
+---------------------+-------------------------------------+
| ``"nixnet"``        | :doc:`interfaces/nixnet`            |
+---------------------+-------------------------------------+
| ``"pcan"``          | :doc:`interfaces/pcan`              |
+---------------------+-------------------------------------+
| ``"robotell"``      | :doc:`interfaces/robotell`          |
+---------------------+-------------------------------------+
| ``"seeedstudio"``   | :doc:`interfaces/seeedstudio`       |
+---------------------+-------------------------------------+
| ``"serial"``        | :doc:`interfaces/serial`            |
+---------------------+-------------------------------------+
| ``"slcan"``         | :doc:`interfaces/slcan`             |
+---------------------+-------------------------------------+
| ``"socketcan"``     | :doc:`interfaces/socketcan`         |
+---------------------+-------------------------------------+
| ``"socketcand"``    | :doc:`interfaces/socketcand`        |
+---------------------+-------------------------------------+
| ``"systec"``        | :doc:`interfaces/systec`            |
+---------------------+-------------------------------------+
| ``"udp_multicast"`` | :doc:`interfaces/udp_multicast`     |
+---------------------+-------------------------------------+
| ``"usb2can"``       | :doc:`interfaces/usb2can`           |
+---------------------+-------------------------------------+
| ``"vector"``        | :doc:`interfaces/vector`            |
+---------------------+-------------------------------------+
| ``"virtual"``       | :doc:`interfaces/virtual`           |
+---------------------+-------------------------------------+

Additional interface types can be added via the :ref:`plugin interface`.