# canlib.kvamemolibxml

Wrapper for the Kvaser kvaMemoLibXml library

The kvaMemoLibXML is a library for converting XML settings to a binary param.lif for Kvaser Memorator 2nd Generation

The binary settings used by Kvaser Memorator 2nd Generation are extensive and an API that covers all possibilities would be very complex. A better approach is to use XML to describe the settings and parse them into a binary settings file with an external library.

The XML conversion results in a binary settings file, param.lif, that can be downloaded to a Kvaser Memorator 2nd Generation with the KvmLib API call `kvmKmfWriteConfig()`.

class `canlib.kvamemolibxml.``Configuration`(xml=None, lif=None)

  Bases: `object`

  Configuration data for Kvaser devices

  It is usually preferred to create objects of this class with one of the functions:

  - `canlib.kvamemolibxml.load_xml`
  - `canlib.kvamemolibxml.load_xml_file`
  - `canlib.kvamemolibxml.load_lif`
  - `canlib.kvamemolibxml.load_lif_file`

  The XML and param.lif representation of this configuration can be accessed with the `xml` and `lif` attributes, respectively.

  Two `Configuration` objects can be tested for equality:

      config1 == config2

  This will test whether the objects are equivalent: whether they have the same param.lif representation.

  Finally, the configuration can be validated with `Configuration.validate`:

      errors, warnings = configuration.validate()
      for error in errors:
          print(error)
      for warning in warnings:
          print(warning)
      if errors:
          raise ValueError("Invalid configuration")

  `lif`

    `bytes` – The param.lif representation of this configuration

  `validate`()

    Validate this configuration

    Validates the XML representation of this configuration, and returns a tuple `(errors, warnings)` where `errors` is a `list` of `canlib.kvamemolibxml.ValidationError` and `warnings` is a `list` `canlib.kvamemolibxml.ValidationWarning`.

  `xml`

    `str` – The XML representation of this configuration

class `canlib.kvamemolibxml.``Error`

  Bases: `canlib.cenum.CEnum`

  `ATTR_NOT_FOUND` = -3
  `ATTR_VALUE` = -4
  `DTD_VALIDATION` = -11
  `ELEM_NOT_FOUND` = -5
  `FAIL` = -1
  `INTERNAL` = -20
  `POSTFIXEXPR` = -9
  `SCRIPT_ERROR` = -12
  `VALUE_CONSECUTIVE` = -8
  `VALUE_RANGE` = -6
  `VALUE_UNIQUE` = -7
  `XML_PARSER` = -10

exception `canlib.kvamemolibxml.``KvaError`

  Bases: `canlib.exceptions.DllException`

class `canlib.kvamemolibxml.``KvaMemoLibXml`

  Bases: `object`

  Deprecated wrapper class for the Kvaser kvaMemoLibXml

  Deprecated since version 1.5.

  All functionality of this class has been moved to the kvamemolibxml module itself:

      # deprecated
      from canlib import kvamemolibxml
      cl = kvamemolibxml.KvaMemoLibXml()  # or kvamemolibxml.kvaMemoLibXml()
      cl.functionName()

      # use this instead
      from canlib import kvamemolibxml
      kvamemolibxml.functionName()

  Differences:

  `xmlGetLastError` Does not take any argument, and returns a two-tuple.

  `dll` = <canlib.kvamemolibxml.dll.KvaMemoLibXmlDll object>
  `installDir` = 'F:\\Data\\180513~2\\pycanlib\\DEFAUL~2\\\\dll32'
  `kvaMemoLibXmlDll` = <WinDLL 'kvaMemoLibXML.dll', handle 69fb0000 at 3694570>
  static `xmlGetLastError`(kvaERR=0)

    Get the last error message (if any).

    Get the last error message (if any) from conversion in human redable format.

    Parameters: | kvaERR (int) – kvaMemoLibXml error code.
    Returns: | msg (string) – Error message associated with kvaERR.

class `canlib.kvamemolibxml.``ValidationError`

  Bases: `canlib.cenum.CEnum`

  `ABORT` = -2
  `DISK_FULL_STARTS_LOG` = -7
  `ELEMENT_COUNT` = -13
  `EXPRESSION` = -16
  `FAIL` = -1
  `MULTIPLE_EXT_TRIGGER` = -5
  `MULTIPLE_START_TRIGGER` = -6
  `NUM_OUT_OF_RANGE` = -8
  `PARSER` = -14
  `SCRIPT` = -15
  `SCRIPT_CONFLICT` = -12
  `SCRIPT_NOT_FOUND` = -9
  `SCRIPT_TOO_LARGE` = -10
  `SCRIPT_TOO_MANY` = -11
  `SILENT_TRANSMIT` = -3
  `UNDEFINED_TRIGGER` = -4

class `canlib.kvamemolibxml.``ValidationErrorMessage`

  Bases: `canlib.kvamemolibxml.configuration.ValidationMessage`

  An error found during validation

class `canlib.kvamemolibxml.``ValidationMessage`(code, text)

  Bases: `tuple`

  `code`

    Alias for field number 0

  `text`

    Alias for field number 1

class `canlib.kvamemolibxml.``ValidationWarning`

  Bases: `canlib.cenum.CEnum`

  `ABORT` = -100
  `DISK_FULL_AND_FIFO` = -102
  `IGNORED_ELEMENT` = -103
  `MULTIPLE_EXT_TRIGGER` = -104
  `NO_ACTIVE_LOG` = -101

class `canlib.kvamemolibxml.``ValidationWarningMessage`

  Bases: `canlib.kvamemolibxml.configuration.ValidationMessage`

  A warning found during validation

`canlib.kvamemolibxml.``dllversion`()

  Get the kvaMemoLibXML DLL version number as a `VersionNumber`

`canlib.kvamemolibxml.``getVersion`

  Get the kvaMemoLibXml DLL version number as a `str`

  Deprecated since version 1.5: Use `dllversion` instead.

`canlib.kvamemolibxml.``kvaBufferToXml`(conf_lif)

  Convert a buffer containg param.lif to XML settings.

  Scripts from the param.lif will be written to current working directory.

  Parameters: | conf_lif (string) – Buffer containing param.lif to convert.
  Returns: | xml_buf (string) – Buffer containing converted XML settings.

`canlib.kvamemolibxml.``kvaError`

  alias of `canlib.kvamemolibxml.exceptions.KvaError`

`canlib.kvamemolibxml.``kvaMemoLibXml`

  alias of `canlib.kvamemolibxml.wrapper.KvaMemoLibXml`

`canlib.kvamemolibxml.``kvaXmlToBuffer`(conf_xml)

  Convert XML settings to param.lif buffer.

  Parameters: | conf_xml (string) – XML settings to convert.
  Returns: | lif_buf (string) – Buffer containing converted param.lif.

`canlib.kvamemolibxml.``kvaXmlToFile`(xml_filename, binary_filename)

  Convert XML file to binary configuration file.

  Parameters: | infile (string) – Filename of file containing the XML settings. outfile (string) – Filename of binary configuration.

`canlib.kvamemolibxml.``kvaXmlValidate`(conf_xml)

  Validate a buffer with XML settings.

  Parameters: | conf_xml (string) – string containing the XML settings to validate.
  Returns: | countErr (int) – Number of XML validation errors. countWarn (int): Number of XML validation warnings.

`canlib.kvamemolibxml.``load_lif`(lif_bytes)

  Create a `Configuration` from a param.lif `bytes`

  Parameters: | lif_bytes (`bytes`) – Binary configuration in param.lif format

`canlib.kvamemolibxml.``load_lif_file`(filepath)

  Like `load_lif` but takes a path to a file containing the lif configuration

`canlib.kvamemolibxml.``load_xml`(xml_string)

  Create a `Configuration` from an xml `string`

  Parameters: | xml_string (`str`) – XML configuration

`canlib.kvamemolibxml.``load_xml_file`(filepath)

  Like `load_lif` but takes a path to a file containing the XML configuration

`canlib.kvamemolibxml.``xmlGetLastError`()

  Get the last error message (if any).

  Get the last error message (if any) from conversion in human redable format.

  Returns: | msg (string) – Error message associated with kvaERR. err (int): kvaMemoLibXml error code.

`canlib.kvamemolibxml.``xmlGetValidationError`()

  Get validation errors (if any).

  Call after kvaXmlValidate() until return status is KvaXmlValidationStatusOK.

  Returns: | validationStatus (int) – Validation status code. text (string): Validation status message.

`canlib.kvamemolibxml.``xmlGetValidationStatusCount`()

  Get the number of validation statuses (if any).

  Call after kvaXmlValidate().

  Returns: | countErr (int) – Number of XML validation errors. countWarn (int): Number of XML validation warnings.

`canlib.kvamemolibxml.``xmlGetValidationWarning`()

  Get validation warnings (if any).

  Call after kvaXmlValidate() until return status is KvaXmlValidationStatusOK.

  Returns: | validationStatus (int) – Validation status code. text (string): Validation status message.