Skip to content

Commit e276670

Browse files
committed
Documentation refactoring
- Tried to explain at a much higher level what the library is about - Most of the readme contents has been integrated into the docs. - Added pages for configuration and installation
1 parent 865cd27 commit e276670

30 files changed

+294
-245
lines changed

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Bruno Pennati
1616
Jack Jester-Weinstein
1717
Joshua Villyard
1818
Giuseppe Corbelli <[email protected]>
19+
Christian Sandberg

README

Lines changed: 17 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -19,169 +19,30 @@ python-can
1919
The **C**\ ontroller **A**\ rea **N**\ etwork is a bus standard designed
2020
to allow microcontrollers and devices to communicate with each other. It
2121
has priority based bus arbitration, reliable deterministic
22-
communication. It is used in cars, trucks, wheelchairs and more. See
23-
`wikipedia <http://en.wikipedia.org/wiki/CAN_bus>`__ for more info.
22+
communication. It is used in cars, trucks, boats, wheelchairs and more.
2423

25-
This module provides controller area network support for
26-
`Python <http://python.org/download/>`__.
24+
The ``can`` package provides controller area network support for
25+
Python developers; providing `common abstractions to
26+
different hardware devices`, and a suite of utilities for sending and receiving
27+
messages on a can bus.
2728

28-
Configuration File
29-
------------------
29+
The library supports Python 2.7, Python 3.3+ and runs on Mac, Linux and Windows.
3030

31-
In order to use this library a CAN interface needs to be specified. A
32-
method to do this is to create a configuration file.
33-
On Linux systems the config file is searched in the following paths:
31+
You can find more information in the documentation, online at
32+
`python-can.readthedocs.org <https://python-can.readthedocs.org/en/stable/>`__.
3433

35-
1. ``/etc/can.conf``
36-
2. ``$HOME/.can``
37-
3. ``$HOME/.canrc``
3834

39-
On Windows systems the config file is searched in the following paths:
40-
1. ``can.ini`` (current working directory)
41-
2. ``$APPDATA/can.ini``
42-
43-
The configuration file sets the default interface and channel:
44-
45-
::
46-
47-
[default]
48-
interface = <the name of the interface to use>
49-
channel = <the channel to use by default>
50-
51-
Interfaces
35+
Discussion
5236
----------
5337

54-
The interface available are:
55-
56-
kvaser
57-
~~~~~~
58-
59-
`Kvaser <http://www.kvaser.com>`__'s CANLib SDK for Windows (also
60-
available on Linux)
61-
62-
socketcan
63-
~~~~~~~~~
64-
65-
On linux the socketcan interface is exposed via either:
66-
67-
- socketcan\_ctypes
68-
- socketcan\_native
69-
70-
serial
71-
~~~~~~
72-
73-
A text based interface. For example use over bluetooth with
74-
``/dev/rfcomm0``
75-
76-
pcan
77-
~~~~
78-
79-
`Peak-System <http://www.peak-system.com/>`__'s PCAN-Basic API.
80-
81-
IXXAT
82-
~~~~~
83-
84-
`IXXAT <http://www.ixxat.com/>`__'s Virtual CAN Interface V3 SDK ONLY on Windows.
85-
The Linux ECI SDK is currently unsupported.
86-
On Linux some devices are supported with socketcan.
87-
88-
virtual
89-
~~~~~~~
90-
91-
A virtual CAN bus that can be used for automatic tests. Any Bus instances
92-
connecting to the same channel (in the same python program) will get each
93-
others messages.
94-
95-
Installation
96-
------------
97-
98-
GNU/Linux dependencies
99-
----------------------
100-
101-
Reasonably modern Linux Kernels (2.6.25 or newer) have an implementation
102-
of ``socketcan``. This version of python-can will directly use socketcan
103-
if called with Python 3.3 or greater, otherwise that interface is used
104-
via ctypes.
105-
106-
Windows dependencies
107-
--------------------
108-
109-
Kvaser
110-
~~~~~~
111-
112-
To install ``python-can`` using the Kvaser CANLib SDK as the backend:
113-
114-
1. Install the `latest stable release of
115-
Python <http://python.org/download/>`__.
116-
117-
2. Install `Kvaser's latest Windows CANLib
118-
drivers <http://www.kvaser.com/en/downloads.html>`__.
119-
120-
3. Test that Kvaser's own tools work to ensure the driver is properly
121-
installed and that the hardware is working.
122-
123-
PCAN
124-
~~~~
125-
126-
To use the PCAN-Basic API as the backend (which has only been tested
127-
with Python 2.7):
128-
129-
1. Download the latest version of the `PCAN-Basic
130-
API <http://www.peak-system.com/Downloads.76.0.html?>`__.
131-
132-
2. Extract ``PCANBasic.dll`` from the Win32 subfolder of the archive or
133-
the x64 subfolder depending on whether you have a 32-bit or 64-bit
134-
installation of Python.
135-
136-
3. Copy ``PCANBasic.dll`` into the working directory where you will be
137-
running your python script. There is probably a way to install the
138-
dll properly, but I'm not certain how to do that.
139-
140-
Note that PCANBasic API timestamps count seconds from system startup. To
141-
convert these to epoch times, the uptime library is used. If it is not
142-
available, the times are returned as number of seconds from system
143-
startup. To install the uptime library, run ``pip install uptime``.
144-
145-
IXXAT
146-
~~~~~
147-
148-
To install ``python-can`` using the IXXAT VCI V3 SDK as the backend:
149-
150-
1. Install the `latest stable release of
151-
Python <http://python.org/download/>`__.
152-
153-
2. Install `IXXAT's latest Windows VCI V3 SDK
154-
drivers <http://www.ixxat.com/support/file-and-documents-download/drivers/vci-v3-driver-download>`__.
155-
156-
3. Test that IXXAT's own tools (i.e. MiniMon) work to ensure the driver
157-
is properly installed and that the hardware is working.
158-
159-
Install python-can
160-
------------------
161-
162-
You may need to install
163-
`pip <http://www.pip-installer.org/en/latest/installing.html>`__ and
164-
`setuptools <https://pypi.python.org/pypi/setuptools>`__ first.
165-
166-
Two options, install normally with:
167-
168-
::
169-
170-
python setup.py install
171-
172-
Or to do a "development" install of this package to your machine (this
173-
allows you to make changes locally or pull updates from the Mercurial
174-
repository and use them without having to reinstall):
175-
176-
::
177-
178-
python setup.py develop
38+
If you run into bugs, you can file them in our
39+
`issue tracker <https://bitbucket.org/hardbyte/python-can/issues>`__.
17940

180-
On linux you will need ``sudo`` rights.
41+
There is also a `python-can <https://groups.google.com/forum/#!forum/python-can>`__
42+
mailing list for development discussion.
18143

182-
Documentation and Help
183-
----------------------
44+
`Stackoverflow <https://stackoverflow.com/questions/tagged/can+python>`__ has several
45+
questions and answers tagged with ``python+can``.
18446

185-
- The Sphinx documentation for python-can can be viewed online at `python-can.readthedocs.org <https://python-can.readthedocs.org/en/latest/>`__
186-
- Questions can be found on `StackOverflow <https://stackoverflow.com/questions/tagged/can+python>`__ (tagged with python+can)
187-
- `Google groups mailing list <https://groups.google.com/forum/#!forum/python-can>`__
47+
Wherever we interact, we strive to follow the
48+
`Python Community Code of Conduct <https://www.python.org/psf/codeofconduct/>`__.

can/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
"""
22
can is an object-orient Controller Area Network interface module.
3-
4-
Modules include:
5-
6-
:mod:`can.message`
7-
defines the :class:`~can.Message` class which is the
8-
lowest level of OO access to the library.
9-
103
"""
114
import logging
125
log = logging.getLogger('can')
136

147
rc = dict(channel=0)
158

9+
1610
class CanError(IOError):
1711
pass
1812

can/broadcastmanager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def modify_data(self, message):
4747
"""Update the contents of this periodically sent message without altering
4848
the timing.
4949
50-
:param message: The :class:`~can.Message` with new :attr:`Message.data`. Note it must have the same
51-
:attr:`Message.arbitration_id`.
50+
:param message: The :class:`~can.Message` with new :attr:`Message.data`.
51+
Note it must have the same :attr:`~can.Message.arbitration_id`.
5252
"""
5353

5454

can/bus.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(self, channel=None, can_filters=None, **config):
4343
def recv(self, timeout=None):
4444
"""Block waiting for a message from the Bus.
4545
46+
:param float timeout: Seconds to wait for a message.
47+
4648
:return:
4749
None on timeout or a :class:`can.Message` object.
4850
"""
@@ -76,7 +78,7 @@ def __iter__(self):
7678
logger.debug("done iterating over bus messages")
7779

7880
def flush_tx_buffer(self):
79-
"""Used for CAN backends which need to flush their transmit buffer.
81+
"""Used for CAN interfaces which need to flush their transmit buffer.
8082
8183
"""
8284
pass

can/interfaces/interface.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ class Bus(object):
1111
"""
1212
Instantiates a CAN Bus of the given `bustype`, falls back to reading a
1313
configuration file from default locations.
14-
15-
:raises: NotImplementedError if the bustype isn't recognized
16-
1714
"""
1815

1916
@classmethod
2017
def __new__(cls, other, channel=None, *args, **kwargs):
18+
"""
19+
Takes the same arguments as :class:`can.BusABC` with the addition of:
20+
21+
:param kwargs:
22+
Should contain a bustype key with a valid interface name.
2123
24+
:raises: NotImplementedError if the bustype isn't recognized
25+
"""
2226
if 'bustype' in kwargs:
2327
can.rc['interface'] = kwargs['bustype']
2428
del kwargs['bustype']

can/interfaces/pcan.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ def __init__(self, channel, *args, **kwargs):
6060
:param str channel:
6161
The can interface name. An example would be PCAN_USBBUS1
6262
63-
Backend Configuration
64-
---------------------
65-
6663
:param int bitrate:
6764
Bitrate of channel in bit/s.
6865
Default is 500 Kbs

can/interfaces/socketcan_ctypes.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
log.info("Loading socketcan ctypes backend")
1818

1919

20+
if not sys.platform.startswith("win32"):
21+
libc = ctypes.cdll.LoadLibrary(find_library("c"))
22+
log.info("Loading libc with ctypes")
23+
else:
24+
log.warning("libc is unavailable")
25+
libc = None
26+
27+
28+
start_sec = 0
29+
start_usec = 0
30+
SEC_USEC = 1000000
31+
32+
2033
class SocketscanCtypes_Bus(BusABC):
2134
"""
2235
An implementation of the :class:`can.bus.BusABC` for SocketCAN using :mod:`ctypes`.
@@ -78,14 +91,6 @@ def send(self, msg):
7891
return sendPacket(self.socket, msg)
7992

8093

81-
log.debug("Loading libc with ctypes...")
82-
libc = ctypes.cdll.LoadLibrary(find_library("c"))
83-
84-
start_sec = 0
85-
start_usec = 0
86-
SEC_USEC = 1000000
87-
88-
8994
class SOCKADDR(ctypes.Structure):
9095
# See /usr/include/i386-linux-gnu/bits/socket.h for original struct
9196
_fields_ = [("sa_family", ctypes.c_uint16),
@@ -471,7 +476,3 @@ def __init__(self, channel, message, count, initial_period, subsequent_period):
471476
if bytes_sent == -1:
472477
logging.debug("Error sending frame :-/")
473478

474-
if __name__ == "__main__":
475-
socket_id = createSocket(CAN_RAW)
476-
print("Created socket (id = {})".format(socket_id))
477-
print(bindSocket(socket_id))

can/interfaces/socketcan_native.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
"""
77

88
import socket
9-
import fcntl
109
import struct
1110
import logging
1211
from collections import namedtuple
1312
import select
1413

14+
1515
log = logging.getLogger('can.socketcan.native')
1616
#log.setLevel(logging.DEBUG)
1717
log.debug("Loading native socket can implementation")
1818

19+
try:
20+
import fcntl
21+
except ImportError:
22+
log.warning("fcntl not available on this platform")
23+
1924
try:
2025
socket.CAN_RAW
2126
except:
22-
log.error("Note Python 3.3 or later is required to use native socketcan")
23-
raise ImportError()
27+
log.debug("CAN_* properties not found in socket module. These are required to use native socketcan")
2428

2529

2630
from can import Message

can/message.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
class Message(object):
66
"""
77
The :class:`~can.Message` object is used to represent CAN messages for both sending and receiving.
8+
9+
Messages can use extended identifiers, be remote or error frames, and contain data.
810
"""
911

1012
def __init__(self, timestamp=0.0, is_remote_frame=False, extended_id=True,

0 commit comments

Comments
 (0)