Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import joulescope
- # Adjust logging level of Joulescope to avoid spamming the log
- logging.getLogger("joulescope").setLevel(logging.WARNING)
- logging.getLogger("jsdrv").setLevel(logging.WARNING)
- # Configure joulescope
- js = joulescope.scan_require_one(config="auto")
- js.open()
- js.parameter_set("source", "on")
- js.parameter_set("i_range", "auto")
- def joulescope_get_data():
- """Callback function to get current and voltage data from Joulescope.
- Packs it to a dictionary for easy storage as CSV.
- """
- try:
- data = js.read(contiguous_duration=0.1)
- # Atempt to re-open joulescope in case of error
- except: # pylint: disable=bare-except
- js.open()
- data = js.read(contiguous_duration=0.1)
- current, voltage = np.mean(data, axis=0)
- timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
- return {"timestamp": timestamp, "current": current, "voltage": voltage}
- # Hand of logging data to DictLogger in separate thread. Set interval to 0.9 as callback blocks for 0.1 second
- joulescope_logger = DictLogger(
- joulescope_get_data, output_path=os.path.join(OUTPUT_FOLDER, JOULESCOPE_LOG_FILENAME), interval=0.9
- )
- joulescope_logger.start_logging()
- ## Do some testing for 30 hours
- # Wrap up
- joulescope_logger.stop_logging()
- js.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement