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.findcan be used to get aDeviceobject:dev = Device.find(ean=EAN('67890-1'))
Device.findsupports searching for devices based on a variety of information, and will return aDeviceobject 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,
Deviceobjects 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
Deviceobjects can be checked for equality (whether they refer to the same device) and be converted to astr.Device.probe_infocan 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:canlib.Channel–Device.channelcanlib.ChannelData–Device.channel_datacanlib.IOControl–Device.iocontrolkvmlib.Memorator–Device.memoratorlinlib.Channel–Device.lin_masterandDevice.lin_slave
Variables: - 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[source]¶ A
Channelfor this device’s first channelThe experimental argument
_chan_no_on_cardmay be given, theintprovided will be added (without any verifications) to thechannel_numberwhere 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_cardattribute, you must make sure that the card actually have the assumed number of local channels. Using this argument with a too largeintcould return a channel belonging to a different device.Arguments to
openChannelother than the channel number can be passed to this function.Changed in version 1.13: Added argument
_chan_no_on_cardDeprecated since version 1.16: Use
open_channelinstead
-
channel_data()[source]¶ A
canlib.ChannelDatafor 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.CanNotFoundexception 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.
- channel_number (
-
iocontrol()[source]¶ A
canlib.IOControlfor 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.Channelmaster for this device’s first channelArguments to
linlib.openMasterother than the channel number can be passed to this function.
-
lin_slave(*args, **kwargs)[source]¶ A
linlib.Channelslave for this device’s first channelArguments to
linlib.openSlaveother than the channel number can be passed to this function.
-
memorator(*args, **kwargs)[source]¶ A
kvmlib.Memoratorfor this device’s first channelArguments to
kvmlib.openDeviceother than the channel number can be passed to this function.
-
open_channel(chan_no_on_card=0, **kwargs)[source]¶ A
canlib.Channelfor this device’s first channelThe parameter
chan_no_on_cardwill be added (without any verifications) to thechannel_numberwhere 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_cardparameter, you must make sure that the card actually have the assumed number of local channels. Using this parameter with a too largeintcould 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
strwith 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.RemoteDevicefor this deviceArguments to
kvrlib.openDeviceother than the channel number can be passed to this function.
-
serial¶