Bonjour,

Je demande l'aide d'une âme charitable.
Je souhaite faire un espion de trame RS232 sur Tkinter.
Je précise que je travaille sur une raspberry pi 2 avec debian Wheezy et une interface FTDI RS232/USB assure la communication.
L'interface fonctionne car j'ai bien mes trames sur jpnevulator.
Après quelques recherches, je suis tombé sur site qui correspond exactement ce que je voulais avec en plus une fonction de tri dans un buffer.

http://robotic-controls.com/learn/py...tkinter-serial

Chacune de mes trames débute par 0x02 et fini par 0x0D. Donc grâce au tri je pourrais avoir une visualisation claire des trames. Mais le soucis est que lorsque j'exécute le script, la fenêtre s'affiche mais je n'ai aucune info sur ma fenêtre.
Voici 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
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
52
53
54
55
56
#!/usr/bin/env python3
from tkinter import *
from serial import *
from tkinter import filedialog
import subprocess
import os
import time
fenetre = Tk()
def espion():
        fe=Toplevel(master=fenetre)
      # # fe.attributes('-fullscreen', 1)
        serialPort = "/dev/ttyUSB0"
        baudRate = 9600
        ser = Serial(serialPort, baudRate,bytesize=SEVENBITS, parity=PARITY_EVEN, stopbits=STOPBITS_ONE, timeout=0, writeTimeout=0, xonxoff= False)
        Frame16 = Frame(fe, borderwidth=2, relief=GROOVE)
        Frame16.pack(side=LEFT, fill=Y)
       # make a scrollbar
        scrollbar = Scrollbar(Frame16)
        scrollbar.pack(side=RIGHT, fill=Y)
       # make a text box to put the serial output
        log = Text ( Frame16, width=30, height=30, takefocus=0)
        log.pack()
       #  attach text box to scrollbar
        log.config(yscrollcommand=scrollbar.set)
        scrollbar.config(command=log.yview)
       #make our own buffer
       #useful for parsing commands
       #Serial.readline seems unreliable at times too
        serBuffer = ""
        def readSerial():
            while True:
                c = ser.read() # attempt to read a character from Serial
        #was anything read?
                if len(c) == 0:
                    break
        # get the buffer from outside of this function
                global serBuffer
        # check if character is a delimeter
                if c == '0D':
                    c = '\r' # don't want returns. chuck it
 
                if c == '02':
                    serBuffer += "\n" # add the newline to the buffer
            #add the line to the TOP of the log
                    log.insert('0.0', serBuffer)
                    serBuffer = "" # empty the buffer
                else:
                    serBuffer += c # add to the buffer
            fe.after(10, readSerial) # check serial again soon
# after initializing serial, an arduino may need a bit of time to reset
        fe.after(100, readSerial)
 
        fe.mainloop()
bouton= Button (fenetre, text='espion', command=espion, height=10, widht=11)
bouton.pack(side=BOTTOM)
fenetre.mainloop()
J'espère avoir donné assez d'infos pour vous permettre de m'aider.

Merci d'avance