Changing baud rate doesn't allow second command
roy at panix.com
Mon Apr 25 09:01:09 EDT 2011
<224f6621-2fc4-4827-8a19-3a12371f39b1 at l14g2000pre.googlegroups.com>,
rjmccorkle <robert.mccorkle at gmail.com> wrote:
> hi - I need to open a serial port in 9600 and send a command followed
> by closing it, open serial port again and send a second command at
> 115200. I have both commands working separately from the python
> command line but it won't work in the script.
I've never used this module (I assume you're talking about
http://pyserial.sourceforge.net/), but my guess is that if it works when
you type it in but not when you run it as a script, there's probably
some kind of race condition around the driver resetting the bit rate.
I would try a 1 second sleep after every call that touches the device
driver (including the serial.Serial() calls) and see if that helps.
It's a bit of a shot in the dark, but doesn't cost anything to try.
Another possibility is that the UART (I assume such things still exist?)
sends a few bits of gibberish onto the line when the bit rate changes,
and this is corrupting your data. It shouldn't, but you never know with
this stuff. If that's the case, you're probably screwed.
Just out of curiosity, what are you trying to do? Serial ports are
pretty much ancient history these days.
More information about the Python-list