Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
2.2 kB
2
Indexable
Never
   def animate(self, i, writer, file, anfStr, isCharger ):

        if self.input_en and i == 5:
            sendstringSetCurr = f"OUT:0"
            sendstringSetCurr = f"ISET:{anfStr}"
            self.set_values(self.port, sendstringSetCurr)
            self.set_values(self.port, "OUT:1")

        zeit = time.strftime("%H:%M:%S", time.localtime())

        if isCharger:
            voltage = float(self.get_data(self.port, "VOUT?"))
            current = float(self.get_data(self.port, "IOUT?"))

        else:
            voltage = float(self.get_data(self.port, ":MEAS:VOLT?")[:-1])
            current = float(self.get_data(self.port, ":MEAS:CURR?")[:-1])

        power = voltage * current
        temperature = self.get_temperature()


        if voltage == anfStr:
            # exit measurement, start next one



    def run_charger(self, port, filename, ladeSchlussV, anfLadeStr):
        self.filename = filename
        self.port = port

        try:
            with open((f"data/{filename}.csv"), "w", newline="") as file:

                writer = csv.writer(file, delimiter=";")

                writer.writerow(["Time", "Voltage", "Current",
                                "Charge", "Power", "Energy", "Temperature"])

                print("Setze Spannungsbegrenzung...")

                self.set_values(self.port, f"VSET:{ladeSchlussV}")
                self.set_values(self.port, f"ISET:{anfLadeStr}")

                self.value_list_init()
                self.input_en = self.set_input()
                print("Starte Messung...")

                self.t1 = 0
                self.t2 = 0

                def init_pass():
                     pass

                self.set_values(self.port, f"VSET:{ladeSchlussV}")
                self.set_values(self.port, "ISET:0")
                self.set_values(self.port, "OUT:1")
                self.ani = animation.FuncAnimation(
                    self.fig, self.animate, fargs=(writer, file, anfLadeStr, True), interval=1000, init_func=init_pass)
                plt.show()

        except KeyboardInterrupt:
            print("Verbindung getrennt.")

        self.set_values(self.port, "OUT:0")
        self.port.close()