Commit 6e52307b authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Mover código do termopar para a biblioteca

parent a9eda2d8
......@@ -51,45 +51,5 @@ def monitor(ctx, channel, interval, save):
except KeyboardInterrupt:
f.close()
@cli.command()
@click.option('--interval', default=1000, help='interval bewteen readings (ms)')
@click.option('--save', default='', help='file to save readings')
@click.pass_context
def lapma(ctx, interval, save):
#with tqdm(total=256, desc="Channel {}".format(channel), bar_format="{desc}|{bar}|{n_fmt}mV") as bar:
#while True:
# bar.n = int(ctx.obj['s'].readVoltage(channel) * 1000)
# bar.refresh()
# sleep(interval/1000.0)
if not save:
while True:
click.echo(ctx.obj['s'].readVoltage(channel))
sleep(interval/1000.0)
else:
f = open(save, 'w')
try:
while True:
voltage = ctx.obj['s'].readVoltage("A3")
current = ctx.obj['s'].readVoltage("A4")
thermocouple = ctx.obj['s'].readVoltage("TC")
try:
temperature = typeR.inverse_CmV((thermocouple + 0.001453125034) * -1000, Tref=25)
except ValueError:
temperature = "Error"
click.echo("Voltage: {}".format(voltage))
click.echo("Current: {}".format(current))
click.echo("Power: {}".format(voltage * current))
click.echo("TC (mV): {}".format(thermocouple))
click.echo("TC (celsius): {}".format(temperature))
click.echo("-----------------")
f.write(str(voltage) + '\t')
f.write(str(current) + '\t')
f.write(str(thermocouple) + '\t')
f.write(str(temperature) + '\n')
sleep(interval/1000.0)
except KeyboardInterrupt:
f.close()
if __name__ == '__main__':
cli(obj={})
from serial import Serial
from thermocouples_reference import thermocouples
class InvalidChannel(Exception):
pass
......@@ -19,6 +20,7 @@ class SACADA(object):
def __init__(self, location):
self.open(location)
self._zero = 0
def open(self, location):
self._serial = Serial(location, timeout=1) # We use USB-CDC so baud rate doesn't matter
......@@ -45,6 +47,18 @@ class SACADA(object):
return float(self.sendSCPICommand("SET:VOLT:DC {} {}".format(channel, voltage)))
def readTemperature(self, tref, _type='R'):
voltage = self.readVoltage("TC")
return thermocouples[_type].inverse_CmV((voltage - self._zero)*1000, Tref=tref)
def zero(self, samples=5):
# Take the average of a few measurements
average = 0
for i in range(samples): # Arbitrary
average += self.readVoltage("TC")
self._zero = average/samples
return self._zero
def _write(self, m):
self._serial.write(bytes(m, "utf-8"))
......
This diff is collapsed.
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