SocketCAN (ctypes)¶
socketcan_ctypes.py is a ctypes wrapper class around libc. It contains replications of constants and structures found in various linux header files. With Python 3.3, much of the functionality of this library is likely to be available natively in the Python socket module.
Bus¶
-
class
can.interfaces.socketcan.
SocketcanCtypes_Bus
(channel='vcan0', receive_own_messages=False, *args, **kwargs)¶ An implementation of the
can.bus.BusABC
for SocketCAN usingctypes
.
Broadcast-Manager¶
The socketcan_ctypes
interface implements thin wrappers to the linux broadcast manager
socket api. This allows the cyclic transmission of CAN messages at given intervals.
The overhead for periodic message sending is extremely low as all the heavy lifting occurs
within the linux kernel.
Internals¶
createSocket¶
-
can.interfaces.socketcan.socketcan_ctypes.
createSocket
(protocol=1)¶ This function creates a RAW CAN socket.
The socket returned needs to be bound to an interface by calling
bindSocket()
.Parameters: protocol (int) – The type of the socket to be bound. Valid values include CAN_RAW and CAN_BCM Returns: 0 protocol invalid -1 socket creation unsuccessful socketID successful creation
bindSocket¶
-
can.interfaces.socketcan.socketcan_ctypes.
bindSocket
(socketID, channel_name)¶ Binds the given socket to the given interface.
Parameters: - socketID (int) – The ID of the socket to be bound
- channel_name (str) – The interface name to find and bind.
Returns: The error code from the bind call.
0 protocol invalid -1 socket creation unsuccessful
connectSocket
-
can.interfaces.socketcan.socketcan_ctypes.
connectSocket
(socketID, channel_name)¶ Connects the given socket to the given interface.
Parameters: - socketID (int) – The ID of the socket to be bound
- channel_name (str) – The interface name to find and bind.
Returns: The error code from the bind call.