我正在尝试用串行通信的python脚本与arduino通信。当我声明全局创建串行对象时,串行通信工作正常,如下所示:
ser = serial.Serial('COM4', 115200, timeout=0) #object to interface with serial, comnumber, baud rate, timeout
def configureArduino():
try:
#there are a few lines here to calculate TsMicro I have ommitted for ease of reading
ser.write(TsMicro.encode('ascii'))
ser.write('\n'.encode('ascii'))
但当我在我的函数中这样做的时候:
def configureArduino():
ser = serial.Serial('COM4', 115200, timeout=0) #object to interface with serial, comnumber, baud rate, timeout
try:
#there are a few lines here to calculate TsMicro I have ommitted for ease of reading
ser.write(TsMicro.encode('ascii'))
ser.write('\n'.encode('ascii'))
有人知道是什么导致了这个问题吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐