This repository was archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojet.py
More file actions
127 lines (94 loc) · 2.95 KB
/
projet.py
File metadata and controls
127 lines (94 loc) · 2.95 KB
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
# importing libraries
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
server_host = str(sys.argv[1])
server_port = int(sys.argv[2])
DEFAULT_STYLE = """
QProgressBar{
border: 2px solid grey;
border-radius: 5px;
text-align: center;
height: 10px;
width: 10px;
}
QProgressBar::chunk {
background-color: lightblue;
}
"""
COMPLETED_STYLE = """
QProgressBar{
border: 2px solid grey;
border-radius: 5px;
text-align: center;
height: 10px;
width: 10px;
}
QProgressBar::chunk {
background-color: red;
}
"""
class Monitoring(QWidget):
def __init__(self):
super().__init__()
self.InitGUI()
def InitGUI(self):
self.setWindowTitle("ModBusTCP Client")
self.resize(640,100)
self.bt1 = QPushButton("1 to Coil Outputs 0",self)
self.bt1.clicked.connect(self.abt1)
self.bt1.move(0,50)
self.bt2 = QPushButton("0 to Coil Outputs 0",self)
self.bt2.clicked.connect(self.abt2)
self.bt2.move(0,50)
self.bt3 = QPushButton("toggle Coil Outputs 0",self)
self.bt3.clicked.connect(self.abt3)
self.bt3.move(0,50)
self.Psatus = QProgressBar(self,maximum=32767,textVisible=False)
self.Plabel = QLabel('Valeur HR 40001',self)
self.Lstatus = QProgressBar(self,maximum=1,textVisible=False)
self.Llabel = QLabel ('LIGHT',self)
self.Lstatus.setStyleSheet(DEFAULT_STYLE)
self.infolayout = QGridLayout(self)
self.infolayout.addWidget(self.Plabel,0,0)
self.infolayout.addWidget(self.Psatus,0,1)
self.infolayout.addWidget(self.Lstatus,1,1)
self.infolayout.addWidget(self.Llabel,1,0)
self.infolayout.setHorizontalSpacing(40)
self.infolayout.addWidget(self.bt1,0,3)
self.infolayout.addWidget(self.bt2,1,3)
self.infolayout.addWidget(self.bt3,2,3)
self.show()
def setPval(self,val):
self.Psatus.setValue(val)
def setLval(self,val):
if val == 10000:
self.Lstatus.setValue(1)
self.Lstatus.setStyleSheet(COMPLETED_STYLE)
else:
self.Lstatus.setValue(0)
def abt1(self):
client.write_coil(0, 1, unit = 1)
def abt2(self):
client.write_coil(0, 0, unit = 1)
def abt3(self):
regs2 = client.read_coils(0,1,unit=1)
if regs2.bits[0]:
client.write_coil(0, 0, unit = 1)
else:
client.write_coil(0, 1, unit = 1)
def affiche():
regs = client.read_holding_registers(0,5,unit=1)
IHM.setPval(int(regs.registers[0]))
IHM.setLval(int(regs.registers[0]))
if __name__ == '__main__':
client = ModbusClient(host=server_host, port=server_port)
client.connect()
app = QApplication(sys.argv)
IHM=Monitoring()
timer=QTimer()
timer.timeout.connect(affiche)
timer.start(100)
app.exec()