Ejemplo n.º 1
0
def exit_gracefully(signum, frame):
    # restore the original signal handler as otherwise evil things will happen
    # in raw_input when CTRL+C is pressed, and our signal handler is not re-entrant
    signal.signal(signal.SIGINT, original_sigint)

    if input("\nReally quit? (y/n)> ").lower().startswith("y"):
        ljm.cleanInterval(interval_handle)
        ljm.close(handle)

        sys.exit(0)

    # restore the exit gracefully handler here
    signal.signal(signal.SIGINT, exit_gracefully)
        # Read AIN0
        result = ljm.eReadName(handle, name)

        # Print results
        print("%s reading: %f V, duration: %0.1f ms, skipped intervals: %i" %
              (name, result, duration, numSkippedIntervals))
        f.write("%s, %0.1f, %0.3f\r\n" % (curTimeStr, duration, result))
        lastTick = curTick
        curIteration = curIteration + 1
    except KeyboardInterrupt:
        break
    except Exception:
        import sys
        print(sys.exc_info()[1])
        break

print("\nFinished!")

#Get the final time
appEndTime = datetime.datetime.now()
# endTimeStr = appEndTime.isoformat(timespec='milliseconds')
endTimeStr = appStartTime.strftime("%Y/%m/%d %I:%M:%S%p")
print("The final time is: %s" % (endTimeStr))

# Close file
f.close()

# Close handles
ljm.cleanInterval(intervalHandle)
ljm.close(handle)
Ejemplo n.º 3
0
num_read_frames = len(read_names)
print("\nStarting %s read loops.%s\n" % (str(loopAmount), loopMessage))
interval_handle = 1
ljm.startInterval(interval_handle,
                  100000)  # Delay between readings (in microseconds)

dac_out = 0

while True:
    try:
        results = ljm.eReadNames(handle, num_read_frames, read_names)
        time = datetime.now()
        labjack_value_0 = results[0]
        print("Time: {}  Value: {:.3f} V".format(time, labjack_value_0))
        ljm.waitForNextInterval(interval_handle)

        ljm.eWriteNames(handle, 1, ["DAC0"], [dac_out])

        if dac_out < 5:
            dac_out += 0.05
        else:
            dac_out = 0

    except Exception:
        print(sys.exc_info()[1])
        break

# Close handles
ljm.cleanInterval(interval_handle)
ljm.close(handle)