# canlib.device

class `canlib.device.``Device`(ean, serial)

  Bases: `object`

  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 a `Device` object:

      dev = Device.find(ean=EAN.from_string('67890-1'))

  `Device.find` supports searching for devices based on a variety of information, and will return a `Device` 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.from_string('67890-1'), serial=42)

  Two `Device` objects can be checked for equality (whether they refer to the same device) and be converted to a `str`. `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`:

  - `canlib.canlib.Channel` – `Device.channel`
  - `canlib.canlib.ChannelData` – `Device.channel_data`
  - `canlib.canlib.IOControl` – `Device.iocontrol`
  - `canlib.kvmlib.Memorator`– `Device.memorator`
  - `canlib.linlib.Channel` – `Device.lin_master` and `Device.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)

    A `canlib.canlib.Channel` for this device’s first channel

    Arguments to `canlib.canlib.openChannel` other than the channel number can be passed to this function.

  `channel_data`()

    A `canlib.canlib.ChannelData` for this device’s first channel

  `channel_number`()

    An `int` with this device’s CANlib channel number

  classmethod `find`(channel_number=None, ean=None, serial=None, channel_name=None)

    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 a `canlib.canlib.CanNotFound` exception 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.

  `iocontrol`()

    A `canlib.canlib.IOControl` for this device’s first channel

  `isconnected`()

    A `bool` whether this device can currently be found

  `issubset`(other)

    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)

    A `canlib.linlib.Channel` master for this device’s first channel

    Arguments to `canlib.linlib.openMaster` other than the channel number can be passed to this function.

  `lin_slave`(*args, **kwargs)

    A `canlib.linlib.Channel` slave for this device’s first channel

    Arguments to `canlib.linlib.openSlave` other than the channel number can be passed to this function.

  `memorator`(*args, **kwargs)

    A `canlib.kvmlib.Memorator` for this device’s first channel

    Arguments to `canlib.canlib.openChannel` other than the channel number can be passed to this function.

  `probe_info`()

    A `str` with information about this device

    This function is useful when the `Device`’s `str()` 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)

    A `canlib.kvrlib.RemoteDevice` for this device

    Arguments to `canlib.kvrlib.openDevice` other than the channel number can be passed to this function.

`canlib.device.``connected_devices`()

  Get all currently connected devices as `Device`s

  Returns an iterator of `Device` object, one object for every physical device currently connected.

  New in version 1.6.

  Changed in version 1.7: `canlib.Device.last_channel_number` will now be set.