19
19
import platform
20
20
import sys
21
21
import importlib
22
+ import signal
22
23
23
24
#----------------------------------------------
24
25
# Check dependencies
42
43
#Check Platform
43
44
myPlatform = ''
44
45
if platform .system () == 'Windows' :
45
- myPlatform = "Windows"
46
- for pac in packagesInstall :
47
- os .system ('start cmd /k pip install ' + str (pac ))
48
- print ("Installing " + str (pac ))
49
- importlib .import_module (pac )
46
+ myPlatform = "Windows"
50
47
elif platform .system () == 'Linux' :
51
48
myPlatform = "Linux"
52
- for pac in packagesInstall :
53
- print ("Installing " + str (pac ))
54
- os .system ('pip install ' + str (pac ))
55
- importlib .import_module (pac )
56
49
print ("My platform: " + myPlatform )
50
+
51
+ for pac in packagesInstall :
52
+ os .system ('pip install ' + str (pac ))
53
+ print ("Installing " + str (pac ))
54
+ importlib .import_module (pac )
55
+
57
56
#----------------------------------------------
58
57
59
58
"""
@@ -87,15 +86,36 @@ def __init__(self, port, baud, timeout):
87
86
self .port = port
88
87
self .baud = baud
89
88
self .timeout = timeout
89
+ while 1 :
90
+ try :
91
+ self .ser = serial .Serial (str (self .port ), self .baud , timeout = self .timeout )
92
+ self .ser .close ()
93
+ self .ser .open ()
94
+ break
95
+ except :
96
+ print ("USB is not connected" )
97
+
98
+ if handler .SIGINT :
99
+ print ("Exit" )
100
+ sys .exit ()
101
+ time .sleep (1 )
90
102
91
103
def send (self , cpu , ram ):
92
- ser = serial .Serial (self .port , self .baud , timeout = self .timeout )
93
- ser .close ()
94
- ser .open ()
95
104
print ("Cpu: " + str (cpu ) + " ram: " + str (ram ))
96
- ser .write (str (cpu )+ "|" + str (ram ))
105
+ self . ser .write (str (cpu )+ "|" + str (ram ))
97
106
time .sleep (0.1 )
98
- ser .close ()
107
+
108
+ def exit (self ):
109
+ self .ser .close ()
110
+
111
+ class SIGINT_handler ():
112
+ def __init__ (self ):
113
+ self .SIGINT = False
114
+
115
+ def signal_handler (self , signal , frame ):
116
+ self .SIGINT = True
117
+ handler = SIGINT_handler ()
118
+ signal .signal (signal .SIGINT , handler .signal_handler )
99
119
100
120
#Create PC info interface
101
121
load = PCLoad ()
@@ -104,6 +124,7 @@ def send(self, cpu, ram):
104
124
print ("Connecting to: " + str (port ))
105
125
toUSB = mySerial (str (port ),9600 ,0.5 )
106
126
127
+
107
128
#Send packages FOREVER!
108
129
while (1 ):
109
130
#Read cpu and ram load
@@ -114,4 +135,9 @@ def send(self, cpu, ram):
114
135
toUSB .send (cpu , ram )
115
136
except :
116
137
print ("USB is not connected" )
138
+
139
+ if handler .SIGINT :
140
+ toUSB .exit ()
141
+ print ("Exit" )
142
+ break
117
143
time .sleep (0.4 )
0 commit comments