Note that there are some explanatory texts on larger screens.

plurals
  1. POpython serial reading issue after a period of inactivity
    primarykey
    data
    text
    <p>I have an arduino board which keeps on dumping values to a serial port (USB) continuously. This data is read in by a machine using a python script using the pySerial library. The code I have used is as follows:</p> <pre><code>import serial import time ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) while True: ser.flushInput() #Clear the serial input buffer print "Value:" print ser.readline() print ser.readline() print ser.readline() time.sleep(30) #Wait for 30 seconds </code></pre> <p>This works perfectly and gives the following output:</p> <pre><code>Value: 162 162 162 Value: 162 162 162 </code></pre> <p>But when I give a much bigger delay than 30 seconds in the loop, say 1minute or higher:</p> <pre><code>time.sleep(60) #Wait for 60 seconds </code></pre> <p>I start getting issues. The 1st set of values are getting printed. From then on, the ser.readline() always times out yielding null values!</p> <p>Output:</p> <pre><code>Value: 162 162 162 Value: Value: </code></pre> <p>Why does the serial module show this behaviour? </p> <p>Initially the machine I used to read in the serial values was a Raspberry Pi board running a Raspian linux. I thought the issue might be due to the RPi putting off the USB to some low power sleep when it encountered an idle period. But I tested the same code on my laptop, then also the same issue was there, implying that it might be some other issue. </p> <p>I wanted to build a system which <strong>needs to be on 24x7</strong> and read in serial values upon certain event occurrences, so this behaviour is not acceptable.</p> <p>Please shed some light on this issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload