Bonjour,
Pour un projet, je dois simuler une télécommande pour tester un système de traductions de protocoles.
La télécommande que je dois simuler envoie des commandes de type LANC sur le port série et je les récupères sur une carte Arduino pour voir si je reçois bien les bon octets.
Voici le code Python exécuté sur mon ordinateur :
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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
# coding: utf-8
 
from tkinter import *
import serial
 
commandePhoto = [0x18, 0x39, 0x0d, 0x0a]
commandeVideo = [0b00011000, 0x3a, 0x0d, 0x0a]
commandeFocusNear = [0b00101000, 0x47, 0x0d, 0x0a]
commandeFocusFar = [0b00101000, 0x45, 0x0d, 0x0a]
 
ser = serial.Serial('/dev/ttyUSB0')
 
def takePhoto():
	for i in range (4):
		ser.write(commandePhoto[i])
 
def takeVideo():
	for i in range (4):
		ser.write(commandeVideo[i])
 
def focusNear():
	for i in range (4):
		ser.write(commandeFocusNear[i])
 
def focusFar():
	for i in range (4):
		ser.write(commandeFocusFar[i])
 
 
Mafenetre = Tk()
 
Mafenetre.title('Télécommande LANC')
Mafenetre.geometry('350x100+400+400')
 
 
boutonPhoto = Button(Mafenetre, text ='Photo', command = takePhoto)
boutonPhoto.pack(side = LEFT, padx = 5, pady = 5)
boutonVideo = Button(Mafenetre, text ='Video', command = takeVideo)
boutonVideo.pack(side = LEFT, padx = 5, pady = 5)
boutonFocusNear = Button(Mafenetre, text ='Focus near', command = focusNear)
boutonFocusNear.pack(side = LEFT, padx = 5, pady = 5)
boutonFocusFar = Button(Mafenetre, text ='Focus far', command = focusFar)
boutonFocusFar.pack(side = LEFT, padx = 5, pady = 5)
 
Texte = StringVar()
 
LabelResultat = Label(Mafenetre, textvariable = Texte, fg ='red', bg ='white')
LabelResultat.pack(side = LEFT, padx = 5, pady = 5)
 
Mafenetre.mainloop()
Et voici le code executé sur l'Arduino :

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
byte incomingByte = 0;
void setup() {
  // put your setup code here, to run once:
  Serial1.begin(9600);
  Serial.begin(9600);
 
}
 
void loop() {
  // put your main code here, to run repeatedly:
  if(Serial1.available() > 0) {
    incomingByte = Serial1.read();
    Serial.write(incomingByte);
    Serial.print(" ");
  }
 
 
}
Le soucis, c'est que quand je clique sur un bouton je reçois sur l'arduino des séries de points d'interrogations.
Je me doutes qu'il y ai un soucis de codage j'ai donc passé la matinée à essayer différente façon de déclarer mes variables, d'utiliser des fonctions de type encode('ascii') mais rien n'y fais, je n'arrive pas à recevoir les bons octets, ni le bon nombre d'octets.
Merci d'avance.