pySerial getting writeTimeout when sending an sms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andelys
    New Member
    • Aug 2007
    • 47

    pySerial getting writeTimeout when sending an sms

    Hi,

    I'm getting a writeTimeout on a serial connection using pyserial here is my code.

    Code:
    ser = serial.Serial('COM10',
                            baudrate=115200,
                            timeout=2,
                            writeTimeout = 2,
                            bytesize=serial.EIGHTBITS,
                            parity=serial.PARITY_NONE,
                            stopbits=serial.STOPBITS_ONE)
    ser.flushOutput()
    ser.flushInput()
    
    print "PDU LENGTH", pdu.length # the length of the pdu
    ser.write('AT+CMGS=%d\r' % pdu.length)
    print ser.readlines()
    time.sleep(1)
    # write the PDU and send a Ctrl+z escape
    print "PDU", pdu.pdu # the pdu string
    ser.write('%s\x1a' % pdu.pdu) # this i about where my app stops and throws a writeTimeout
    print "sent pdu"
    time.sleep(1)
    print ser.readlines()
    the error i get is:
    Code:
    Traceback (most recent call last):
      File "C:\Users\Andreas\Documents\My Dropbox\Programmering\Projects\SMSTerminal\src\SMSSender.py", line 52, in <module>
        send_text('41603627', 'r'*200)
      File "C:\Users\Andreas\Documents\My Dropbox\Programmering\Projects\SMSTerminal\src\SMSSender.py", line 36, in send_text
        ser.write('%s\x1a\r' % pdu.pdu)
      File "c:\Python26\lib\site-packages\serial\serialwin32.py", line 260, in write
        raise writeTimeoutError
    serial.serialutil.SerialTimeoutException: Write timeout
    I have tried to extent both the write and the read timeout without any luck

    Have anybody experienced the same problem?

    i have tried the same commands in hyperterminal and it works.



    Andreas
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Code:
    ser = serial.Serial('COM10',
    Do you have 10 serial ports? Also, pyserial uses either
    ser = serial.Serial(0 ) # open first serial port
    or
    ser = serial.Serial('/dev/ttyS0')
    AFAIK
    In addition you should check for a connect with either of these statements
    print ser.portstr # check which port was really used
    print ser.isOpen()

    Comment

    • Andelys
      New Member
      • Aug 2007
      • 47

      #3
      thank you for answering, and yes. When i connect my cellphone to my usb it get 2 serial port and i have connect a couple of them by now and it just count up every time, not the problem.

      The port is open, because i am able to send the first command, but when i try to send the pdu which is about 200 chars long it throws a write error. I tried the exact same in Hyperterminal and it works in hyper terminal.

      Anyway thanks for your quick reply :)

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #4
        I would add a print statement for the length and type, and send the CTRL-Z separately to isolate everything.
        Code:
        print "PDU", pdu.pdu # the pdu string
        print len(pdu.pdu), type(pdu.pdu)
        ser.write('%s' % pdu.pdu) # this i about where my 
        print "pdu.pdu sent"
        ser.write('\x1a')

        Comment

        Working...