-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArduinoThread.py
34 lines (33 loc) · 992 Bytes
/
ArduinoThread.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
import serial
from time import sleep
from threading import Thread
from re import findall
class AThread:
def __init__(self,com,bound):
self.com = com
self.bound = bound
self.ser = serial.Serial(com, baudrate=bound, timeout=0)
self.src = [0, 0]
self._stop = False
def stop(self):
self._stop = True
def start(self):
Thread(target = self.update,args=()).start()
return self
def update(self):
try:
if self._stop == True:
return
while True:
self.inp = self.ser.readline()
self.inp = str(self.inp)
self.inp = findall('[0-9]+', self.inp)
self.src = self.inp
sleep(1./120)
except serial.SerialException as e:
print("Serial portu kapanırken hata oluştu", e)
return
def read(self):
return self.inp
def feedbacksrc(self):
return self.src