本文将通过介绍kvmlib,使用Kvaser Memorator数据记录仪,配置和读取已记录的数据:
1 开始使用kvmlib
2 为配置添加脚本和触发点
3 进一步了解kvmlib
4用kvmlib配置SD卡
很多时候我们只能访问将要插入设备的SD卡,那么需要进行哪些不同的操作。此假设场景是,SD卡还未插入设备。我们将使用一个在Windows中格式化的16 GB SD卡,初始化并配置此SD卡,以便之后将它插入运行固件版本3.11的Kvaser Memorator Pro 2xHS (EAN 00819-9)。在运行我们的数据记录后,将从设备中取出SD卡,读取并重置记录文件。

初始化SD

即使我们手里没有设备,仍然可以使用Windows电脑和 mhydraformat.exe程序,初始化SD卡。但是,这比直接使用设备要花费更多的时间,因为初始化16 GB卡大约需要3分钟。mhydraformat.exe 程序位于在 Kvaser Memorator Config Tool.1 的安装目录下。你可以用 --help变量运行这个格式化程序,来查看使用帮助部分。

[C:]mhydraformat.exe --help
Disk formatting program for Kvaser Memorator (2nd generation) devices.

-h --help | Print this information.
-d=DRIVE --drive=DRIVE | The drive to format, e.g. F:
-r=X --reserve=X | The number of MB to reserve for user files.
-c=X --config=X | The number of MB to reserve for configurations.
–fat16 | Format the disk with FAT16. Default is FAT32.
-i --interactive | Require the user to confirm before format.
-q --quiet | Stop all outputs. Overrides -i.
–bin5 | Use the older, smaller version 5 of PARAM.LIF.
–lio3 | Use the older LIO data format 3 for KMF files.

Example:
mhydraformat -d=F: -r=100 -c=10 --interactive
View sourceCopy to clipboard
将SD卡连接到电脑并记下驱动器代码字母。对于我来说,SD卡被分配给了J:盘。现在我们运行 mhydraformat.exe 来初始化卡。请注意,用于指定分配给DATABASE.BIN 空间的命令行改换为 --config。在初始化之后,我们还使用Windows dir命令查看此卡的内容。
C:> mhydraformat.exe -d=J: -r=10000 -c=10
Formatting…done.

C:> dir j:

Volume in drive J has no label.
Directory of J:\

2018-08-10 10:39 10 010 624 DATABASE.BIN
2018-08-10 10:39 1 073 741 824 LOG00000.KMF
2018-08-10 10:39 1 073 741 824 LOG00001.KMF
2018-08-10 10:39 1 073 741 824 LOG00002.KMF
2018-08-10 10:39 1 073 741 824 LOG00003.KMF
2018-08-10 10:39 1 073 741 824 LOG00004.KMF
2018-08-10 10:39 514 785 280 LOG00005.KMF
2018-08-10 10:39 10 485 760 PARAM.LIF
8 File(s) 5 903 990 784 bytes
0 Dir(s) 10 004 455 424 bytes free
View sourceCopy to clipboard
在这里我们看到二进制的配置文件(PARAM.LIF),此记录文件容器(LOG00000.KMF 到 LOG00005.KMF)和为Kvaser Memorator Config Tool (10MB DATABASE.BIN)保留的配置文件。我们还看到了我们要求的10000 MB空闲区。

把配置存储到卡上

要把此配置直接下载到SD卡,我们需要打开文件系统,我们还需要通知kvmlib我们的SD卡装在哪里。这是通过调用函数 kmfOpen() 和提供去文件LOG00000.KMF的完整路径来完成的,该文件总是在一个已正确初始化的SD卡上。
我们现在用kvamemo libxml将二进制配置文件直接写入SD卡,我们需要提供正确的设备类型。

12_设置Sd.py

from canlib import kvamemolibxml

print('kvamemolib version: ', kvamemolibxml.dllversion())

我们的SD卡装在J:驱动器里, 所以我们的二进制配置应该在那里。

filename = ‘J:/PARAM.LIF’

转换之前验证的XML配置文件

并将此结果二进制配置写入SD卡

kvamemolibxml.kvaXmlToFile(“config.xml”, filename)
View sourceCopy to clipboard
列表 15:将二进制配置写入SD卡。
要以明确文字形式下载配置,我们完全像在前一部分博客中那样操作,但是通过Windows挂载点直接将该zip文件写入SD卡。

13_复制_文件_到_卡上.py

import zipfile

我们的SD卡装在J:驱动

filename = ‘J:/config.zip’

生成zip文档

with zipfile.ZipFile(filename, mode=‘w’,
compression=zipfile.ZIP_DEFLATED) as zipf:
# 把文件添加到zip 文档里
zipf.write(‘config.xml’)
zipf.write(‘myCanGenerator.txe’)
View sourceCopy to clipboard
列表 1:将二进制配置写入SD卡。

要以明确文字形式下载配置,通过Windows挂载点直接将该zip文件写入SD卡。

13_复制_文件_到_卡上.py

import zipfile

我们的SD卡装在J:驱动

filename = ‘J:/config.zip’

生成zip文档

with zipfile.ZipFile(filename, mode=‘w’,
compression=zipfile.ZIP_DEFLATED) as zipf:
# 把文件添加到zip 文档里
zipf.write(‘config.xml’)
zipf.write(‘myCanGenerator.txe’)
View sourceCopy to clipboard
列表 16: 用压缩文档写下明确文字配置。
现在如果你查看我们的SD卡,它的内容如下所示。
C:>dir J:
Volume in drive J has no label.
Directory of J:\

2018-08-10 11:16 40 604 PARAM.LIF
2018-08-10 10:39 1 073 741 824 LOG00000.KMF
2018-08-10 10:39 1 073 741 824 LOG00001.KMF
2018-08-10 10:39 1 073 741 824 LOG00002.KMF
2018-08-10 10:39 1 073 741 824 LOG00003.KMF
2018-08-10 10:39 1 073 741 824 LOG00004.KMF
2018-08-10 10:39 514 785 280 LOG00005.KMF
2018-08-10 10:39 10 010 624 DATABASE.BIN
2018-08-10 11:21 2 516 config.zip
9 File(s) 5 893 548 144 bytes
0 Dir(s) 10 014 892 032 bytes free
View sourceCopy to clipboard
列表 2: 用压缩文档写下明确文字配置。

现在如果你查看我们的SD卡,它的内容如下所示:
C:>dir J:
Volume in drive J has no label.
Directory of J:\

2018-08-10 11:16 40 604 PARAM.LIF
2018-08-10 10:39 1 073 741 824 LOG00000.KMF
2018-08-10 10:39 1 073 741 824 LOG00001.KMF
2018-08-10 10:39 1 073 741 824 LOG00002.KMF
2018-08-10 10:39 1 073 741 824 LOG00003.KMF
2018-08-10 10:39 1 073 741 824 LOG00004.KMF
2018-08-10 10:39 514 785 280 LOG00005.KMF
2018-08-10 10:39 10 010 624 DATABASE.BIN
2018-08-10 11:21 2 516 config.zip
9 File(s) 5 893 548 144 bytes
0 Dir(s) 10 014 892 032 bytes free
View sourceCopy to clipboard
从SD卡读取结果

当我们从现场取回SD卡,将SD卡重新接到我们的电脑上,并开始验证SD卡上的LIO数据格式版本。

14_验证Lio格式Sd.py

from canlib import kvmlib

我们的SD卡装在J:驱动, 所以我们的 LOG00000.KMF can可以在这里打开

filename = ‘J:/LOG00000.KMF’

打开SD卡并读取LIO数据格式版本

我们设备的固件版本是3.0 ,此SD卡将插入此设备, 这意味着FW在使用Lio数据格式v5.0,我们应使用kvmDEVICE_MHYDRA_EXT作为设备类型deviceType

with kvmlib.openKmf(
filename,
device_type=kvmlib.Device.MHYDRA_EXT) as kmf:
ldf_version = kmf.log.ldf_version

print(‘Lio Data Format version:’, ldf_version)

验证SD卡的此 LIO数据格式版本,和我们用来打开此设备的设备版本匹配

if ldf_version != (5, 0):
print(‘Unexpected Lio Data Format:’, ldf_version)
if ldf_version == (3, 0):
print(“This log file can be read if you reopen the”
" device as kvmDEVICE_MHYDRA.")
View sourceCopy to clipboard
列表 17: 验证SD卡上的LIO数据格式。
下一步是读取记录下来的数据。和我们的上一部分博客唯一不同的是,我们现在打开此SD卡,而不是打开已连接的设备。我们回到上一部分,更详细地说明这里的状况。

15_从Sd读取结果.py

import glob
import os

from canlib import EAN, VersionNumber
from canlib import kvmlib

#我们的SD卡装在J:驱动, 所以我们的 LOG00000.KMF can可以在这里打开
filename = ‘J:/LOG00000.KMF’

用来存放结果文件的目录

resultDir = “result”

确定结果文件的目录存在并且空闲

if os.path.isdir(resultDir):
files = glob.glob(os.path.join(resultDir, “*”))
for f in files:
os.remove(f)
else:
os.mkdir(resultDir)
os.chdir(resultDir)

打开SD卡

我们之前已经验证此SD卡是使用Lio 数据格式 v5.0,而且我们应该用

kvmDEVICE_MHYDRA_EXT 作为设备类型deviceType
with kvmlib.openKmf(filename) as kmf:
ldf_version = kmf.log.ldf_version
#验证SD卡的此LIO数据格式版本,和我们用来打开此设备的设备版本匹配

if ldf_version != VersionNumber(major=5, minor=0):if ldf_version == VersionNumber(major=3, minor=0):raise ValueError('This log file can be read if you reopen the'' device as kvmDEVICE_MHYDRA.')raise ValueError('Unexpected Lio Data Format: ' + str(ldf_version))# 读取已记录下来的文件数量
num_log_files = len(kmf.log)
print("Found {num} file on card: ".format(num=num_log_files))# 选择所有记录文件并把它们的内容写入.kme50文件
for i, log_file in enumerate(kmf.log):print("\n==== File {index}: {start} - {end}, approx {num} events".format(index=i,start=log_file.start_time,end=log_file.end_time,num=log_file.event_count_estimation()))# 第一个记录事件包含设备信息event_iterator = iter(log_file)first_event = next(event_iterator)ean = EAN.from_hilo([first_event.eanHi, first_event.eanLo])serial = first_event.serialNumber# 把EAN和系列号添加到文件名上logfile_name = ('log_{ean}_{sn}_{index:03}.kme50'.format(ean=str(ean), sn=serial, index=i))print('Saving to:', logfile_name)with kvmlib.createKme(logfile_name) as kme:print(first_event)kme.write_event(first_event)for event in event_iterator:# 把事件书写到stdoutprint(event)kme.write_event(event)# 删除所有记录文件
# kmf.log.删除_所有()

View sourceCopy to clipboard
列表 3 验证SD卡上的LIO数据格式。

下一步是读取记录下来的数据,我们现在打开此SD卡,而不是打开已连接的设备。

15_从Sd读取结果.py

import glob
import os

from canlib import EAN, VersionNumber
from canlib import kvmlib

#我们的SD卡装在J:驱动, 所以我们的 LOG00000.KMF can可以在这里打开
filename = ‘J:/LOG00000.KMF’

用来存放结果文件的目录

resultDir = “result”

确定结果文件的目录存在并且空闲

if os.path.isdir(resultDir):
files = glob.glob(os.path.join(resultDir, “*”))
for f in files:
os.remove(f)
else:
os.mkdir(resultDir)
os.chdir(resultDir)

打开SD卡

我们之前已经验证此SD卡是使用Lio 数据格式 v5.0,而且我们应该用

kvmDEVICE_MHYDRA_EXT 作为设备类型deviceType
with kvmlib.openKmf(filename) as kmf:
ldf_version = kmf.log.ldf_version
#验证SD卡的此LIO数据格式版本,和我们用来打开此设备的设备版本匹配

if ldf_version != VersionNumber(major=5, minor=0):if ldf_version == VersionNumber(major=3, minor=0):raise ValueError('This log file can be read if you reopen the'' device as kvmDEVICE_MHYDRA.')raise ValueError('Unexpected Lio Data Format: ' + str(ldf_version))# 读取已记录下来的文件数量
num_log_files = len(kmf.log)
print("Found {num} file on card: ".format(num=num_log_files))# 选择所有记录文件并把它们的内容写入.kme50文件
for i, log_file in enumerate(kmf.log):print("\n==== File {index}: {start} - {end}, approx {num} events".format(index=i,start=log_file.start_time,end=log_file.end_time,num=log_file.event_count_estimation()))# 第一个记录事件包含设备信息event_iterator = iter(log_file)first_event = next(event_iterator)ean = EAN.from_hilo([first_event.eanHi, first_event.eanLo])serial = first_event.serialNumber# 把EAN和系列号添加到文件名上logfile_name = ('log_{ean}_{sn}_{index:03}.kme50'.format(ean=str(ean), sn=serial, index=i))print('Saving to:', logfile_name)with kvmlib.createKme(logfile_name) as kme:print(first_event)kme.write_event(first_event)for event in event_iterator:# 把事件书写到stdoutprint(event)kme.write_event(event)# 删除所有记录文件
# kmf.log.删除_所有()

View sourceCopy to clipboard
列表 4 从SD卡读取已记录的数据并保存到.kme50文件上。

运行上面的程序,在此记录里出现的每个通道上,我们能看到6个报文。
Found 1 file on card:

==== File 0: 2018-08-10 12:26:38 - 2018-08-10 12:26:44, approx 20 events
Saving to: log_73-30130-00819-9_11573_000.kme50
*t: - EAN:73-30130-00819-9 s/n:11573 FW:v3.11.557 LIO:v5.0
t: 2.701738275 DateTime: 2018-08-10 12:26:38
t: 2.701738275 Log Trigger Event (type: 0x2, trigno: 0x01, pre-trigger: 0, post-trigger: 0)

t: 2.701738275 ch:1 f: 2 id: 3 dlc: 8 d:12 21 13 31 22 34 41 15
t: 2.701738337 Log Trigger Event (type: 0x2, trigno: 0x01, pre-trigger: 0, post-trigger: 0)

t: 2.701738337 ch:0 f: 42 id: 3 dlc: 8 d:12 21 13 31 22 34 41 15
t: 3.7017584 ch:1 f: 2 id: 4 dlc: 8 d:12 21 13 31 22 34 41 15
t: 3.701758462 ch:0 f: 42 id: 4 dlc: 8 d:12 21 13 31 22 34 41 15
t: 4.701774525 ch:1 f: 2 id: 5 dlc: 8 d:12 21 13 31 22 34 41 15
t: 4.701774587 ch:0 f: 42 id: 5 dlc: 8 d:12 21 13 31 22 34 41 15
t: 5.70179165 Log Trigger Event (type: 0x2, trigno: 0x01, pre-trigger: 0, post-trigger: 2500)

t: 5.70179165 ch:1 f: 2 id: 6 dlc: 8 d:12 21 13 31 22 34 41 15
t: 5.701791712 ch:0 f: 42 id: 6 dlc: 8 d:12 21 13 31 22 34 41 15
t: 6.701809775 ch:1 f: 2 id: 7 dlc: 8 d:12 21 13 31 22 34 41 15
t: 6.701809837 ch:0 f: 42 id: 7 dlc: 8 d:12 21 13 31 22 34 41 15
t: 7.7018359 ch:1 f: 2 id: 8 dlc: 8 d:12 21 13 31 22 34 41 15
t: 7.701835962 ch:0 f: 42 id: 8 dlc: 8 d:12 21 13 31 22 34 41 15
View sourceCopy to clipboard

从SD卡读取配置

为了操作完整,我们还需要说明,怎样读取我们之前通过Windows挂载点放在SD卡上的压缩配置。

16_从Sd读取配置.py

import glob
import os
import shutil

#我们的SD卡装在J:驱动, 所以我们的 LOG00000.KMF can可以在这里打开
filename = ‘J:/LOG00000.KMF’

for file in glob.glob(os.path.join(os.path.dirname(filename), “.”)):
if(os.path.splitext(file)[1].lower() == ‘.kmf’
or file.lower() == ‘param.lif’
or file.lower() == ‘database.bin’):
print(‘Skipping:’, file)
else:
print(‘Copying:’, file)
shutil.copy(file, “.”)
View sourceCopy to clipboard
列表 19:从SD卡复制所有用户文件。
现在,此运行的所有内容都放到了结果目录中。
C:> dir result

Directory of result

2018-08-10 13:28 2 516 config.zip
2018-08-10 13:28 10 010 624 DATABASE.BIN
2018-08-10 13:16 452 log_73-30130-00819-9_11573_000.kme50
2018-08-10 13:28 40 604 PARAM.LIF
4 File(s) 10 054 196 bytes
2 Dir(s) 786 525 990 912 bytes free
View sourceCopy to clipboard
列表 5:从SD卡复制所有用户文件。

现在,此运行的所有内容都放到了结果目录中。
C:> dir result

Directory of result

2018-08-10 13:28 2 516 config.zip
2018-08-10 13:28 10 010 624 DATABASE.BIN
2018-08-10 13:16 452 log_73-30130-00819-9_11573_000.kme50
2018-08-10 13:28 40 604 PARAM.LIF
4 File(s) 10 054 196 bytes
2 Dir(s) 786 525 990 912 bytes free
View sourceCopy to clipboard
就谈到这里,希望能帮助你对kvmlib有更多了解,并展示了kvmlib在管理Kvaser记录设备方面可以为你做些什么。

注释

1、Kvaser Memorator Config Tool的缺省安装位置在
C:\Program Files (x86)\Kvaser\MemoratorConfigTool\mhydraformat.exe
2、我们仅提供记录文件容器文件的第一个文件名,在该第一个文件记录到卡上之后,其他文件会马上跟进。

Kvaser Memorator数据记录仪通过KVmlib配置和读取SD卡相关推荐

  1. 绘制STM32最小系统电路原理图、STM32F103读取SD卡的数据

    绘制STM32最小系统电路原理图.STM32F103读取SD卡的数据 文章目录 绘制STM32最小系统电路原理图.STM32F103读取SD卡的数据 1 AltiumDesigner 软件配置 2 A ...

  2. STM32通过SDIO读取SD卡,FATFS文件管理系统

    STM32cubemx配置FATFS,读取SD卡: 1 准备工具: STM32CubeMx,keil,正点原子STM32F103,SD卡. 2打开cubemx配置工程: 2.1 配置时钟 选择高速外部 ...

  3. Arduino ESP32 读取SD卡接口选择参考

    ESP32 读取SD卡接口选择参考 ESP3232读取SD卡可以通过spi和sdmmc两种方式来读取,不过我们在市面上能买到的都基本上是4线的SPI接口的SD卡模块套件. 卡类型有如下,8-9Pin被 ...

  4. android 读取sd卡中的图片

    一.获取读取SD卡的权限 <!--在SDCard中创建与删除文件权限 --><uses-permission android:name="android.permissio ...

  5. 读取SD卡里面的BMP文件 显示到TFT上

    读取SD卡里面的BMP文件 显示到TFT上 http://blog.csdn.net/yunxianpiaoyu/article/details/8841755 我刚好最近做了一个BMP565格式的图 ...

  6. android 音乐播放器 获取sd卡所有音乐文件,Android Studio音乐播放器无法读取SD卡,只有内部存储器...

    我很抱歉,如果这原来是一个愚蠢的问题,它可能会成为一个快速修复,但我只是无法弄清楚.我在android studio中创建了音乐播放器,并且没有任何sdcard上的歌曲不会显示在列表视图中,只有内部内 ...

  7. Arduino ESP32 第三方库读取SD卡信息(三)

    Arduino ESP32 第三方库读取SD卡信息(三) 相关篇<Arduino ESP32 第三方库读取SD卡信息(一)> <Arduino ESP32 第三方库读取SD卡信息(二 ...

  8. 读取sd卡里的jar包

    读取sd卡里的jar包并使用里面的类 button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClic ...

  9. Arduino UNO 读取SD卡的信息

    Arduino UNO 读取SD卡的信息 SD卡座模块 接口描述: 控制接口:共6个引脚(GND.VCC.MISO.MOSI.SCK.CS),GND为地,VCC为供电电源,MISO.MOSI.SCK为 ...

  10. 《Arduino》开发 TFT_eSPI-master 库 之用 ESP32 读取SD卡上的图片并显示在1.14IPS屏幕上

    前几天解决了 TFT_eSPI-master 库 图片取模问题,但尽管是ESP32的 flash 也无法存储太多图片的数组,因此我找到了ESP32从SD卡读取图片并显示在LCD屏幕上的方法,SD卡可以 ...

最新文章

  1. Exchange2003-2010迁移系列之四,配置第一台Exchange CAS/HUB服务器
  2. 单片机简单的计算器c语言程序,求一个 89C51 简易计算器的c语言程序 只要加减乘除就行!...
  3. zillow房价预测
  4. MongoDB之compact操作详解
  5. 7个相同小球4个不同盒子_如何用天平称三次找出12个外观相同小球中仅有的一个次品?次品质量与正品不同。...
  6. perl anyevent socket监控web日志client
  7. 「Algospot」量化QUANTIZE
  8. Ubuntu下编译运行C#——mono tools
  9. 网关与路由器的区别!!
  10. Linux下通过rdesktop连接Windows远程桌面
  11. 一个中东外贸业务员分享的干货
  12. 教程篇(7.0) 08. FortiGate安全 Web过滤 ❀ Fortinet 网络安全专家 NSE 4
  13. IOS获取UDID添加到开发者账号用来安装测试包
  14. Pandas Series入门丨Pandas数据分析基础(3)
  15. win10中sql plus中文乱码
  16. 中科院基于gpt的学术优化网站搭建教程
  17. 智慧零售企业向服务升级进行时,全面实时监控成重点
  18. 智能物流系统领域国内外的发展状况及趋
  19. 兰伯特(Lambert)方程的求解算法3
  20. 关于js延迟加载的几种方法

热门文章

  1. 手把手教你sql触发器的使用
  2. 盖章php源码,模拟电子签章盖章效果的jQuery插件源码_jquery
  3. 关于 Nginx 0day 漏洞,需要采取哪些措施?
  4. R语言中三线表是什么?使用table1包绘制(生成)三线表实战
  5. 百度AI-语音识别图片搜索(Java)
  6. dpdk X710 VF reset
  7. 以前进行的程序安装创建了挂起的文件操作(SqlServer2000或SqlServer 2000 SP4补丁安装) .
  8. 微型计算机 路由,华硕RT-AC68U无线路由器深度体验
  9. 使用JDOM生成/解析XML文档
  10. 2019全国大学生电子设计竞赛备赛笔记--风力摆--板球--模拟曲射电磁炮