Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
CANlib v5.12
Browse files Browse the repository at this point in the history
Updated samples to match relase v5.12
  • Loading branch information
Cecron committed Oct 7, 2015
1 parent e0614a2 commit 46c7a79
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 15 deletions.
85 changes: 85 additions & 0 deletions Samples/Python/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
26 changes: 13 additions & 13 deletions Samples/Python/kvMemoConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions Samples/Python/kvmlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 46c7a79

Please sign in to comment.