-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileFetcher.py
executable file
·32 lines (28 loc) · 1.02 KB
/
fileFetcher.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
#!/usr/bin/env python
import threading
import sys
import time
class FileFetcher(threading.Thread):
def __init__(self, chans, fil):
threading.Thread.__init__(self)
self.chans = chans
self.stream = open(fil, 'r')
#self.stream = open("/dev/ttyUSB0", 'r') #Linux style
self.stream.readline() #read and forget to avoid data-glitches on first read.
self.setDaemon(True)
self.start()
def run (self):
while (True):
time.sleep(0.01)
for line in self.stream:
try:
data = [float(val) for val in line.split()]
except ValueError:
print("ValueError " + str(line))
continue
if len(data) > len(self.chans):
print ("Wrong length!!!: " + str(line))
continue
for chan, dat in zip(self.chans, data):
chan['data'].popleft()
chan['data'].append(dat)