Exemple #1
0
    ]
    aValues = [199, 10.0, 0, 0, 199, 10.0, 0, 0]
numFrames = len(names)
ljm.eWriteNames(handle, numFrames, names, aValues)

print("\nSet configuration:")
for i in range(numFrames):
    print("    %s : %f" % (names[i], aValues[i]))

# Read AIN0 and AIN1 from the LabJack with eReadNames in a loop.
numFrames = 2
names = ["AIN0", "AIN1"]

print("\nStarting %s read loops.%s\n" % (str(loopAmount), loopMessage))
intervalHandle = 1
ljm.startInterval(intervalHandle,
                  1000000)  # Delay between readings (in microseconds)
i = 0
while True:
    try:
        results = ljm.eReadNames(handle, numFrames, names)
        print("AIN0 : %f V, AIN1 : %f V" % (results[0], results[1]))
        ljm.waitForNextInterval(intervalHandle)
        if loopAmount is not "infinite":
            i = i + 1
            if i >= loopAmount:
                break
    except KeyboardInterrupt:
        break
    except Exception:
        import sys
        print(sys.exc_info()[1])
# Build a file-name and the file path.
fileName = timeStr + "-%s-Example.csv" % (name)
filePath = os.path.join(cwd, fileName)

# Open the file & write a header-line
f = open(filePath, 'w')
f.write("Time Stamp, Duration/Jitter (ms), %s" % (name))

# Print some program-initialization information
print("The time is: %s" % (startTimeStr))
print("Reading %s %i times and saving data to the file:\n - %s\n" %
      (name, numIterations, filePath))

# Prepare final variables for program execution
intervalHandle = 0
ljm.startInterval(intervalHandle, rateUS)
curIteration = 0
numSkippedIntervals = 0

lastTick = ljm.getHostTick()
duration = 0

while curIteration < numIterations:
    try:
        numSkippedIntervals = ljm.waitForNextInterval(intervalHandle)
        curTick = ljm.getHostTick()
        duration = (curTick - lastTick) / 1000
        curTime = datetime.datetime.now()
        curTimeStr = curTime.strftime("%Y/%m/%d %I:%M:%S%p")

        # Read AIN0
        "AIN0_SETTLING_US"
    ]
    aValues = [199, 10, 0, 0]
numFrames = len(aNames)
ljm.eWriteNames(handle, numFrames, aNames, aValues)

print("\nSet configuration:")
for i in range(numFrames):
    print("    %s : %f" % (aNames[i], aValues[i]))

print("\nStarting %s read loops.%s\n" % (str(loopAmount), loopMessage))
i = 0
dacVolt = 0.0
fioState = 0
intervalHandle = 1
ljm.startInterval(intervalHandle, 1000000)
while True:
    try:
        # Setup and call eWriteNames to write to DAC0, and FIO5 (T4) or
        # FIO1 (T7 and other devices).
        # DAC0 will cycle ~0.0 to ~5.0 volts in 1.0 volt increments.
        # FIO5/FIO1 will toggle output high (1) and low (0) states.
        if deviceType == ljm.constants.dtT4:
            aNames = ["DAC0", "FIO5"]
        else:
            aNames = ["DAC0", "FIO1"]
        dacVolt = i % 6.0  # 0-5
        fioState = i % 2  # 0 or 1
        aValues = [dacVolt, fioState]
        numFrames = len(aNames)
        ljm.eWriteNames(handle, numFrames, aNames, aValues)