![]() |
|
#1
|
|||
|
|||
Trouble with pyserial scriptI have pyserial installed on a Mac Mini (10.4.8) with a Keyspan USB-Serial adapter. Everything is installed correctly, and I can send serial commands in python interactive mode just fine.
But... When I create a script with the same commands, the script does everything else (assigning the port, etc.), but it does NOT actually send the serial string. The script that is NOT working is root:wheel, has been chmod'd up to 777, and is being run by root. Here it is: Python Code:
...but of course when I enter python interactive mode, and type the same commands, the ser.write() command sends out the serial like it's supposed to. Can anyone help me get the script to send the serial? PS: I'm a python newbie - this is the first thing I've tried with python, but I've done a lot of PHP stuff. I got pyserial installed and had it working in interactive mode in about 10 minutes, but I've spun my wheels on getting the script to work for a day now. THANKS! Last edited by LuciWiz : 21-Feb-2007 at 11:49.
Reason: Please insert your Python code between [py] & [/py] tags
|
|||
|
#2
|
||||
|
||||
Re: Trouble with pyserial scriptTry changing your first line to:
Python Code:
The "she-bang" line needs to be marked as a comment, which it currently isn't. I'm surprised you aren't getting error messages, though the OS could be smart enough to figure it out. The rest of your script looks like it should be working. What Python editor are you using? Many of them, such as SPE, let you run the code within the IDE and see if there are any errors. Additionally, you may also want to look at Google's Python newsgroup. Most of the people on this forum are Python newbies (I've only been using it for a year and I imagine I'm one of the "senior Pythonistas" here). __________________
Start Programming with Python-A beginner's guide to programming and the Python language. ------------- Common Sense v2.0-Striving to make the world a little bit smarter. |
|
#3
|
|||
|
|||
Re: Trouble with pyserial scriptQuote:
Oh, sorry, my shebang line is right in the script, I transposed the first two characters somehow when I was copying and pasting for the post. |
|
#4
|
|||
|
|||
Re: Trouble with pyserial scriptSOLVED. I needed to add a time.sleep(0.1) statement after the ser.write() to give the script enough time to do the work before closing.
|
|
#5
|
|||
|
|||
Re: Trouble with pyserial scriptDoes that point to a need to flush the output? Instead of sleep()ing, you could call flush() on it (i.e. ser.flush() )? I'm just guessing here. I've never used pyserial so I don't know it's limitations/features.
|
|
#6
|
|||
|
|||
Re: Trouble with pyserial scriptQuote:
Yes, you are correct: ser.flush() also causes the serial command to be sent. This, I'm sure, is a much more appropriate way to use pyserial than using time.sleep(). Thanks, |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Web stats | fcolor | Web Design Forum | 10 | 12-Jul-2007 08:48 |
| Need Free Website Templates | sam_dezine | Web Design Forum | 8 | 06-Sep-2006 03:25 |
| Who Is A Web Designer ? | alicehopkins | Web Design Forum | 1 | 13-Jun-2006 02:56 |
| HTML Code | amgujral | Web Design Forum | 0 | 07-Apr-2006 09:46 |
| Two virtual hosts, cgi script behaves differently on each | blimbo | Apache Web Server Forum | 0 | 04-Aug-2004 09:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The