コード例 #1
0
  def readEventsFromDevice(ean, channel, msgId):
      # Read all events from device matching ean, channel and msgId
      print "Open device..."
      # Create a device with the selected EAN number
      dev = kvDevice.kvDevice(ean=ean)
      # Open a device that matches our criteria (EAN)
      dev.memoOpen()
      # Mount the log files so we can acces them
      dev.memo.deviceMountKmf()
      # Read out how many log files that are availible on the card
      fileCount = dev.memo.logFileGetCount()
      print "Found %d file%s on card:" % (fileCount, "s" if fileCount > 1 else "")

      # Now we read all events from each file found on the card.
      for fileIndx in range (fileCount):
          # When mounting the logfile, we get an aproximate value back
          eventCount = dev.memo.logFileMount(fileIndx)
          print "File %3d: Contains less than %d events" % (fileIndx, eventCount)
          # We read out when the logging was started
          startTime = dev.memo.logFileGetStartTime()
          print "Logging started at %s\n" % startTime

          while True:
              # Read events from the log file, when no more events are availible,
              # 'None' will be returned
              event = dev.memo.logReadEventEx()
              if event is None:
                  break

              # We are only interested in events that are log messages
              if type(event) is kvmlib.logMsg:
                  # Also filter on message id and channel number
                  if event.id == msgId and event.channel == channel:
                      # We know the message data is a float, so convert it to a
                      # more usable format
                      value = raw2float(event.data)
                      # Now filter on the value
                      if value > 159 and value < 163:
                          # Get the time of the event
                          eventTime = getEventTime(startTime, event)
                          print "%s, Msg id %d value %f on channel %d:" % (eventTime, msgId, value, channel)
                          #print event

          print "\n"
          # Dismount to free up resources
          dev.memo.logFileDismount()
      # We are done, close the kvmlib handle to device
      dev.memoClose()
コード例 #2
0
ファイル: readlog.py プロジェクト: Kvaser/developer-blog
import sys
sys.path.append("D:/temp/CanlibSDK_5.14/Samples/Python")


import kvDevice

# Connect to our Kvaser Memorator Pro 5xHS with EAN 00778-9
dev = kvDevice.kvDevice(ean="73-30130-00778-9")
dev.open()
dev.memoOpen()
fileCount = dev.memo.logFileGetCount()
print "Found %d file%s on card:" % (fileCount,
                                    "s" if fileCount > 1 else "")

# Loop through all logfiles and write their contents to stdout
for fileIndx in range(fileCount):
    myEvents = dev.memoReadEvents(fileIndx)
    for event in myEvents:
        print event
    print "\n"

# Delete all logfiles
dev.memo.logFileDeleteAll()

# Close device
dev.memoClose()
dev.close()
コード例 #3
0
ファイル: envvar.py プロジェクト: Kvaser/developer-blog
# In order to hide these secret messages, we write them encoded ;-)
messages = [(1, "-Jung unccraf gb n sebt'f pne jura vg oernxf qbja?"),
            (2, "-Vg trgf gbnq njnl."),
            (3, "-Jul jnf fvk fpnerq bs frira?"),
            (4, "-Orpnhfr frira 'ngr' avar."),
            (5, "-Jung vf gur qvssrerapr orgjrra fabjzra naq fabjjbzra?"),
            (6, "-Fabjonyyf."),
            (7, "-Jurer qvq lbh svaq gurfr?"),
            (8, "-uggc://jjj.ynhtusnpgbel.pbz/wbxrf/jbeq-cynl-wbxrf")]


# We will be using the first Eagle device found connected to the PC
# For an introduction to the kvDevice object, see
# http://www.kvaser.com/developer-blog/object-oriented-approach-accessing-kvaser-device-python-3-3/
eagle_ean = "73-30130-00567-9"
dev = kvDevice.kvDevice(ean=eagle_ean)

# Open a handle to the device
dev.open()

# Load the t program into slot 0
dev.channel.scriptLoadFile(0, "envvar.txe")

# Start the program in slot 0
dev.channel.scriptStart(0)

# Our protocol states that we should wait until HostIdConnected is zero before trying to connect
print "Waiting for device to be free..."
# All calls to the kvScriptEnvarOpen() and kvScriptEnvvarGetXXX() functions are hidden in the
# envvar class inside canlib.py. Here we can access it directly with dev.channel.envvar.YYY
while dev.channel.envvar.HostIdConnected != 0: