import serial
ser = serial.Serial('/dev/ttyS0',38400)
s = [0x55,0xaa,0xdc,0x13,0x22,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,0x00]
d1 = 43690
d2 = 43690
h1 = d1&(0xff00)
h1=h1>>8
h2 = d1&(0x00ff)
h3 = d2&(0xff00)
h3=h3>>8
h4 = d2&(0x00ff)
s[17]=h1
s[18]=h2
s[19]=h3
s[20]=h4
n = len(s)
print(n)
temp=s[3]
for i in range(4,22):
print(i)
temp = temp^s[i]
print(hex(temp))
s[n-1]=temp
ser.write(s)
python 串口通信---留作记录
最新推荐文章于 2025-06-26 09:28:12 发布