Bonjour,
J'aimerai savoir si je peux récupérer la trame envoyé par un appareil branché sur mon PC en USB?
J'aimerai faire un script comme si j'utilisais 'tera term' pour ne pas le citer.
Merci par avance pour vos retour.
Bonjour,
J'aimerai savoir si je peux récupérer la trame envoyé par un appareil branché sur mon PC en USB?
J'aimerai faire un script comme si j'utilisais 'tera term' pour ne pas le citer.
Merci par avance pour vos retour.
Salut,
Peut être avec pyserial?
- W
Voir ICI !
J'ai installé la bibliothèque Pyserial. Elle a l'air complète (enfin il faut voir à l'utilisation :-)).
Donc avec cette bibliothèque, je peux récupérer toute la trame si j'ai 1,2,3, 4 lignes voir plus?
J'ai trouvé un code qui correspond à mes besoins, je le poste si jamais quelqu'un est intéressé:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import serial import time # Optional (if using time.sleep() below) connected = False port = 'COM10' baud = 9600 try: print('Port.......'+port) print('Baudrate...'+str(baud)) ser = serial.Serial(port, baud, timeout=0) while (True): # NB: for PySerial v3.0 or later, use property `in_waiting` instead of function `inWaiting()` below! if (ser.inWaiting()>0): #if incoming bytes are waiting to be read from the serial input buffer data_str = ser.read(ser.inWaiting()).decode('ascii') #read the bytes and convert from binary array to ASCII print(data_str, end='') #print the incoming string without putting a new-line ('\n') automatically after every print() #Put the rest of your code you want here time.sleep(0.01) # Optional: sleep 10 ms (0.01 sec) once per loop to let other threads on your PC run during this time. except: print('Error '+port+ ' is not connected')
Je reviens vers vous car j'ai un soucis au niveau de la gestion de la trame... Je voudrais qu'une fois que j'ai récupéré mes x lignes de ma trame, j'arrête la scrutation pour traiter mes données...
Pour mémoire le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import serial import time # Optional (if using time.sleep() below) connected = False port = 'COM10' baud = 9600 try: print('Port.......'+port) print('Baudrate...'+str(baud)) ser = serial.Serial(port, baud, timeout=0) while (True): # NB: for PySerial v3.0 or later, use property `in_waiting` instead of function `inWaiting()` below! if (ser.inWaiting()>0): #if incoming bytes are waiting to be read from the serial input buffer data_str = ser.read(ser.inWaiting()).decode('ascii') #read the bytes and convert from binary array to ASCII print(data_str, end='') #print the incoming string without putting a new-line ('\n') automatically after every print() #Put the rest of your code you want here time.sleep(0.01) # Optional: sleep 10 ms (0.01 sec) once per loop to let other threads on your PC run during this time. except: print('Error '+port+ ' is not connected')
Partager