From 46c7a79d17967c6e8e2dfc22e177ebc9e628b416 Mon Sep 17 00:00:00 2001 From: Cecron Date: Wed, 7 Oct 2015 12:45:28 +0200 Subject: [PATCH] CANlib v5.12 Updated samples to match relase v5.12 --- Samples/Python/canlib.py | 85 ++++++++++++++++++++++++++++++++++ Samples/Python/kvMemoConfig.py | 26 +++++------ Samples/Python/kvmlib.py | 9 +++- 3 files changed, 105 insertions(+), 15 deletions(-) diff --git a/Samples/Python/canlib.py b/Samples/Python/canlib.py index 9514e42..03d493b 100644 --- a/Samples/Python/canlib.py +++ b/Samples/Python/canlib.py @@ -545,6 +545,18 @@ def getChannelData_CardNumber(self, channel): return buf.value def getChannelData_EAN(self, channel): + """Get EAN code + + Retrieves the EAN number for the device connected to channel. If there + is no EAN number, "00-00000-00000-0" will be returned. + + Args: + channel (int): The channel you are interested in + + Returns: + ean (str): The device's EAN number + + """ self.fn = inspect.currentframe().f_code.co_name buf_type = ct.c_ulong * 2 buf = buf_type() @@ -558,6 +570,19 @@ def getChannelData_EAN(self, channel): (ean_lo >> 4) & 0xfffff, ean_lo & 0xf) def getChannelData_EAN_short(self, channel): + """Get short EAN code + + Retrieves the short EAN number, aka product number, for the device + connected to channel. If there is no EAN number, "00000-0" will be + returned. + + Args: + channel (int): The channel you are interested in + + Returns: + ean (str): The device's shortened EAN number + + """ self.fn = inspect.currentframe().f_code.co_name buf_type = ct.c_ulong * 2 buf = buf_type() @@ -568,6 +593,18 @@ def getChannelData_EAN_short(self, channel): return "%04x-%x" % ((ean_lo >> 4) & 0xffff, ean_lo & 0xf) def getChannelData_Serial(self, channel): + """Get device serial number + + Retrieves the serial number for the device connected to channel. If the + device does not have a serial number, 0 is returned. + + Args: + channel (int): The channel you are interested in + + Returns: + serial (int): The device serial number + + """ self.fn = inspect.currentframe().f_code.co_name buf_type = ct.c_ulong * 2 buf = buf_type() @@ -866,28 +903,76 @@ def scriptEnvvarGetData(self, envHandle, envSize): return envvarValue.value def fileGetCount(self): + """Get the number of files on the device. + + Returns: + count (int): The number of files. + """ self.canlib.fn = inspect.currentframe().f_code.co_name count = ct.c_int() self.dll.kvFileGetCount(self.handle, ct.byref(count)) return count.value def fileGetName(self, fileNo): + """Get the name of the file with the supplied number. + + Args: + fileNo (int): The number of the file. + + Returns: + fileName (string): The name of the file. + """ self.canlib.fn = inspect.currentframe().f_code.co_name fileName = ct.create_string_buffer(50) self.dll.kvFileGetName(self.handle, ct.c_int(fileNo), fileName, ct.sizeof(fileName)) return fileName.value + def fileCopyToDevice(self, hostFileName, deviceFileName): + """Copy an arbitrary file from the host to the device. + + Args: + hostFileName (string): The target host file name. + deviceFileName (string): The device file name. + """ + self.canlib.fn = inspect.currentframe().f_code.co_name + self.dll.kvFileCopyToDevice(self.handle, hostFileName, + deviceFileName) + def fileCopyFromDevice(self, deviceFileName, hostFileName): + """Copy an arbitrary file from the device to the host. + + Args: + deviceFileName (string): The device file name. + hostFileName (string): The target host file name. + """ self.canlib.fn = inspect.currentframe().f_code.co_name self.dll.kvFileCopyFromDevice(self.handle, deviceFileName, hostFileName) def kvDeviceSetMode(self, mode): + """Set the current device's mode. + + Note: The mode is device specific, which means that not all modes are + implemented in all products. + + Args: + mode (int): One of the kvDEVICE_MODE_xxx constants, defining which + mode to use. + """ self.canlib.fn = inspect.currentframe().f_code.co_name self.dll.kvDeviceSetMode(self.handle, ct.c_int(mode)) def kvDeviceGetMode(self): + """Read the current device's mode. + + Note: The mode is device specific, which means that not all modes are + implemented in all products. + + Returns: + mode (int): One of the kvDEVICE_MODE_xxx constants, indicating + which mode is in use. + """ self.canlib.fn = inspect.currentframe().f_code.co_name mode = ct.c_int() self.dll.kvDeviceGetMode(self.handle, ct.byref(mode)) diff --git a/Samples/Python/kvMemoConfig.py b/Samples/Python/kvMemoConfig.py index a2ae65a..9dbd940 100644 --- a/Samples/Python/kvMemoConfig.py +++ b/Samples/Python/kvMemoConfig.py @@ -321,6 +321,7 @@ class kvTrigAction(object): class function: START_LOG = 'ACTION_START_LOG' STOP_LOG = 'ACTION_STOP_LOG' + STOP_LOG_COMPLETELY = 'ACTION_STOP_LOG_COMPLETELY' ACTIVATE_AUTO_TRANSMIT_LIST = 'ACTION_ACTIVATE_AUTO_TRANSMIT_LIST' DEACTIVATE_AUTO_TRANSMIT_LIST = 'ACTION_DEACTIVATE_AUTO_TRANSMIT_LIST' EXTERNAL_PULSE = 'ACTION_EXTERNAL_PULSE' @@ -433,7 +434,7 @@ def __str__(self): class kvMemoConfig(object): - def __init__(self, version="2.0", afterburner=0, log_all=False, + def __init__(self, version="2.0", binary_version="5.0", afterburner=0, log_all=False, fifo_mode="NO", param_lif=None, param_xml=None): if param_lif is not None: self.parseLif(param_lif) @@ -452,6 +453,10 @@ def __init__(self, version="2.0", afterburner=0, log_all=False, text = self.document.createTextNode(version) child.appendChild(text) root.appendChild(child) + child = self.document.createElement('BINARY_VERSION') + text = self.document.createTextNode(binary_version) + child.appendChild(text) + root.appendChild(child) xmlSettings = self.document.createElement('SETTINGS') root.appendChild(xmlSettings) xmlMode = self.document.createElement('MODE') @@ -469,16 +474,11 @@ def addBusparams(self, rateParam, channel=0, silent=False): self.document.documentElement.appendChild(child) else: child = child[0] - PhSeg2 = rateParam.tseg2 - PhSeg1 = PhSeg2 - PrSeg = (rateParam.tseg1 + rateParam.tseg2) - (PhSeg1 + PhSeg2) - PSC = (16000000 / (rateParam.freq * (1 + PrSeg + PhSeg1 + PhSeg2))) - 1 newchild = self.document.createElement('PARAMETERS') newchild.setAttribute('channel', str(channel)) - newchild.setAttribute('phase_seg1', str(PhSeg1)) - newchild.setAttribute('phase_seg2', str(PhSeg2)) - newchild.setAttribute('prop_seg', str(PrSeg)) - newchild.setAttribute('prescaler', str(PSC)) + newchild.setAttribute('bitrate', str(rateParam.freq)) + newchild.setAttribute('tseg1', str(rateParam.tseg1)) + newchild.setAttribute('tseg2', str(rateParam.tseg2)) newchild.setAttribute('sjw', str(rateParam.sjw)) newchild.setAttribute('silent', "YES" if silent else "NO") child.appendChild(newchild) @@ -624,11 +624,11 @@ def toLif(self): trigger.addTrigVarTimer(trigVarTimer) trigVarTimer = kvTrigVarTimer(idx="trigger_timer_1", offset=20) trigger.addTrigVarTimer(trigVarTimer) - trigStatement = kvTrigStatement(postFixExpr="trigger_timer_0", - function=ACTION_START_LOG) + trigStatement = kvTrigStatement(expression="trigger_timer_0", + function=kvTrigStatement.function.START_LOG) trigger.addStatement(trigStatement) - trigStatement = kvTrigStatement(postFixExpr="trigger_timer_1", - function=ACTION_STOP_LOG) + trigStatement = kvTrigStatement(expression="trigger_timer_1", + function=kvTrigStatement.function.START_LOG) trigger.addStatement(trigStatement) memoConfig.addTrigger(trigger) diff --git a/Samples/Python/kvmlib.py b/Samples/Python/kvmlib.py index b181ede..c2bcfda 100644 --- a/Samples/Python/kvmlib.py +++ b/Samples/Python/kvmlib.py @@ -101,12 +101,17 @@ def differ(a, b): def __init__(self, timestamp=None): self.timeStamp = timestamp + self.ignored = False def __str__(self): + if self.ignored: + text = "*t:" + else: + text = " t:" if self.timeStamp is not None: - text = "t:%14s " % (self.timeStamp/1000000000.0) + text += "%14s " % (self.timeStamp/1000000000.0) else: - text = "t: - " + text += " - " return text def __eq__(self, other):