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

Prevenir que o GC mate o gráfico

parent 7ee0c7fe
......@@ -3,13 +3,11 @@ device:
type: mock
location: "/dev/ttyACM0"
channels:
- id: "PWR"
name: "Potência"
- id: "A0"
name: "Amostra"
color: "#FF0000"
unit: "W"
- id: "TC"
name: "Temperatura"
unit: "V"
- id: "A3"
name: "Pressão"
color: "#0000FF"
unit: "ºC"
tc: 18
type: "R"
unit: "bar"
from random import random
from time import sleep
from sacada import SACADA as _SACADA
class SACADA(object):
def __init__(self, logger, location, channels):
self.channels = channels
self.s = _SACADA(location)
self.s.sendSCPICommand("IN:SCALE A0,V0256")
logger("[SACADA]", "Opening SACADA at {}".format(location))
logger("[SACADA]", str(self.s.identify()))
logger("[SACADA]", "Valor do zero: {}".format(self.s.zero()))
......@@ -18,6 +20,8 @@ class SACADA(object):
return 0
if channel["id"] == "PWR":
return self.s.readVoltage("A3") * self.s.readVoltage("A4")
if channel["id"] == "A3":
return self.s.readVoltage("A3") * (250.0/10.0)
return self.s.readVoltage(channel["id"])
def readAll(self):
......
......@@ -258,7 +258,7 @@ font: 10pt &quot;Liberation Mono&quot;;</string>
<string notr="true"/>
</property>
<property name="title">
<string>Temperatura</string>
<string>Amostra</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set>
......@@ -298,7 +298,7 @@ font: 10pt &quot;Liberation Mono&quot;;</string>
<string notr="true"/>
</property>
<property name="title">
<string>Potência</string>
<string>Pressão</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0">
<item alignment="Qt::AlignRight">
......
from datetime import datetime
from PyQt5.QtCore import QTimer
from pyqtgraph import AxisItem, InfiniteLine, mkColor, mkPen, setConfigOption
from interfaces import *
......@@ -17,6 +18,9 @@ class Graph():
self.axis = []
self.config = Config().data
self.device = self.config["device"]
today = datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
self.logFile = open("/home/phckopper/logs/{}-calib.csv".format(today), "w")
self._configurePlots()
self.lastupdated = 0
......@@ -30,14 +34,18 @@ class Graph():
self.graph.setBackground((240, 240, 240))
def updateGraphs(self):
self.logFile.write("\n")
for i, channel in enumerate(self.device["channels"]):
self.dataX[i].append(self.dataX[i][-1] + self.interval/1000.0)
self.dataY[i].append(self.interface.read(self.device["channels"][i]))
self.plots[i].getViewBox().setRange(xRange=(self.dataX[0][-1] - 10, self.dataX[0][-1]))
self.plots[i].setData(self.dataX[i], self.dataY[i], clear=True)
#self.plots[i].getViewBox().setRange(xRange=(self.dataX[0][-1] - 10, self.dataX[0][-1]))
self.plots[i].setData(self.dataX[i], self.dataY[i])
self.logFile.write("{},".format(self.dataY[i][-1]))
self.logFile.write("{}".format(self.dataX[0][-1]))
self.logFile.flush()
self.ui.forceLabel.setText("{:.4f} U".format(self.dataY[0][-1]))
self.ui.calibratorLabel.setText("{:.2f} ºC".format(self.dataY[1][-1]))
self.ui.forceLabel.setText("{:.2f} bar".format(self.dataY[1][-1]))
self.ui.calibratorLabel.setText("{:.4f} mV".format(self.dataY[0][-1] * 1000))
pg.QtGui.QApplication.processEvents()
def setInterval(self, interval):
......@@ -62,10 +70,14 @@ class Graph():
self.plots.append(plot)
plotItem.setClipToView(True)
plotItem.showGrid(True)
plotItem.getViewBox().setMouseEnabled(False, False)
#plotItem.getViewBox().setMouseEnabled(False, False)
plotItem.getViewBox().enableAutoRange(plotItem.getViewBox().YAxis)
#plotItem.getViewBox().setAutoPan(x=True)
self.dataX.append([0])
self.dataY.append([0])
plotItem.setLabel("left", text=channel["name"], units=channel["unit"])
self.logger("[GRAPH]", "Added channel {}".format(channel["name"]))
self.logFile.write("{},".format(channel["name"]))
self.logFile.write("timestamp")
from datetime import datetime
from time import sleep
from time import sleep, time
from sys import exit
from PyQt5.QtCore import QThread, QTimer
from PyQt5.QtWidgets import QMessageBox, QApplication
......@@ -8,36 +8,36 @@ from config import Config
from util.Timer import Timer
class MainThread():
def __init__(self, ui, parent=None):
def __init__(self, ui, timer):
#super(MainThread, self).__init__(parent)
self.ui = ui
self.data = []
self.graph = Graph(self.ui, 100, self._log)
self.graph = Graph(self.ui, 250, self._log)
#self.upTimer = Timer()
#self.downTimer = Timer(delay=10)
try:
self.config = Config()
except FileNotFoundError:
self._fatal("Arquivo de configuração não encontrado!")
self.graphTimer = QTimer(ui.mainGraph)
self.graphTimer = timer
self.graphTimer.timeout.connect(self.graph.updateGraphs)
self.graphTimer.start(self.graph.interval)
self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate)
def run(self):
pass
#self.ui.startTimerButton.pressed.connect(self._startTimer)
#self.ui.stopTimerButton.pressed.connect(self._stopTimer)
#self.ui.startRegTimerButton.pressed.connect(self._startTimer)
#self.ui.stopRegTimerButton.pressed.connect(self._stopTimer)
#self.ui.playPauseButton.aboutToShow.connect(self._playPause)
#self.ui.finalizeButton.aboutToShow.connect(self._finalize)
#while True:
while True:
#self._updateTimers()
#if self.graph.running:
# self.graph.updateGraphs()
#QApplication.processEvents()
#sleep(self.graph.interval/1000.0) # Updates at 30FPS
QApplication.processEvents()
print(time())
sleep(self.graph.interval/1000.0) # Updates at 30FPS
def _updateSamplingRate(self):
MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000]
......
......@@ -269,9 +269,9 @@ class Ui_Generico(object):
self.samplingCBox.setItemText(7, _translate("Generico", "5 seg"))
self.samplingCBox.setItemText(8, _translate("Generico", "10 seg"))
self.absValGBox.setTitle(_translate("Generico", "Valores Absolutos"))
self.calibratorGBox.setTitle(_translate("Generico", "Temperatura"))
self.calibratorGBox.setTitle(_translate("Generico", "Amostra"))
self.calibratorLabel.setText(_translate("Generico", "0 mV"))
self.forceGBox.setTitle(_translate("Generico", "Potência"))
self.forceGBox.setTitle(_translate("Generico", "Pressão"))
self.forceLabel.setText(_translate("Generico", "0 Tonf"))
self.fileMenu.setTitle(_translate("Generico", "Arquivo"))
self.stageMenu.setTitle(_translate("Generico", "Etapa"))
......
import sys
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import QTimer
from .GenericoW import Ui_Generico
from threads.MainThread import MainThread
......@@ -17,8 +18,9 @@ class Ui_MainWindow(object):
self.ui.setupUi(self.dialog)
print(self.ui)
main_thread = MainThread(self.ui)
#main_thread.finished.connect(self.app.exit)
#main_thread.start()
self.timer = QTimer(self.app)
self.main_thread = MainThread(self.ui, self.timer)
self.dialog.showMaximized()
#main_thread.finished.connect(self.app.exit)
#main_thread.start()
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