擅长:python、mysql、java
<p>这些解决方案将占用CPU,同时等待字符。</p>
<p>您应该至少执行一个阻塞调用来读取(1)</p>
<pre><code>while True:
if '\n' in buffer:
pass # skip if a line already in buffer
else:
buffer += ser.read(1) # this will block until one more char or timeout
buffer += ser.read(ser.inWaiting()) # get remaining buffered chars
</code></pre>
<p>…和以前一样做分裂的事情。</p>