# Device

class canlib.Device(ean, serial)

  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('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('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.Channel` – `Device.channel`

  - `canlib.ChannelData` – `Device.channel_data`

  - `canlib.IOControl` – `Device.iocontrol`

  - `kvmlib.Memorator`– `Device.memorator`

  - `linlib.Channel` – `Device.lin_master` and `Device.lin_slave`

  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)

    A `Channel` for this device’s first channel

    The experimental argument `_chan_no_on_card` may be given, the `int` provided will be added (without any verifications) to the `channel_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 large `int` 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()

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

  channel_number()

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

  ean
  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.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()

    A `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.

  last_channel_number
  lin_master(*args, **kwargs)

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

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

  lin_slave(*args, **kwargs)

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

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

  memorator(*args, **kwargs)

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

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

  open_channel(chan_no_on_card=0, **kwargs)

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

    The parameter `chan_no_on_card` will be added (without any verifications) to the `channel_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 large `int` 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()

    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 `kvrlib.RemoteDevice` for this device

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

  serial

## connected_devices()

canlib.connected_devices()

  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.