-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
34 lines (31 loc) · 1.04 KB
/
run.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 thread
import time
time.sleep(20)
#Don't fight with the Kernel, wait some seconds for prepare device
class _CDC :
def __init__(self):
self.dev = "/dev/ttyACM0"
self.query = ""
def read(self,_passarg):
with open("/dev/ttyACM0","r") as readBuff:
while True :
ans = readBuff.readline()
if ans:
print(ans[:-2])#Ignore "\r\n" parts !
#time sleep for save cpu clocks
time.sleep(0.001)
def write(self,_passarg):
with open("/dev/ttyACM0","a") as writeBuff:
while True :
if self.query != "" :
writeBuff.write(self.query+"\n")
self.query = ""
#time sleep for save cpu clocks
time.sleep(0.001)
CDC = _CDC()
thread.start_new_thread(CDC.read,(None,))
thread.start_new_thread(CDC.write,(None,))
for i in range(30):
q = "SEND-TEST%02d"%i
CDC.query = q+((64-len(q))*"\x00")
time.sleep(0.1)