-
Notifications
You must be signed in to change notification settings - Fork 0
/
Measure_thread.py
35 lines (30 loc) · 1.02 KB
/
Measure_thread.py
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
from threading import Thread
import socket
import time
class Measure_thread(Thread):
values = ()
times = ()
clock = 0
def __init__(self, controller, ip, port):
self.controller = controller
self.ip = ip
self.port = int(port)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((self.ip, self.port))
Thread.__init__(self)
self.setDaemon(True)
def change_freq(self, frequency) :
self.freq = frequency
def run(self):
while 1:
if self.controller.measurements_started == True:
message = "%f" % self.clock
self.socket.send(message.encode('ascii'))
data = self.socket.recv(128).decode('ascii')
self.times += (self.clock, )
self.values += (float(data), )
self.clock += 1/self.freq
time.sleep(1/self.freq)
else:
time.sleep(1)
self.socket.close()