-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
30 lines (28 loc) · 877 Bytes
/
test.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
import thread
import time
time.sleep(5)
class _CDC :
def __init__(self):
self.dev = "/dev/tty.usbmodem3671271"
self.query = ""
def read(self,_passarg):
with open("/dev/tty.usbmodem3671271", "r") as readBuff:
while True :
ans = readBuff.readline()
if ans:
print ans[:-2]
time.sleep(0.001)
def write(self,_passarg) :
with open("/dev/tty.usbmodem3671271","a") as writeBuff:
while True :
if self.query != "":
writeBuff.write(self.query+"\n")
self.query = ""
time.sleep(0.001)
CDC = _CDC()
thread.start_new_thread(CDC.read,(None,))
thread.start_new_thread(CDC.write,(None,))
while True:
q = "SEND-TEST%02d"%2
CDC.query = q+((64-len(q))*"\x00")
time.sleep(0.1)