From f1a4a5c7cdf78c681c51c130329831710e056b46 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sun, 3 May 2026 15:05:17 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20fonction=20de=20d=C3=A9tectio?= =?UTF-8?q?n=20de=20carte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IdentificationCartes.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 IdentificationCartes.py diff --git a/IdentificationCartes.py b/IdentificationCartes.py new file mode 100644 index 0000000..4457541 --- /dev/null +++ b/IdentificationCartes.py @@ -0,0 +1,40 @@ +import serial +from time import sleep +from LectureReception import lire_message + + +def ping(ser: serial.Serial): + # lecture de 1 octet à l'adresse 0. + if ser.in_waiting: + ser.read(ser.in_waiting) # On vide le tampon + + # On teste la carte actionneur + ser.write(b'?') + sleep(0.01) + if ser.in_waiting: + message = ser.read(ser.in_waiting) # On vide le tampon + if(message[0] == b'A'[0]): + print("Carte Actionneur") + else: + print("Carte inconue : " + str(message)) + return + + # On teste les cartes au protocole "com_v2" (détection, propulsion) + ser.write(b'\xFF\xFF\x05dD\x00\x01\x00') + sleep(0.01) + messages, tmp = lire_message(ser, b'') + if messages is not []: + if messages[0][0] == b'D'[0]: + print("Carte de détection") + return + if messages[0][0] == b'P'[0]: + print("Carte de propulsion") + return + + + +if __name__ == "__main__": + ser = serial.Serial('/dev/ttyACM0' , 115200) + while(1): + ping(ser) + sleep(1) \ No newline at end of file