import serial
import time
def write_with_delay(command):
while len(command)>0: # Loop till all of string has been sent
char_to_tx = command[0] # Get a
dongle.write(char_to_tx)
command = command[1:] # Remove sent character
time.sleep(0.01)
dongle = serial.Serial("/dev/ttyUSB0", 9600)
write_with_delay('Some data\n')
我怀疑你需要在串行写入中添加字符间延迟。不幸的是,这样的东西在PySerial中是不可用的。有一个
inter_byte_timeout
,但那是用于读取的。你知道吗比如:
它将发送字符串,每个字符之间有10毫秒(0.01秒)的延迟。通常,在代码中添加任意延迟是一件坏事,但对于串行通信来说,这有时是必要的。你知道吗
相关问题 更多 >
编程相关推荐