Device¶
- class canlib.Device(ean, serial)[source]¶
Class for keeping track of a physical device
This class represents a physical device regardless of whether it is currently connected or not, and on which channel it is connected.
If the device is currently connected,
Device.find
can be used to get aDevice
object:dev = Device.find(ean=EAN('67890-1'))
Device.find
supports searching for devices based on a variety of information, and will return aDevice
object corresponding to the first physical device that matched its arguments. In this case, it would be the first device found with an EAN of 73-30130-67890-1.If the device wanted is not currently connected,
Device
objects can be created with their EAN and serial number (as this is the minimal information needed to uniquely identify a specific device):dev = Device(ean=EAN('67890-1'), serial=42)
Two
Device
objects can be checked for equality (whether they refer to the same device) and be converted to astr
.Device.probe_info
can also be used for a more verbose string representation that queries the device (if connected) for various pieces of information.This class also provides functions for creating the other objects of
canlib
:- Parameters
ean (
canlib.EAN
) – The EAN of this device.serial (
int
) – The serial number of this device.last_channel_number (
int
) – The channel number this device was last found on (used as an optimization; while the device stays on the same CANlib channel there is no need for a linear search of all channels).
New in version 1.6.
- channel(*args, **kwargs)[source]¶
A
Channel
for this device’s first channelThe experimental argument
_chan_no_on_card
may be given, theint
provided will be added (without any verifications) to thechannel_number
where this device was found on, and may thus be used to open a specific local channel on this device.Note
When using the
_chan_no_on_card
attribute, you must make sure that the card actually have the assumed number of local channels. Using this argument with a too largeint
could return a channel belonging to a different device.Arguments to
openChannel
other than the channel number can be passed to this function.Changed in version 1.13: Added argument
_chan_no_on_card
Deprecated since version 1.16: Use
open_channel
instead
- channel_data()[source]¶
A
canlib.ChannelData
for this device’s first channel
- ean¶
- classmethod find(channel_number=None, ean=None, serial=None, channel_name=None)[source]¶
Searches for a specific device
Goes through all CANlib channels (from zero and up), until one of them matches the given arguments. If an argument is omitted or
None
, any device will match it. If no devices matches acanlib.CanNotFound
exception will be raised.- Parameters
channel_number (
int
) – Find a device on this CANlib channel (number).ean (
canlib.EAN
) – Find a device with this EAN.serial (
int
) – Find a device with this serial number.channel_name (
str
) – Find a device with this CANlib channel name.
- iocontrol()[source]¶
A
canlib.IOControl
for this device’s first channel
- issubset(other)[source]¶
Check if device is a subset of other Device.
This can be used to see if a found device fulfills criteria specified in other. Setting an attribute to None is regarded as a Any. This means that e.g. any serial number will be a subset of a serial number specified as None.
New in version 1.9.
- last_channel_number¶
- lin_master(*args, **kwargs)[source]¶
A
linlib.Channel
master for this device’s first channelArguments to
linlib.openMaster
other than the channel number can be passed to this function.
- lin_slave(*args, **kwargs)[source]¶
A
linlib.Channel
slave for this device’s first channelArguments to
linlib.openSlave
other than the channel number can be passed to this function.
- memorator(*args, **kwargs)[source]¶
A
kvmlib.Memorator
for this device’s first channelArguments to
kvmlib.openDevice
other than the channel number can be passed to this function.
- open_channel(chan_no_on_card=0, **kwargs)[source]¶
A
canlib.Channel
for this device’s first channelThe parameter
chan_no_on_card
will be added (without any verifications) to thechannel_number
where this device was found on, and may thus be used to open a specific local channel on this device.Note
When using the
chan_no_on_card
parameter, you must make sure that the card actually have the assumed number of local channels. Using this parameter with a too largeint
could return a channel belonging to a different device.Arguments to
canlib.open_channel
, other than the channel number, can be passed to this function, but must be passed as keyword arguments.New in version 1.16.
- probe_info()[source]¶
A
str
with information about this deviceThis function is useful when the
Device
’sstr()
does not give enough information while debugging. When the device is connected various pieces of information such as the device name, firmware, and driver name is given. When the device is not connected only basic information can be given.Note
Never inspect the return value of this function, only use it for displaying information. Exactly what is shown depends on whether the device is connected or not, and is not guaranteed to stay consistent between versions.
- remote(*args, **kwargs)[source]¶
A
kvrlib.RemoteDevice
for this deviceArguments to
kvrlib.openDevice
other than the channel number can be passed to this function.
- serial¶
connected_devices()¶
- canlib.connected_devices()[source]¶
Get all currently connected devices as
Device
Returns an iterator of
Device
object, one object for every physical device currently connected.New in version 1.6.
Changed in version 1.7:
Device.last_channel_number
will now be set.