Bonjour,
J'utilise Python 3.5, PyQt5, pyserial et la librairie Xbee afin de faire communiquer deux Xbee. Voici mon 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
 
#! /usr/bin/python3
from __future__ import print_function
 
 
import sys, serial, time, datetime, csv
from os import system
import RPi.GPIO as GPIO
from xbee import XBee, ZigBee
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
#import de la fenêtre
from Interface.rdint import Ui_RdInt
###############Définition des classes##################
class RadioApp(QMainWindow):
    def __init__(self,parent=None):
        super (RadioApp, self).__init__(parent)
        self.createWidgets()
        self.ser = serial.Serial(SERIALPORT, BAUDRATE)
        self.xbee = XBee(self.ser, callback=self.Reception)
        self.ui.txtRecept.setText("Test")
        #self.SERIALPORT=SERIALPORT
        #self.BAUDRATE=BAUDRATE
 
    def createWidgets(self):
        self.ui = Ui_RdInt()
        self.ui.setupUi(self)
 
    def closeEvent(self, event):
        self.xbee.halt()
        self.ser.close()
        QApplication.instance().exit(2)
 
    def Reception(self, data):
        self.ui.txtRecept.setText("20")
 
SERIALPORT = "/dev/serial0"
BAUDRATE = 9600
 
#Test application graphique
if __name__ == "__main__":
    app = QApplication(sys.argv)
    myapp = RadioApp()#"/dev/serial0",9600
    myapp.show()
    rc = app.exec_()
    sys.exit(rc)
Le Xbee distant envoie une donnée toutes les 10s. A ce moment là, la fonction callback est bien exécutée mais génère cette erreur que je ne sais pas comment résoudre :
QObject: Cannot create children for a parent that is in different thread. (Parent is QTextDocument(0xd1a970), parent's thread is QThread(0xc6d500), current thread is QThread(0x6b500e50)
Erreur de segmentation.
Savez-vous comment contourner ce problème ?
Merci.