¼¼Êõ²©¿Í

19/04/2016 ×÷Õß ÔÆº£ÓÎÏ·

ʹÓÃkvmlibÅäÖÃSD¿¨

ÕâÊÇʹÓÃÔÆº£ÓÎÏ· MemoratorµÚ¶þ´úÉ豸ͨ¹ýkvmlib½øÐÐÅäÖúͶÁÈ¡¼Ç¼Êý¾Ý4ƪϵÁÐÎÄÕµÄ×îºóһƪ£º

  1. kvmlibÈëÃÅÖ¸ÄÏ
  2. ÔÚÅäÖÃÖÐÌí¼Ó½Å±¾ºÍ´¥·¢Æ÷
  3. ÉîÈëÁ˽âkvmlib
  4. ʹÓÃkvmlibÅäÖÃSD¿¨

֮ǰÎÒÃÇͨ¹ý kvmlibÅäÖÃÉ豸£¬¼ìË÷ÅäÖúͼǼµÄÊý¾ÝÒÔ½øÐнøÒ»²½·ÖÎö¡£ÏÖÔÚÎÒÃÇÒª¿´¿´Èç¹ûÎÒÃÇֻʹÓòåÈëµ½É豸ÖеÄSD¿¨£¬ÄÇô»áÓÐÄÄЩ²»Í¬µÄ²Ù×÷¡£ÕâÖÖÇé¿öÈ¡¾öÓÚSD¿¨ÔÚÎïÀíÈÕ־λÖúÍÎÒÃÇÖ®¼ä´«ÊäµÄλÖá£

ΪÁË´ïµ½ÕâÏ×÷µÄÄ¿±ê£¬ÎÒÃÇ»áʹÓÃÒ»¸öÒѾ­ÔÚWindowsÖиñʽ»¯µÄ16GµÄSD¿¨£¬³õʼ»¯²¢ÅäÖøÿ¨£¬ÕâÑùÎÒÃǾÍÄܽ«´ËSD¿¨²åÈëµ½ÎÒÃǵÄÔÆº£ÓÎÏ· Memorator Pro 5xHS(±àÂë00778-9)ÖÐʹÓã¬Æä¹Ì¼þ°æ±¾Îª3.0¡£ÔËÐÐÈÕÖ¾»á»°Ö®ºó£¬ÎÒÃÇ»á´ÓÉ豸ÉÏÒÆ³ýSD¿¨£¬¶ÁÈ¡²¢ÖØÖÃÈÕÖ¾Îļþ¡£È«²¿³ÌÐòÁбí¿ÉÔÚGitHubÉÏ»ñµÃ¡£

4.1 ³õʼ»¯SD¿¨

Èç¹ûÄãÊÖͷûÓÐÏà¹ØÉ豸£¬ÄãÒ²¿ÉÒÔÓÃÄãµÄµçÄÔºÍmhydraformat.exe³ÌÐò³õʼ»¯SD¿¨¡£µ«ÊÇÕâÖÖ·½Ê½»á±ÈʹÓÃÉ豸¸ñʽ»¯»¨·Ñ¸ü¶àµÄʱ¼ä£¬³õʼ»¯Ò»¸ö16GµÄ¿¨´óÔ¼ÐèÒª»¨·Ñ3·ÖÖÓ¡£

mhydraformat.exe ³ÌÐò¿ÉÒÔÔÚÔÆº£ÓÎÏ· MemoratorÅäÖù¤¾ßµÄ°²×°Ä¿Â¼ÖÐÕÒµ½¡£1 Äã¿ÉÒÔʹÓèChelp²ÎÊýÔËÐиñʽ»¯³ÌÐòÀ´²é¿´Ê¹ÓðïÖúÎı¾¡£

[C:\]mhydraformat.exe --help
Disk formatting program for ÔÆº£ÓÎÏ· 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

½«ÄãµÄSD¿¨Á¬½ÓµçÄÔ£¬Çë×¢ÒâÇý¶¯Æ÷ÅÌ·û¡£ÎÒµÄʾÀýÖУ¬Ö¸¶¨SD¿¨ÔÚE:¡£¼ì²é¹ýSD¿¨µÄÄÚÈݺó£¬ÎÒÃÇÔËÐÐmhydraformat.exe³ÌÐò³õʼ»¯¸Ã¿¨¡£Çë×¢Ò⣬ÓÃÓÚÖ¸¶¨Òª·ÖÅ䏸DATABASE.BINµÄ¿Õ¼äµÄÃüÁîÐпª¹ØÔÚ´Ë´¦ÃüÃûΪ¨Cconfig¡£ÔÚʹÓÃWindows dirÃüÁî¸ñʽ»¯Ö®ºó£¬ÎÒÃÇÒ²ÒªÔٲ鿴SD¿¨µÄÄÚÈÝ¡£

dir E:
 Volume in drive E has no label.
 Volume Serial Number is 5C92-4738

 Directory of E:\

2016-02-23 08:41                  0 dummy_file
              1 File(s)               0 bytes
              0 Dir(s)   16?129?335?296 bytes free
mhydraformat.exe -d=E: -r=10000 -c=10
Formatting...done.
dir E:
 Volume in drive E has no label.

 Directory of E:\

2016-02-23 08:45 10?485?760 PARAM.LIF
2016-02-23 08:45 1?073?741?824 LOG00000.KMF
2016-02-23 08:45 1?073?741?824 LOG00001.KMF
2016-02-23 08:45 1?073?741?824 LOG00002.KMF
2016-02-23 08:45 1?073?741?824 LOG00003.KMF
2016-02-23 08:45 1?073?741?824 LOG00004.KMF
2016-02-23 08:45 736?649?216 LOG00005.KMF
2016-02-23 08:45 10?010?624 DATABASE.BIN
8 File(s) 6?125?854?720 bytes
0 Dir(s) 10?004?480?000 bytes free
echo
ECHO is on.

ÔÚ´ËÎÒÃÇ¿´µ½µÄÊǶþ½øÖÆÅäÖÃÎļþ(PARAM.LIF)¡¢ÈÕÖ¾ÎļþÈÝÆ÷(´ÓLOG00000.KMFµ½LOG00005.KMF)ÒÔ¼°ÎªÔƺ£ÓÎÏ· MemoratorÅäÖù¤¾ß±£ÁôµÄÅäÖÃÎļþ(10 MB?DATABASE.BIN)¡£ÎÒÃÇÒ²¿ÉÒÔ¿´µ½ÎÒÃÇËùÐèµÄ10000MB¿ÉÓÿռä¡£

4.2 ½«ÅäÖñ£´æµ½´ÅÅÌ

ΪÁËÖ±½ÓÏÂÔØÅäÖõ½SD¿¨£¬ÎÒÃÇÐèÒª´ò¿ªÎļþϵͳ£¬¶ø²»ÊÇÏñ֮ǰ·¢²¼µÄ²©ÎÄÖÐÄÇÑù´ò¿ªÉ豸¡£ÎÒÃÇ»¹ÐèҪ֪ͨkvmlibÎÒÃǵÄSD¿¨°²×°ÔÚÄÄ¡£ÕâÊÇͨ¹ýµ÷Óú¯ÊýkmfOpen()À´ÊµÏֵ쬲¢ÏòLOG00000.KMFÎļþÌṩÍêÕû·¾¶£¬ÆäÒ»Ö±´æÔÚÓÚÒÑÕýÈ·³õʼ»¯µÄSD¿¨ÄÚ¡£2

ÎÒÃÇÏÖÔÚҲʹÓÃkvaMemoLibXmlÖ±½Ó½«¶þ½øÖÆÅäÖÃÎļþ±àдµ½SD¿¨Àï¡£

ÈçǰËùÊö£¬ÎÒÃÇÈÔÐèÌṩÕýÈ·µÄÉ豸ÐͺÅ¡£

# Our SD card is mounted under E:, so that is where our
# binary configuration should be placed.
filename = "E:\\PARAM.LIF"
 
xl = kvaMemoLibXml.kvaMemoLibXml()
print "kvaMemoLibXml version: v%s" % xl.getVersion()
 
# Convert the previously validated XML configuration file
# and write the resulting binary configuration to SD card
xl.kvaXmlToFile("config.xml", filename)

Áбí18£º½«¶þ½øÖÆÅäÖÃÎļþ±àдµ½SD¿¨Àï

ÒªÒÔÃ÷ÎÄÐÎʽÏÂÔØÅäÖã¬ÎÒÃÇÖ»ÐèÏñ֮ǰÎÄÕÂÀïÌáµ½µÄÄÇÑù×ö¼´¿É£¬³ý´ËÖ®Íâ¿Éͨ¹ýWindows°²×°µã½«Ñ¹ËõÎļþÖ±½ÓдÈëSD¿¨¡£

import zipfile
 
# Our SD card is mounted under E:
filename = "E:\\config.zip"

# Creating zip archive
with zipfile.ZipFile(filename, mode='w',
                     compression=zipfile.ZIP_DEFLATED) as zipf:
    # Adding files to zip archive
    zipf.write("config.xml")
    zipf.write("myCanGenerator.txe")

Áбí19£ºÊ¹ÓÃzip°ü±àдÃ÷ÎÄÅäÖÃ

Èç¹ûÎÒÃÇÏÖÔڲ鿴ÎÒÃǵÄSD¿¨ÀïµÄÄÚÈÝ£¬ÎÒÃǻῴµ½ÈçÏÂÄÚÈÝ¡£

d:\temp\blog>dir E:
 Volume in drive E has no label.

 Directory of E:\

2016-02-19 07:58 40?308 PARAM.LIF
2016-02-11 14:43 1?073?741?824 LOG00000.KMF
2016-02-11 14:43 1?073?741?824 LOG00001.KMF
2016-02-11 14:43 1?073?741?824 LOG00002.KMF
2016-02-11 14:43 1?073?741?824 LOG00003.KMF
2016-02-11 14:43 1?073?741?824 LOG00004.KMF
2016-02-11 14:43 744?030?208 LOG00005.KMF
2016-02-11 14:43 10?002?432 DATABASE.BIN
2016-02-19 10:10 2?406 config.zip
              9 File(s) 6?122?784?474 bytes
              0 Dir(s) 10?010?435?584 bytes free

4.3 ´ÓSD¿¨¶ÁÈ¡½á¹û

µ±ÎÒÃÇ´ÓÏÖ³¡»ñÈ¡SD¿¨Ê±£¬ÎÒÃǽ«SD¿¨ÖØÐÂÁ¬½Óµ½ÎÒÃǵļÆËã»ú£¬²¢¿ªÊ¼ÑéÖ¤SD¿¨ÉϵÄLIOÊý¾Ý¸ñʽ°æ±¾¡£

ml = kvmlib.kvmlib()
  
# Our SD card is mounted under E:, so our LOG00000.KMF can
# be opened from here
filename = "E:\\LOG00000.KMF"

try:
    # Open the SD card
    # We have firmware version 3.0 in the device this SD card will
    # be inserted into, this means that the FW is using Lio Data
    # Format v5.0 and we should use kvmDEVICE_MHYDRA_EXT as
    # the deviceType
    lioDataFormat = ml.kmfOpenEx(filename,
                                 deviceType=kvmlib.kvmDEVICE_MHYDRA_EXT)
    print "Lio Data Format v%s" % lioDataFormat

    # Close SD card
    ml.close()

    # Verify that the LIO data format of the card corresponds to
    # the device type we used when opening the device
    if lioDataFormat != '5.0':
        print "Unexpected Lio Data Format:", lioDataFormat
        if lioDataFormat == '3.0':
            print("This log file can be read if you reopen the"
                  " device as kvmDEVICE_MHYDRA.")
        exit(1)
except kvmlib.kvmDiskNotFormated:
    print "SD card is not initialized..."
    exit(1)

Áбí20£ºÑéÖ¤SD¿¨ÉϵÄLIOÊý¾Ý¸ñʽ

ÏÂÒ»²½ÊǶÁ³ö¼Ç¼µÄÊý¾Ý¡£Óë֮ǰ²©ÎÄÖÐʹÓÃÁ¬½ÓÉ豸Ψһ²»Í¬Ö®´¦ÔÚÓÚ´ò¿ªSD¿¨¶ø·ÇÉ豸¡£¾ßÌåÏêÇéÇë²éÔÄ֮ǰ²©ÎÄ¡£

import glob
import os

ml = kvmlib.kvmlib()

# Our SD card is mounted under E:, so our LOG00000.KMF can
# be opened from here
filename = "E:\\LOG00000.KMF"

# Directory to put the resulting files in
resultDir = "result"

# Make sure the result directory exists and is empty
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)
 
# Open the SD card
# We have earlier verified that the SD card is using Lio Data Format v5.0
# and we should use kvmDEVICE_MHYDRA_EXT as the deviceType
ml.kmfOpen(filename, deviceType=kvmlib.kvmDEVICE_MHYDRA_EXT)
  
# Read number of recorded logfiles
fileCount = ml.logFileGetCount()
print "Found %d file%s on card:" % (fileCount,
                                    "s" if fileCount > 1 else "")

# Loop through all logfiles and write their contents to .kme50 files
for fileIndx in range(fileCount):
    eventCount = ml.logFileMount(fileIndx)
    print "\tFile %3d: %10d events" % (fileIndx, eventCount)
    logEvent = ml.logFileReadEventLogFormat()
 
    # The first logEvent contains device information
    memoEvent = logEvent.createMemoEvent()
    sn = memoEvent.serialNumber
    ean_lo = memoEvent.eanLo
    ean_sn = "%05x-%x_%d" % ((ean_lo >> 4) & 0xfffff, ean_lo & 0xf, sn)

    # Add EAN and serial number info to filename
    logfileName = "log_%s_%d.kme50" % (ean_sn, fileIndx)
    ml.kmeCreateFile(logfileName, kvmlib.kvmFILE_KME50)
    while logEvent is not None:
        # Write event to stdout
        print logEvent
        ml.kmeWriteEvent(logEvent)
        # Read next event
        logEvent = ml.logFileReadEventLogFormat()
    ml.kmeCloseFile()
  
# Delete all logfiles
ml.logFileDeleteAll()
  
# Close device
ml.close()

Áбí21£º´ÓSD¿¨¶ÁÈ¡¼Ç¼µÄÊý¾Ý²¢±£´æÖÁ.kme50Îļþ

4.4 ´ÓSD¿¨¶ÁÈ¡ÅäÖÃ

»¹Ê£×îºóÒ»¼þÊ£ºÈçºÎ¶Á»ØÎÒÃÇ֮ǰʹÓÃWindows°²×°µãÖÃÓÚSD¿¨ÉϵÄѹËõÅäÖá£

import glob
import os
import shutil

# Our SD card is mounted under E:, so our LOG00000.KMF can
# be opened from here
filename = "E:\\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 %s" % file
    else:
        print "Copying %s" % file
        shutil.copy(file, ".")

Áбí22£º´ÓSD¿¨¸´ÖÆËùÓÐÓû§Îļþ

Copying E:\\PARAM.LIF
Skipping E:\\LOG00000.KMF
Skipping E:\\LOG00001.KMF
Skipping E:\\LOG00002.KMF
Skipping E:\\LOG00003.KMF
Skipping E:\\LOG00004.KMF
Skipping E:\\LOG00005.KMF
Copying E:\\DATABASE.BIN
Copying E:\\config.zip

ÖÁ´Ë£¬¸ÃÔËÐгÌÐòµÄËùÓÐÊä³ö¶¼ÒÑ·ÅÈë½á¹ûÎļþĿ¼ÄÚ¡£

d:\temp\blog>dir result
 Volume in drive D is HDD
 Volume Serial Number is 26E3-B474

 Directory of d:\temp\blog\result

2016-02-22 16:06     <DIR>          .
2016-02-22 16:06     <DIR>          ..
2016-02-22 16:06              2?406 CONFIG.ZIP
2016-02-22 16:06         10?002?432 DATABASE.BIN
2016-02-22 16:06             40?308 PARAM.LIF
              3 File(s)      10?045?146 bytes
              2 Dir(s)   961?850?183?680 bytes free

d:\temp\blog>More?

ÒÔÉϾÍÊÇÈ«²¿µÄÎÄÕÂÄÚÈÝ£¬Ï£Íû¸ÃÎÄÕÂϵÁÐÄܹ»°ïÄãÁ˽⵽kvmlibµÄ¸ü¶à֪ʶ£¬µ±¹ÜÀíÔÆº£ÓÎÏ·¼Ç¼ÒÇÉ豸ʱ£¬ÈÃÄãÁ˽â³Ìʽ¿âµÄ¾ßÌåÔËÓá£

½Å×¢

1 ÔÆº£ÓÎÏ· MemoratorÅäÖù¤¾ßµÄĬÈϰ²×°Î»ÖÃΪ£º

C:\Program Files (x86)\ÔÆº£ÓÎÏ·\MemoratorConfigTool\mhydraformat.exe

2 ÎÒÃÇֻΪÈÝÆ÷ÎļþµÄµÚÒ»¸öÈÕÖ¾ÎļþÌṩÎļþÃû£¬ÒòΪÆäÓàµÄ½«½ô¸úÔÚ¿¨ÉϵĵÚÒ»¸öÎļþÖ®ºó¡£

Author Image

Magnus Carlsson

Margus CarlssonÊÇÔÆº£ÓÎÏ· AB¹«Ë¾µÄÈí¼þ¿ª·¢ÈËÔ±£¬´Ó2007ÄêÒÔÀ´Éî¶È²ÎÓëÁËÔÆº£ÓÎÏ·¹Ì¼þºÍÈí¼þµÄ¿ª·¢¡£Ëû»¹ÎªÔƺ£ÓÎÏ·µÄ¼¼Êõ²©¿Í׫дÁËÐí¶àÓÃÁ÷ÐеÄPythonÓïÑÔ±àдӦÓóÌÐòµÄÎÄÕ¡£

¡¾ÍøÕ¾µØÍ¼¡¿¡¾sitemap¡¿