SACADA.py 1.25 KB
Newer Older
1
from random import random
2
from time import sleep
3
from sacada import SACADA as _SACADA
4
from util.Logger import Logger
5 6

class SACADA(object):
7 8 9
    def __init__(self, location, channels):
        self.logger = Logger()

10
        self.channels = channels
11 12
        logger("[SACADA]", "Opening SACADA at {}".format(location))

13
        self.s = _SACADA(location)
14
        self.s.sendSCPICommand("IN:SCALE A0,V0256")
15 16 17 18 19
        logger("[SACADA]", str(self.s.identify()))
        logger("[SACADA]", "Valor do zero: {}".format(self.s.zero()))

    def read(self, channel):
        if channel["id"] == "TC":
20
            try:
21
                return self.s.readTemperature("A0", channel["type"])
22 23 24 25
            except:
                # Should handle value errors better
                return 0
        if channel["id"] == "PWR":
26 27 28 29
            # A3 é conectado na caixa preta (V1, escala de 540.55 Ampère por Volt) tabela no Git
            # A4 é conectado na caixa preta (V2, tensão RMS na amostra)
            return ((self.s.readVoltage("A3") * 540.55) - 20.12) * self.s.readVoltage("A4")

30
        if channel["id"] == "A3":
31
            return self.s.readVoltage("A3") * (400.0/10.0) - 3.0
32 33 34 35
        return self.s.readVoltage(channel["id"])

    def readAll(self):
        return [self.read("TC")]