-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerial-demo.py
More file actions
36 lines (35 loc) · 1.27 KB
/
Serial-demo.py
File metadata and controls
36 lines (35 loc) · 1.27 KB
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
import serial
from bitarray import bitarray
import struct
from SSL_Lib.Robot import *
#打开串口
serialPort="COM5" #串口
baudRate=115200 #波特率
ser=serial.Serial(serialPort,baudRate,timeout=0.5)
print(ser.isOpen())
print ("参数设置:串口=%s ,波特率=%d"%(serialPort,baudRate))
start_package = b'\xff\xb0\x01\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x31'
config_package= b'\xff\xb0\x04\x05\x06\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x85'#频点为0
package_1= b'\xff\x00\x01\x01\x26\x41\x90\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00'
package_2= b'\xff\x00\x01\x01\x06\x40\x00\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00'
#收发数据
address = ('127.0.0.1', 20011)
#y2 = Robot("blue",3,0.15,address)
#a=y2.setSpeed(-0.5,0.6,0)
#pac_test=a
while True:
a=ser.write(start_package)
a=ser.readline()
if a is not b'':
print(a)
#a might be b'\xff\xb0"\xcfV\xd6\x10qE\x98\x00!\x82V\xa9\x11\x00\x00\x00\x00\x00\x00\x00\x00n'
break
a=ser.write(config_package)
import time
#time.sleep(5)
while True:
a=ser.write(package_2)
a=ser.readline()
if a is not b'':
print(a)
break