diff --git a/PAR 153/test_communication/ecrire_port_serie.py b/PAR 153/test_communication/ecrire_port_serie.py new file mode 100644 index 0000000000000000000000000000000000000000..4fb2c36f5c15941b5bf0e143817cdd13339d0bc5 --- /dev/null +++ b/PAR 153/test_communication/ecrire_port_serie.py @@ -0,0 +1,58 @@ +import serial #Importation de la bibliothèque « pySerial » +import time +import json +import keyboard + +ser = serial.Serial(port="COM3", baudrate=115200, timeout=0.05,write_timeout=0.1) #Création du port lié au COM6 a une vitesse de 115200 bauds et un timout d’une seconde +ser.close() #Cloture du port pour le cas ou il serait déjà ouvert ailleurs +ser.open() #Ouverture du port + +if ser.isOpen(): + print(ser.name + " is open…") + print(ser.get_settings()) #Grace a ces 3 lignes lorsque le Port est ouvert c’est indiqué dans le LOG + +#ser.write(b‘hello’) #Ecriture de « Hello » sur le port + + +time.sleep(3) +"""script inputs""" +#""" +while True: + with open('input.txt') as f: + n = f.readlines() + n = f"{n}" + print("input: "+n) + ser.write((n+'\n').encode("utf-8")) + cc=str(ser.readline()) + print("output: "+cc[2:][:-5]) + print("Success") +#""" + + +"""kb inputs""" + +""" +while True: + forward = 0 + direction = 30 + if keyboard.is_pressed('q'): + direction=-70 + if keyboard.is_pressed('x'): + direction=direction/2 + elif keyboard.is_pressed('d'): + direction=130 + if keyboard.is_pressed('x'): + direction=direction/2 + if keyboard.is_pressed('z'): + forward = 20 + if keyboard.is_pressed('s'): + forward = -10 + n = f"['{str(forward)} {str(direction)} 0']" + print("input: "+str(n)) + ser.write((str(n)+'\n').encode("utf-8")) + cc=str(ser.readline()) + print("output: "+cc[2:][:-5]) + print("Success") +#""" + +ser.close() \ No newline at end of file diff --git a/PAR 153/test_communication/get_ports.py b/PAR 153/test_communication/get_ports.py new file mode 100644 index 0000000000000000000000000000000000000000..2740212d92a652cce7e29080a60710ae86bd77f5 --- /dev/null +++ b/PAR 153/test_communication/get_ports.py @@ -0,0 +1,36 @@ +import sys +import glob +import serial + + +def serial_ports(): + """ Lists serial port names + + :raises EnvironmentError: + On unsupported or unknown platforms + :returns: + A list of the serial ports available on the system + """ + if sys.platform.startswith('win'): + ports = ['COM%s' % (i + 1) for i in range(256)] + elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'): + # this excludes your current terminal "/dev/tty" + ports = glob.glob('/dev/tty[A-Za-z]*') + elif sys.platform.startswith('darwin'): + ports = glob.glob('/dev/tty.*') + else: + raise EnvironmentError('Unsupported platform') + + result = [] + for port in ports: + try: + s = serial.Serial(port) + s.close() + result.append(port) + except (OSError, serial.SerialException): + pass + return result + + +if __name__ == '__main__': + print(serial_ports()) \ No newline at end of file diff --git a/PAR 153/test_communication/input.txt b/PAR 153/test_communication/input.txt new file mode 100644 index 0000000000000000000000000000000000000000..898c34153b43d8987702c4fa1650643717a1364f --- /dev/null +++ b/PAR 153/test_communication/input.txt @@ -0,0 +1 @@ +0 0 0 \ No newline at end of file