Debugging Python serial I/O errors

Stephen shriek at gmx.co.uk
Fri Dec 21 09:43:08 CET 2001


Having a hell of a time trying to read serial I/O on my
redhat 7.2 machine, with a variety of methods ~


========================================
First attempt ~ using the USPP module ~
========================================
>>> from uspp import *
>>> s = SerialPort("/dev/ttyS1", 1000, 9600)
>>> s.write("AT")
>>> s.read()
Exception exceptions.AttributeError: '_SerialPort__handle' in <method
SerialPort.__del__ of SerialPort instance at 80da628> ignored
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "SerialPort_linux.py", line 217, in read
    s=s+SerialPort.__read1(self)
  File "SerialPort_linux.py", line 204, in __read1
    raise SerialPortException('Timeout')
SerialPort_linux.SerialPortException: Timeout

It seems to be recognizing the port OK, otherwise it would
have thrown up one of these errors 

   termios.error: (5, 'Input/output error')
or
    SerialPort_linux.SerialPortException: Unable to open port


 * btw, if USPP is 'universal', shouldn't it be
   called with the same parameters on all platforms ?
   I tried SerialPort("COM2", 1000, 9600) 
   and it really didn't like that, preferring "/tty/devS1")


========================================
Second attempt ~ write straight to the file
=======================================

>>> f = open("/dev/ttyS1", "rw")
>>> f.write("AT")
Traceback (innermost last):
  File "<stdin>", line 1, in ?
IOError: [Errno 9] Bad file descriptor


That's very strange because f is a file descriptor as shown by ~

>>> f 
<open file '/dev/ttyS1', mode 'rw' at 80dc158>I was surprised that it 


========================================
Third attempt ~ using PosixSerial.py
=======================================

>>> import PosixSerial
>>> p = PosixSerial.Port()
>>> p.open("/dev/ttyS1")
>>> p.write("AT")
>>> p.read()

and then it just hangs. 


All of this points to my device being the problem but it's
just a modem and the above AT works fine when I use Python
on windows with the SerialIO module. 

Note that all of the above errors would also apply if I used
/dev/ttyS0 and COM1 instead of /dev/ttyS1 and COM2.

Is there any way I can check the exact status of my COM port
and what python is sending, or get more of an idea how to debug
this ? 

Thanking you all.

Stephen



More information about the Python-list mailing list