Communication entre Blender et Qt5 (point d'étape)

This commit is contained in:
Philippe Roy 2023-01-15 11:18:40 +01:00
parent 9dba4ac24e
commit af09b80de2
4 changed files with 51 additions and 15 deletions

View File

@ -86,6 +86,7 @@ def init(cont):
scene.objects['Recepteur IR']['description']="Capteur barrage IR (absence d\"obstacle) : ir_recep()"
system_init() # Initialisation du système
scene.objects['System']['plot_proc'] = None # Initialisation du processus plot
def get_pin_config():
return pin_config

View File

@ -51,11 +51,12 @@ def commandes():
# mot_f(False)
# gyr(False)
# Ecrire votre code ici ...
gyr(True) # Activer le gyrophare
plot()
plot(['Led'])
while True:
pass
gyr(True)
tempo(0.25)
gyr(False)
tempo(0.25)
fin() # A garder

View File

@ -106,7 +106,7 @@ def stop():
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
time.sleep(1)
scene.objects['System']['plot']=False
scene.objects['System']['plot_draw']=False
thread_cmd_stop()
# Fin naturelle
@ -114,7 +114,7 @@ def end():
if scene.objects['System']['twins']:
serial_close(scene.objects['System']['board'])
time.sleep(1)
scene.objects['System']['plot']=False
scene.objects['System']['plot_draw']=False
thread_cmd_end()
def fin():
@ -128,18 +128,52 @@ def quit():
###############################################################################
# Lancement du grapheur
def plot():
def plot(data):
# subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], , stdin=subprocess.PIPE) # Process bloquant
# Terminer le processus précédent
if scene.objects['System']['plot_proc'] is not None:
if scene.objects['System']['plot_proc'].poll()==None:
scene.objects['System']['plot_proc'].terminate()
scene.objects['System']['plot_draw'] = True
scene.objects['System']['plot_time'] = 0
scene.objects['System']['plot_data'] = data # FIXME : conversion mémonique -> 3D
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)
# Communication avec Qt5
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
# Affichage du graphique
if scene.objects['System']['plot_draw']:
# Préparation du message
# FIXME : ajouter les valeurs réelles et valeurs numériques ('activated_real')
msg=str(scene.objects['System']['plot_time'])
for obj in scene.objects['System']['plot_data']:
if scene.objects[obj]['activated']:
msg = msg+",1"
else:
msg = msg+",0"
msg = msg+"\n"
# Envoi (Pipe)
if scene.objects['System']['plot_proc'].poll()==None:
# scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Communication bloquante
scene.objects['System']['plot_proc'].stdin.write(msg)
else:
print ("Stop")
scene.objects['System']['plot']=False
scene.objects['System']['plot_draw'] =False
scene.objects['System']['plot_proc'].terminate()
# Arret de l'affichage du graphique
else :
if scene.objects['System']['plot_proc'].poll()==None:
pass
else:
print ("Stop")
scene.objects['System']['plot']=False
scene.objects['System']['plot_draw'] =False
scene.objects['System']['plot_proc'].terminate()