Skip to content

mgsb/battlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

The battlab module provides a Python 3 class for interacting with a BattLab-One instrument.

  • Encapsulates instrument firmware serial protocol
  • Configure operating parameters via properties
  • Read 1 or N samples of current readings
  • Usable from CLI and GUI applications
  • Cross-platform

The battery modeling feature of the original BattLab-One application is not implemented here. This module is solely for data acquisition.

Use help(BattLabOne) for docs.

A command-line utility is provided in bl1cli.py. Invoke using python3 -m battlab or bl1cli after installing via setup.py or pip3 install.

Examples

Basic

From examples/basic/main.py:

from battlab import BattLabOne

def main():
    """Example usage of BattLabOne class"""
    bl1 = BattLabOne()
    bl1.reset()

    print("fw version: {}".format(bl1.version))
    print(bl1.VOLTAGES)

    bl1.current_range = BattLabOne.CurrentRange.HIGH

    bl1.voltage = 3.0

    data = bl1.take_n(bl1.sample(), 100)

    bl1.voltage = 0

    print(max(data), min(data), sum(data) / len(data))


if __name__ == "__main__":
    main()

Triggered

examples/triggered/main.py provides an example of triggered sampling.

CLI

CLI utility:

python3 bl1cli.py --help
usage: bl1cli.py [-h] [-c {high,low}] [-d DURATION] [-g] [--leave-on]
                 [--no-reset] [-o OUTPUT] [-p PORT] [-t] [-v VOLTAGE] [-w WAIT]

Measure current with BattLab-One

optional arguments:
  -h, --help            show this help message and exit
  -c {high,low}, --current-range {high,low}
                        use high or low current range
  -d DURATION, --duration DURATION
                        duration of measurement (seconds)
  -g, --graph           graph (plot) the sample data
  --leave-on            leave voltage on when exiting program
  --no-reset            do not reset device
  -o OUTPUT, --output OUTPUT
                        output file to store sample data in
  -p PORT, --port PORT  serial (com) port to use
  -t, --trigger         use triggered sampling
  -v VOLTAGE, --voltage VOLTAGE
                        voltage for testing
  -w WAIT, --wait WAIT  wait seconds before sampling

GUI

See examples/gui for an example that uses PySimpleGUI and matplotlib for a simple GUI application including plotting.

BattLab-One GUI Example

TODO

  • Test on Windows and macOS

About

Python module and utilities for BattLab-One

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages