Commit 42832918 authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Initial commit

parent de20f5df
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
tqdm = "*"
sacada = {editable = true,path = "."}
pyserial = "*"
click = "*"
[requires]
python_version = "3.5"
#!/usr/bin/env python3
from time import sleep
import click
from tqdm import tqdm
from sacada.SACADA import SACADA
@click.group()
@click.option('--port', default="/dev/ttyACM0", help='serial port location eg.: /dev/ttyACM0 (default)')
@click.pass_context
def cli(ctx, port):
ctx.obj['s'] = SACADA(port)
@cli.command()
@click.pass_context
def show(ctx):
click.echo(ctx.obj['s'].identify())
@cli.command()
@click.argument('channel')
@click.pass_context
def read(ctx, channel):
click.echo(ctx.obj['s'].readVoltage(channel))
@cli.command()
@click.argument('channel')
@click.option('--interval', default=1000, help='interval bewteen readings (ms)')
@click.pass_context
def monitor(ctx, channel, interval):
with tqdm(total=18, desc="Channel {}".format(channel), bar_format="{desc}|{bar}|{n_fmt}V") as bar:
while True:
bar.n = ctx.obj['s'].readVoltage(channel)
bar.refresh()
sleep(interval/1000.0)
if __name__ == '__main__':
cli(obj={})
from serial import Serial
class InvalidChannel(Exception):
pass
class InvalidOption(Exception):
pass
class SACADA(object):
"""SACADA boards Python interface
Right now it just implements support for SACADA Mini using SCPI
over USB-CDC. The plan is to provide a generic base class for use
with all SACADA boards.
"""
IN_CHANNELS = ["A0", "A1", "A2", "A3", "A4", "INSTR"]
OUT_CHANNELS = ["CH1", "CH2"]
def __init__(self, location):
self.open(location)
def open(self, location):
self._serial = Serial(location, timeout=1) # We use USB-CDC so baud rate doesn't matter
def close(self):
self._serial.close()
def identify(self):
return self.sendSCPICommand("*IDN?")
def sendSCPICommand(self, command):
self._write(command + "\r\n") # SACADA Mini requires \r\n at the end of commands
return self._read()
def readVoltage(self, channel):
if channel not in self.IN_CHANNELS:
raise InvalidChannel("{} is not a valid input channel".format(channel))
return float(self.sendSCPICommand("MEAS:VOLT:DC? {}".format(channel)))
def setVoltage(self, channel, voltage):
if channel not in self.OUT_CHANNELS:
raise InvalidChannel("{} is not a valid output channel".format(channel))
return float(self.sendSCPICommand("SET:VOLT:DC {} {}".format(channel, voltage)))
def _write(self, m):
self._serial.write(bytes(m, "utf-8"))
def _read(self):
return self._serial.readline().strip()
from . import SACADA
from setuptools import setup, find_packages
setup(name='sacada', version='0.1', packages=['sacada'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment