diff --git a/portail_coulissant/porcou_lib.py b/portail_coulissant/porcou_lib.py index d941743..4017c6b 100644 --- a/portail_coulissant/porcou_lib.py +++ b/portail_coulissant/porcou_lib.py @@ -106,6 +106,7 @@ def stop(): if scene.objects['System']['twins']: serial_close(scene.objects['System']['board']) time.sleep(1) + scene.objects['System']['plot']=False thread_cmd_stop() # Fin naturelle @@ -113,6 +114,7 @@ def end(): if scene.objects['System']['twins']: serial_close(scene.objects['System']['board']) time.sleep(1) + scene.objects['System']['plot']=False thread_cmd_end() def fin(): @@ -125,7 +127,19 @@ def quit(): # Visualisation des données ############################################################################### -# Grapheur +# Lancement du grapheur def plot(): - # subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")]) # Process bloquant - subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")]) + # subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], , stdin=subprocess.PIPE) # Process bloquant + scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], stdin=subprocess.PIPE, encoding = 'utf8') + scene.objects['System']['plot']=True + +# Envoi des données (Pipe) +def plot_maj(cont): + if cont.sensors['Plot'].positive : + time_send = str(scene.objects['System']['plot_time'])+'\n' + if scene.objects['System']['plot_proc'].poll()==None: + # scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Bloquant + scene.objects['System']['plot_proc'].stdin.write(time_send) + else: + print ("Stop") + scene.objects['System']['plot']=False diff --git a/portail_coulissant/portail_coulissant-17.blend b/portail_coulissant/portail_coulissant-17.blend index a5334de..49fcf14 100644 Binary files a/portail_coulissant/portail_coulissant-17.blend and b/portail_coulissant/portail_coulissant-17.blend differ diff --git a/twin_config.xml b/twin_config.xml index 04f58ec..888d7b7 100644 --- a/twin_config.xml +++ b/twin_config.xml @@ -1,7 +1,7 @@ - 1325 - 745 + 1609 + 905 1 \ No newline at end of file diff --git a/twin_plot.py b/twin_plot.py index d6466bf..7d9b207 100644 --- a/twin_plot.py +++ b/twin_plot.py @@ -1,12 +1,8 @@ -# import bge # Bibliothèque Blender Game Engine (UPBGE) -# from twin_threading import thread_plot_start, thread_plot_end # Multithreading import sys import random import matplotlib matplotlib.use('Qt5Agg') - -from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets - +from PyQt5 import QtCore, QtGui, QtWidgets from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar from matplotlib.figure import Figure @@ -38,7 +34,6 @@ class MplCanvas(FigureCanvasQTAgg): self.axes = fig.add_subplot(111) super(MplCanvas, self).__init__(fig) - class MainWindow(QtWidgets.QMainWindow): # Création du graphique @@ -65,22 +60,29 @@ class MainWindow(QtWidgets.QMainWindow): # Données # donnees = ([0,1,2,3,4], [10,1,20,3,40]) - print (self.xdata[len(self.xdata)-1]+1) + # print (self.xdata[len(self.xdata)-1]+1) new_x=self.xdata[len(self.xdata)-1]+1 self.xdata.append(new_x) self.ydata.append(random.randint(0, 10)) - # self.ydata = self.ydata + [random.randint(0, 10)] + # Lecture du Pipe + for line in sys.stdin: + print('Output:', line.rstrip()) + break + + # self.ydata = self.ydata + [random.randint(0, 10)] # Drop off the first y element, append a new one. # self.ydata = self.ydata[1:] + [random.randint(0, 10)] - self.canvas.axes.cla() # Clear the canvas. + + # Redraw + self.canvas.axes.cla() self.canvas.axes.plot(self.xdata, self.ydata, 'r') - # Trigger the canvas to update and redraw. self.canvas.draw() ############################################################################### # Application ############################################################################### + app = QtWidgets.QApplication(sys.argv) w = MainWindow() app.exec_()