PySerial rereads its own data
Grant Edwards
grante at visi.com
Tue Jun 3 23:37:02 EDT 2003
In article <slrnbdqqs8.ast.grante at localhost.localdomain>, Grant Edwards wrote:
> In article <bbjl2p$a1ndg$1 at ID-169208.news.dfncis.de>, Greg Ewing (using news.cis.dfn.de) wrote:
>
>> I missed your original post, so this is just a guess, but
>> are you by any chance trying to use the same file object
>> to both read and write the serial port?
>>
>> I made that mistake once in C, and I got exactly that
>> symptom. It seems that stdio gets its buffering in a
>> knot if you try to do that.
>
> If you're using open(), then stdio has nothing to do with it.
Uh, That wasn't clear at all. I meant os.open() instead of the builtin
open().
> I've been doing Unix serial stuff for years and years, and I've always used
> the same file descriptor for input and output without any problems. I do it
> every day in both C and Python.
>
>> If that's the problem, the solution is to open the
>> serial device twice, once for reading and once for
>> writing, e.g.
>>
>> fin = open("/dev/ttyS0", "r") # read from this one
>> fout = open("/dev/ttyS0", "w") # write to this one
>
> Wait a minute. Are you talking about FILE pointers and fopen() or file
> descriptors and open()?
Once again, I forgot to switch from C-speak into Python-speak. If you're
using file objects and the builtin open, then I've no idea what sorts of bad
things can happen. For serial ports, I never use anything but os.open() and
the associated calls, though often I wrap them up in a class to hide the
particular nasty termios stuff.
--
Grant Edwards grante Yow! I'm dressing up in
at an ill-fitting IVY-LEAGUE
visi.com SUIT!! Too late...
More information about the Python-list
mailing list