Pyserial - Embedded Systems
<p>I am not expecting a code here, but rather to pick up on knowledge of the folks out there. </p>

<p>I have a python code - which uses pyserial for serial communication with an Micro Controller Unit(MCU). My MCU is 128byte RAM and has internal memory. I use ser.write command to write to the MCU and MCU responds with data - I read it using ser.read command. </p>

<p>The question here is - It is working excellently until last week. Since yesterday - I am able to do the serial communication only in the morning of the day. After a while, when I read the data the MCU responds with"NONE" message. I read the data next day, it works fine. Strange thing is - I have Hyperterminal installed and it properly communicates with the MCU and reads the data. So I was hoping if anyone have faced this problem before. </p>

<p>I am using threads in my python program - Just  to check if running the program mulitple times with threads is causing the problem. To my knowledge, threads should only effect the Memory of my PC and not the MCU. </p>

<p>I rebooted my Computer and also the MCU and I still have this problem. </p>

<p>Note: Pycharm is giving me the answers I mentioned in the question. If I do the same thing in IDLE - it is giving me completely different answers</p>

<p>So, ultimately you're looking for advice on how to debug this sort of time dependent problem.
Somehow, state is getting created somewhere in your computer, your python process, or the microcontroller that affects things.  (It's also theoretically possible that an external environmental factor is affecting things.  As an example, if your microcontroller has a realtime clock, you could actually have a time-of-day dependent bug.  That seems less likely than other possibilities).</p>

<p>First, try restarting your python program.  If that fixes things, then you know some state is created inside python or your program that causes the problem.
Update your question with this information.</p>

<p>If that doesn't fix it, try rebooting your computer.  If that fixes things, then you strongly suspect some state in your computer is affecting things.</p>

<p>If none of that works, try rebooting the micro controller.  If rebooting both the PC and the micro controller doesn't fix things, include that in your question as it is very interesting data.</p>

<p>Examples of state that can get created:</p>

<ul>
<li><p>flow control.  The micro controller could be sending xoff, clearing clear-to-send or otherwise indicating it does not want data</p></li>
<li><p>Flow control in the other direction: your PC could be sending xoff, clearing request-to-send or otherwise indicating that it doesn't want data</p></li>
<li><p>Your program gets pyserial into a confused state--either because of a  bug in your code or pyserial.</p></li>
<li><p>Serial port configuration--the serial port settings could be getting messed up.</p></li>
</ul>

<p>Hyper terminal could do various things to clear flow control state or reconfigure the serial port.</p>

<p>If restarting python doesn't fix the problem, threading is very unlikely to be your issue.  If restarting python fixes the problem threading may be an issue.</p>

python multithreading embedded pyserial