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)[source]¶ Bases:
objectConfiguration data for Kvaser devices
It is usually preferred to create objects of this class with one of the functions:
canlib.kvamemolibxml.load_xmlcanlib.kvamemolibxml.load_xml_filecanlib.kvamemolibxml.load_lifcanlib.kvamemolibxml.load_lif_file
The XML and param.lif representation of this configuration can be accessed with the
xmlandlifattributes, respectively.Two
Configurationobjects 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¶ The param.lif representation of this configuration
Type: bytes
-
validate()[source]¶ Validate this configuration
Validates the XML representation of this configuration, and returns a tuple
(errors, warnings)whereerrorsis alistofcanlib.kvamemolibxml.ValidationErrorandwarningsis alistcanlib.kvamemolibxml.ValidationWarning.
-
xml¶ The XML representation of this configuration
Type: str
-
class
canlib.kvamemolibxml.Error[source]¶ 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¶
-
-
class
canlib.kvamemolibxml.KvaMemoLibXml[source]¶ Bases:
objectDeprecated 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:
xmlGetLastErrorDoes not take any argument, and returns a two-tuple.-
dll= <canlib.kvamemolibxml.dll.KvaMemoLibXmlDll object>¶
-
installDir= 'F:\\Data\\190303~2\\pycanlib\\DEFAUL~2\\\\dll32'¶
-
kvaMemoLibXmlDll= <WinDLL 'kvaMemoLibXML.dll', handle 67a80000 at 576afd0>¶
-
-
class
canlib.kvamemolibxml.ValidationError[source]¶ 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[source]¶ Bases:
canlib.kvamemolibxml.configuration.ValidationMessageAn 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[source]¶ 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[source]¶ Bases:
canlib.kvamemolibxml.configuration.ValidationMessageA warning found during validation
-
canlib.kvamemolibxml.dllversion()[source]¶ Get the kvaMemoLibXML DLL version number as a
VersionNumber
-
canlib.kvamemolibxml.getVersion[source]¶ Get the kvaMemoLibXml DLL version number as a
strDeprecated since version 1.5: Use
dllversioninstead.
-
canlib.kvamemolibxml.kvaBufferToXml(conf_lif)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ 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)[source]¶ Create a
Configurationfrom a param.lifbytesParameters: lif_bytes ( bytes) – Binary configuration in param.lif format
-
canlib.kvamemolibxml.load_lif_file(filepath)[source]¶ Like
load_lifbut takes a path to a file containing the lif configuration
-
canlib.kvamemolibxml.load_xml(xml_string)[source]¶ Create a
Configurationfrom an xmlstringParameters: xml_string ( str) – XML configuration
-
canlib.kvamemolibxml.load_xml_file(filepath)[source]¶ Like
load_lifbut takes a path to a file containing the XML configuration
-
canlib.kvamemolibxml.xmlGetLastError()[source]¶ 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()[source]¶ Get validation errors (if any).
Call after kvaXmlValidate() until return status is KvaXmlValidationStatusOK.
Returns: validationStatus (int) – Validation status code. text (string): Validation status message.