mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Fermeture de la liaison propre
This commit is contained in:
parent
ea3a95dc36
commit
e968972cbe
@ -29,7 +29,13 @@ from porcou_lib import * # Bibliothèque portail coulissant
|
||||
###############################################################################
|
||||
|
||||
# Brochage du portail coulissant
|
||||
brochage={}
|
||||
carte = None
|
||||
brochage={
|
||||
'bp_ext' : 2,'bp_int' : 3,
|
||||
'fdc_o' : 4,'fdc_f' : 5,
|
||||
'mot_o' : 6,'mot_f' : 7,
|
||||
'gyr' : 8,
|
||||
'ir_emett' : 9,'ir_recept' : 10}
|
||||
|
||||
###############################################################################
|
||||
# Fonctions
|
||||
@ -41,10 +47,9 @@ brochage={}
|
||||
|
||||
def commandes():
|
||||
|
||||
# Ecrire votre code ici ...
|
||||
# jumeau()
|
||||
gyr(True) # Activer le gyrophare
|
||||
# ir_emet(True)
|
||||
# jumeau(carte, brochage)
|
||||
jumeau(brochage)
|
||||
gyr(True)
|
||||
while True:
|
||||
pass
|
||||
|
||||
@ -59,4 +64,4 @@ def commandes():
|
||||
if __name__=='start':
|
||||
thread_cmd_start(commandes)
|
||||
if __name__=='stop':
|
||||
thread_cmd_stop()
|
||||
stop()
|
||||
|
@ -1,6 +1,8 @@
|
||||
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
|
||||
# rom twin_serial import open, close # Liaison série
|
||||
import twin_serial # Liaison série
|
||||
# import twin_serial # Liaison série
|
||||
import time
|
||||
|
||||
###############################################################################
|
||||
@ -16,19 +18,19 @@ import time
|
||||
scene = bge.logic.getCurrentScene()
|
||||
|
||||
# Carte du jumeau numérique
|
||||
board = None
|
||||
board_it = None # Iterator (input)
|
||||
# board = None
|
||||
# board_it = None # Iterator (input)
|
||||
|
||||
# Brochage du jumeau numérique
|
||||
bp_int_pin = None
|
||||
bp_ext_pin = None
|
||||
fdc_o_pin = None
|
||||
fdc_f_pin = None
|
||||
ir_emett_pin = None
|
||||
ir_recept_pin = None
|
||||
mot_o_pin = None
|
||||
mot_f_pin = None
|
||||
gyr_pin = None
|
||||
# bp_int_pin = None
|
||||
# bp_ext_pin = None
|
||||
# fdc_o_pin = None
|
||||
# fdc_f_pin = None
|
||||
# ir_emett_pin = None
|
||||
# ir_recept_pin = None
|
||||
# mot_o_pin = None
|
||||
# mot_f_pin = None
|
||||
# gyr_pin = None
|
||||
|
||||
# UPBGE constants
|
||||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||||
@ -101,8 +103,9 @@ def bp_int ():
|
||||
# Jumeau
|
||||
###############################################################################
|
||||
|
||||
def jumeau ():
|
||||
twin_serial.open()
|
||||
def jumeau (brochage):
|
||||
scene.objects['System']['board']=twin_serial.open()
|
||||
print ("jumeau : ", scene.objects['System']['board'])
|
||||
|
||||
###############################################################################
|
||||
# Cycle
|
||||
@ -112,10 +115,18 @@ def jumeau ():
|
||||
def tempo (duree):
|
||||
time.sleep(duree)
|
||||
|
||||
# Fin
|
||||
# Arrêt
|
||||
def stop():
|
||||
if scene.objects['System']['twins']:
|
||||
twin_serial.close(scene.objects['System']['board'])
|
||||
time.sleep(0.5)
|
||||
thread_cmd_stop()
|
||||
|
||||
# Fin naturelle
|
||||
def end():
|
||||
if scene.objects['System']['twins']:
|
||||
twin_serial.close()
|
||||
twin_serial.close(scene.objects['System']['board'])
|
||||
time.sleep(0.5)
|
||||
thread_cmd_end()
|
||||
|
||||
def fin():
|
||||
|
Binary file not shown.
5
twin.py
5
twin.py
@ -141,19 +141,20 @@ def cmd_init():
|
||||
scene.objects['ResetView-Hl'].setVisible(False,False)
|
||||
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
||||
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
||||
# scene.objects['Twins-icon'].setVisible(False,True)
|
||||
|
||||
# UI : Text, ...
|
||||
scene.objects['Cmd-text']['Text']=""
|
||||
scene.objects['Cmd-text'].setVisible(True,False)
|
||||
scene.objects['Twins-text']['Text']="Connection fermée."
|
||||
# scene.objects['Twins-text'].setVisible(False,False)
|
||||
|
||||
# Windows
|
||||
windows=("Doc", "Doc_chap-general", "Doc_chap-system", "Doc_chap-python", "About")
|
||||
for window in windows:
|
||||
scene.objects[window].setVisible(False,True)
|
||||
|
||||
# Jumeau
|
||||
scene.objects['System']['twins'] = False
|
||||
|
||||
##
|
||||
# Highlight des commandes
|
||||
##
|
||||
|
@ -101,7 +101,8 @@ def close(cont):
|
||||
# scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud']) # Crash de UPBGE sur la supression de l'Overlay
|
||||
scene.objects['Twins-icon'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay
|
||||
scene.objects['Twins-text'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay
|
||||
scene.objects['Cmd-text']['Text']= " " # Redraw pour afficher scene.objects['Twins-icon'] et scene.objects['Twins-text']
|
||||
bpy.context.view_layer.update() # Bug de mise à jour
|
||||
# scene.objects['Cmd-text']['Text']= " " # Redraw pour afficher scene.objects['Twins-icon'] et scene.objects['Twins-text']
|
||||
scene.objects['About'].setVisible(False,True)
|
||||
|
||||
##
|
||||
|
@ -1,7 +1,7 @@
|
||||
<data>
|
||||
<screen>
|
||||
<width>1411</width>
|
||||
<height>794</height>
|
||||
<width>1318</width>
|
||||
<height>741</height>
|
||||
<quality>1</quality>
|
||||
</screen>
|
||||
</data>
|
@ -318,9 +318,6 @@ def close(cont):
|
||||
scene.objects["Doc_text-"+card].setVisible(False,True)
|
||||
else:
|
||||
text_dynamic_hide()
|
||||
# scene.objects['Twins-icon'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay
|
||||
# scene.objects['Twins-text'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay
|
||||
# scene.objects['Cmd-text']['Text']= " " # Redraw pour afficher scene.objects['Twins-icon'] et scene.objects['Twins-text']
|
||||
|
||||
##
|
||||
# Highlight
|
||||
|
@ -19,7 +19,9 @@ from serial.tools.list_ports import comports # Détection du port automatique
|
||||
# UPBGE scene
|
||||
scene = bge.logic.getCurrentScene()
|
||||
|
||||
board = None
|
||||
# Carte du jumeau numérique
|
||||
# board = None
|
||||
# board_it = None # Iterator (input)
|
||||
|
||||
##
|
||||
# Recherche automatique du port
|
||||
@ -83,7 +85,6 @@ def devices():
|
||||
|
||||
# def jumeau(pins):
|
||||
def open():
|
||||
global board
|
||||
|
||||
# UI : étape 1
|
||||
scene.objects['Twins-text']['Text'] = "Connection en cours ..."
|
||||
@ -129,7 +130,8 @@ def open():
|
||||
# mot_o_pin = board_io('d:'+str(es_dict['mot_o'])+':o') # Ouvrir le portail (moteur sens trigo)
|
||||
# mot_f_pin = board_io('d:'+str(es_dict['mot_f'])+':o') # Fermer le portail (moteur sens horaire
|
||||
# ir_emett_pin = board_io('d:'+str(es_dict['ir_emett'])+':o') # Emetteur pour le capteur barrage IR
|
||||
return True
|
||||
return (board)
|
||||
# return True
|
||||
|
||||
# def board_io(da,pin,io):
|
||||
# if pin_def is not None:
|
||||
@ -141,8 +143,7 @@ def open():
|
||||
# Fermeture de la communication série
|
||||
##
|
||||
|
||||
def close():
|
||||
global board
|
||||
def close(board):
|
||||
scene.objects['Twins-text']['Text'] = "Connection fermée."
|
||||
board.exit() # Fermer proprement la communication avec la carte
|
||||
scene.objects['System']['twins'] = False
|
||||
|
@ -3,7 +3,6 @@ import threading # Multithreading
|
||||
import trace
|
||||
import sys
|
||||
import time
|
||||
import twin_serial # Liaison série
|
||||
|
||||
###############################################################################
|
||||
# twin_threading.py
|
||||
@ -104,8 +103,6 @@ def thread_cmd_start(fct):
|
||||
thread_start(threads_cmd, "commands", fct)
|
||||
|
||||
def thread_cmd_stop():
|
||||
if scene.objects['System']['twins']:
|
||||
twin_serial.close()
|
||||
thread_stop(threads_cmd, "commands")
|
||||
|
||||
def thread_cmd_end():
|
||||
|
Loading…
Reference in New Issue
Block a user