Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pyserial write()函数在发送之前必须发送多次_Python_Serial Port_Pyserial - Fatal编程技术网

Python pyserial write()函数在发送之前必须发送多次

Python pyserial write()函数在发送之前必须发送多次,python,serial-port,pyserial,Python,Serial Port,Pyserial,阿杜伊诺 蟒蛇 void setup() { Serial.begin(9600); } void loop() { char readChar[64]; Serial.readBytesUntil(33,readChar,64); String read_ = String(readChar); Serial.println(read_); } 结果 import serial import time sr = serial.Serial('COM5', 9600

阿杜伊诺

蟒蛇

void setup() {
  Serial.begin(9600);

}

void loop() {
  char readChar[64];
  Serial.readBytesUntil(33,readChar,64);
  String read_ = String(readChar);
  Serial.println(read_);
}
结果

import serial
import time


sr = serial.Serial('COM5', 9600)
time.sleep(2)
sr.flush()
time.sleep(2)
while True:
    wr = '574352936875!'
    print(wr)
    sr.write(wr.encode())
    time.sleep(2)
    rd = sr.readline()
    print(rd)
    time.sleep(2)
第一个1~2次write()函数是dot not work 在第三个函数之后,write函数可以正常工作。 b'9922352936875更改为b'5743529336875

我用 阿杜伊诺·乌诺 pyserial 3.4 python 3.7

在Arduino Due中没有这样的问题。为什么呢

574352936875!
b'9922352936875\xed\xbf\xef\xed\xdd\xaem~\xf5\xf6\xb7Y\xf1\x9f3#\xe9j\xd3\xf5\xf9\x8fJr\xf6z\x13\xdb\xfd\xdd]\xfa\xcc4v\xf9F\xf7\xd5\xcc\xdf\x06K?\xf8\x9c\xff\xef\xa0\xfd\xff\r\n'
574352936875!
b'9922352936875\xed\xbf\xef\xed\xdd\xaem~\xf5\xf6\xb7Y\xf1\x9f3#\xe9j\xd3\xf5\xf9\x8fJr\xf6z\x13\xdb\xfd\xdd]\xfa\xcc4v\xf9F\xf7\xd5\xcc\xdf\x06K?\xf8\x9c\xff\xef\xa0\xfd\xff\r\n'
574352936875!
b'5743529368755\xed\xbf\xef\xed\xdd\xaem~\xf5\xf6\xb7Y\xf1\x9f3#\xe9j\xd3\xf5\xf9\x8fJr\xf6z\x13\xdb\xfd\xdd]\xfa\xcc4v\xf9F\xf7\xd5\xcc\xdf\x06K?\xf8\x9c\xff\xef\xa0\xfd\xff\r\n'
574352936875!
b'5743529368755\xed\xbf\xef\xed\xdd\xaem~\xf5\xf6\xb7Y\xf1\x9f3#\xe9j\xd3\xf5\xf9\x8fJr\xf6z\x13\xdb\xfd\xdd]\xfa\xcc4v\xf9F\xf7\xd5\xcc\xdf\x06K?\xf8\x9c\xff\xef\xa0\xfd\xff\r\n'

Process finished with exit code -1