Skip to content
Snippets Groups Projects
Commit 0ecfd629 authored by Ouhouuhu's avatar Ouhouuhu
Browse files

test antenne

parent d87c8d07
Branches
No related tags found
No related merge requests found
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
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
0 0 0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment