NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Python script collapsing after a while
March 10, 2011 by lcruz007 |
Hi, My python program serves as the interface between the microcontroller and the PC using the serial port. After a while, however, my program closes by itself and I receive this error:
Any ideas? Thank you. |
---|---|
March 10, 2011 by Ralphxyz |
Chances are your Python code is opening (calling) a program or file and you are looping around and calling it again and again. You need to close the program with each call or change your program to just open the program once. This is called "...". Darn I cannot remember what it is called (the AGE virus strikes again) but it is a common error. Especially when you a calling (opening) a database which probable is not your case but just opening a text file or lookup table has to be specifically closed each time. Ralph |
March 10, 2011 by lcruz007 |
Thanks, That makes sense since I'm opening a text file. I am making sure to close the file at each call though, but going to look at the code more closely and see if I find something (I'm not an expert with python! =p). See if you can see something wrong with it though!
|
March 10, 2011 by bretm |
It's the serial port that you're opening over and over again without closing it. Move the serial.Serial(...) outside of the while loop so that you only open it once. |
March 10, 2011 by lcruz007 |
Thanks, I think it solved my problem =) Thanks a lot, didn't think about that as a problem. Again not an expert with python! =P Thank you both for your help! :) |
March 10, 2011 by Ralphxyz |
So post you working code, hat will help all of us. Ralph |
March 11, 2011 by missle3944 |
I have a weird problem were I open the python program and then it suddenly closes. I tried raw_input, but it always closes right after I open it |
Please log in to post a reply.
Did you know that sound travels via pressure waves in the air, and you can make these with a piezoelectric buzzer? Learn more...
|