擅长:python、mysql、java
<p>你假设如果有数据,那就是完整的数据。如果在传输部分对串行端口的处理方式有缓冲,则只能获得部分数据。在</p>
<p>您可以尝试在python代码中添加一个<code>ser.flush()</code>,但也应该检查所接收到的数据是否完整。您可以通过确保您的数据以已知字符结束并进行检查来做到这一点。在</p>
<p>请记住,您还应该有某种类型的超时,这样您就不会陷入某个读取循环中。在</p>
<p>另一个问题是,您正在读取<code>char</code>类型,但是<code>Serial.read()</code>实际上返回了一个<code>int</code>,根据{a1}。<code>char</code>数据类型的大小为1个字节,而{<cd4>}的大小为2个字节,所以这可能就是为什么您会得到奇怪的东西(有一个引用<a href="http://playground.arduino.cc/Code/DatatypePractices" rel="nofollow">here</a>)。在</p>
<p>它还说<code>read</code>将只返回数据的第一个字节。所以,如果你想要第二个字节,你需要读两次。在</p>