我试图使用Python和串行通信向arduino发送日期时间,但发送数据时遇到问题。当我使用var = raw_input ("input:")
时
数据已发送。但是当我使用var = str (time.asctime (time.localtime (time.time ())))
时,数据没有发送到arduino。在
下面是我的Python代码:
import serial, time
port = serial.Serial('COM4',9600)
var = str(time.asctime(time.localtime(time.time())))
if port.isOpen():
print ('Port Aktif')
while 1:
port.write(var)
time.sleep(1)
print port.readline()
else:
print 'port Tidak Aktif'
我的代码是arduino:
^{pr2}$
见https://pyserial.readthedocs.io/en/latest/pyserial_api.html#classes
上面写着:
这意味着,使用
^{pr2}$而不是
使用:
^{pr2}$后者将返回一个字节字符串,这是写入串行端口时所必需的。在
相关问题 更多 >
编程相关推荐