Bonjour,

J'ai créé une interface avec des boutons et des comboBox et je veux modifier la valeur de DATA [1] qui se trouve dans le fichier send.py à chaque fois que j'appuie sur un bouton, il lui attribue la nouvelle valeur de DAT1.

J'ai défini les fonctions de BTN1, BTN2, BTN3 pour les boutons poussoirs

Je veux avoir une idée comment coder pour avoir le résultat souhaité
Nom : Capture.PNG
Affichages : 85
Taille : 195,3 Ko

Voici le code de mes 2 fichier Python:

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
from PCANBasic import *
from exemple import *
 
 
DAT1=0b11111111
 
 
#Initialize the PCAN
 
m_PCAN = PCANBasic()
 
m_Result = m_PCAN.Initialize(PCAN_USBBUS1, PCAN_BAUD_500K)
 
 
#SEND DATA of ARD1
 
#####################################ARD1#####################
ARD1 = TPCANMsg()
 
ARD1.ID = 0x461
ARD1.LEN =8
ARD1.DATA[0] = 0x07
ARD1.DATA[1] = DAT1
 
 
print(ARD1.DATA[1])
 
 
ARD1.MSGTYPE = PCAN_MESSAGE_STANDARD
 
m_Result = m_PCAN.Write(PCAN_USBBUS1,ARD1)
 
if m_Result == PCAN_ERROR_OK :
        print("ARD1 Send")
else:
    print("ARD1 Not Send")
 
m_PCAN.Uninitialize(PCAN_USBBUS1)
Le code de mon fichier Python Qt :
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from PyQt5 import QtCore, QtGui, QtWidgets
from send import *
 
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(975, 603)
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(130, 110, 91, 21))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(Form)
        self.pushButton_2.setGeometry(QtCore.QRect(130, 170, 93, 21))
        self.pushButton_2.setObjectName("pushButton_2")
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setGeometry(QtCore.QRect(30, 110, 73, 22))
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox_2 = QtWidgets.QComboBox(Form)
        self.comboBox_2.setGeometry(QtCore.QRect(30, 170, 73, 22))
        self.comboBox_2.setObjectName("comboBox_2")
        self.comboBox_2.addItem("")
        self.comboBox_2.addItem("")
        self.pushButton_3 = QtWidgets.QPushButton(Form)
        self.pushButton_3.setGeometry(QtCore.QRect(130, 230, 93, 21))
        self.pushButton_3.setObjectName("pushButton_3")
        self.comboBox_3 = QtWidgets.QComboBox(Form)
        self.comboBox_3.setGeometry(QtCore.QRect(30, 230, 73, 22))
        self.comboBox_3.setObjectName("comboBox_3")
        self.comboBox_3.addItem("")
        self.comboBox_3.addItem("")
 
        self.pushButton.clicked.connect(self.BTN1)
        self.pushButton_2.clicked.connect(self.BTN2)
        self.pushButton_3.clicked.connect(self.BTN3)
 
 
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
 
 
 
    def BTN1(self,DAT1):
 
        x=int(self.comboBox.currentText())
 
        if x == 1:
 
            a= 0b00000111 or DAT1
            DAT1 = a
 
            print("Communication BTN1 Detected")
            return DAT1
        elif x == 0:
 
            b= 0b11111000 and DAT1
            DAT1 = b
 
            print("Communication BTN1 NOT Detected")
 
            return DAT1
 
    def BTN2(self,DAT1):
 
        x=int(self.comboBox_2.currentText())
 
        if x == 1:
 
            a= 0b00111000 or DAT1
            DAT1 = a
 
 
 
            print("Communication BTN2 Detected")
            return DAT1
        elif x == 0:
 
 
            b= 0b11000111 and DAT1
            DAT1 = b
 
            print("Communication BTN2 NOT Detected")
 
            return DAT1
 
    def BTN3(self,DAT1):
        x=int(self.comboBox_3.currentText())
 
        if x == 1:
 
            a= 0b11000000 or DAT1
            DAT1 = a
 
            print("Communication BTN3 Detected")
            return DAT1
        elif x == 0:
 
 
            b= 0b00111111 and DATA1
            DATA1 = b
 
            print("Communication BTN3 NOT Detected")
 
            return DAT1
 
 
    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "BTN1"))
        self.pushButton_2.setText(_translate("Form", "BTN2"))
        self.comboBox.setItemText(0, _translate("Form", "1"))
        self.comboBox.setItemText(1, _translate("Form", "0"))
        self.comboBox_2.setItemText(0, _translate("Form", "1"))
        self.comboBox_2.setItemText(1, _translate("Form", "0"))
        self.pushButton_3.setText(_translate("Form", "BTN3"))
        self.comboBox_3.setItemText(0, _translate("Form", "1"))
        self.comboBox_3.setItemText(1, _translate("Form", "0"))
 
 
 
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())