“你好,在尝试了几个小时不同的事情后,我有点迷失了。我已经包含了我的代码。我想向 arduino 获取一个 5 位数字,但在尝试发送数字范围时出现错误。我不是一个经验丰富的程序员,但我已经放弃了很多使用 arduino 的经验。我可以毫无问题地从 Arduino 接收。
一段测试代码:
import serial
import time
import struct
ser = serial.Serial(
port='COM15',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=0)
time.sleep(3)
print("connected to: " + ser.portstr)
#this will store the line
bline = []
while True:
ser.write(10128)
time.sleep(1)
ser.write(10000)
time.sleep(1)
ser.close()
错误:
connected to: COM15
Traceback (most recent call last):
File "C:/Users/Danny/Documents/arachnoid-0.5/testreceive.py", line 19, in <module>
ser.write(10128)
File "C:\Python33\lib\site-packages\serial\serialwin32.py", line 283, in write
data = to_bytes(data)
File "C:\Python33\lib\site-packages\serial\serialutil.py", line 75, in to_bytes
for item in seq:
TypeError: 'int' object is not iterable
>>>