-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc7serial.py.save
executable file
·49 lines (43 loc) · 1.04 KB
/
sc7serial.py.save
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print u"Content-type: text/html; charset=utf-8\n\n"
#mycomment=тест serial port
import serial
import time
ser = serial.Serial(port='/dev/ttyUSB0',
baudrate=115200,
bytesize=8,
parity='O',
stopbits=1,
timeout=0.03,
xonxoff=0,
rtscts=0)
#print ser
#print ser.name
#ser.write(chr(x05)+chr(x02)+chr(x00)+chr(x00)+chr(x00)+chr(x08)+chr(x78)+chr(x48)) # write a string
bytearr=[0x05,0x02,0x00,0x00,0x00,0x08,0x78,0x48]
j=1
StartT=time.time()
while True:
ser.write(bytearr)
response = ser.read(size=6)
freq=j/(time.time()-StartT)
print j,"request: "," ".join(str(hex(i)) for i in bytearr),\
" --> response: "," ".join(hex(ord(i)) for i in response),\
"req/s:",round(freq,2),\
" [ms] ",round(1000/freq,2),\
"\r",
j+=1
"""
numOfLines = 0
while True:
response = ser.read()
response = ser.read(size=6)
print response
#print("read data: " + str(hex(ord(response))))
numOfLines = numOfLines + 1
if (numOfLines >= 6):
break
"""
ser.close()
#print s