canlib.device¶
-
class
canlib.device.Device(ean, serial)[source]¶ Bases:
objectClass 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.from_string('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.from_string('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.canlib.Channel–Device.channelcanlib.canlib.ChannelData–Device.channel_datacanlib.canlib.IOControl–Device.iocontrolcanlib.kvmlib.Memorator–Device.memoratorcanlib.linlib.Channel–Device.lin_masterandDevice.lin_slave
Variables: - ean (
canlib.ean.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
canlib.canlib.Channelfor this device’s first channelArguments to
canlib.canlib.openChannelother than the channel number can be passed to this function.
-
channel_data()[source]¶ A
canlib.canlib.ChannelDatafor this device’s first channel
-
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.canlib.CanNotFoundexception will be raised.Parameters: - channel_number (
int) – Find a device on this CANlib channel (number). - ean (
canlib.ean.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.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.
-
lin_master(*args, **kwargs)[source]¶ A
canlib.linlib.Channelmaster for this device’s first channelArguments to
canlib.linlib.openMasterother than the channel number can be passed to this function.
-
lin_slave(*args, **kwargs)[source]¶ A
canlib.linlib.Channelslave for this device’s first channelArguments to
canlib.linlib.openSlaveother than the channel number can be passed to this function.
-
memorator(*args, **kwargs)[source]¶ A
canlib.kvmlib.Memoratorfor this device’s first channelArguments to
canlib.canlib.openChannelother than the channel number can be passed to this function.
-
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
canlib.kvrlib.RemoteDevicefor this deviceArguments to
canlib.kvrlib.openDeviceother than the channel number can be passed to this function.