By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,399 Members | 886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,399 IT Pros & Developers. It's quick & easy.

pySerial getting writeTimeout when sending an sms

P: 47

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

Expand|Select|Wrap|Line Numbers
  1. ser = serial.Serial('COM10',
  2.                         baudrate=115200,
  3.                         timeout=2,
  4.                         writeTimeout = 2,
  5.                         bytesize=serial.EIGHTBITS,
  6.                         parity=serial.PARITY_NONE,
  7.                         stopbits=serial.STOPBITS_ONE)
  8. ser.flushOutput()
  9. ser.flushInput()
  11. print "PDU LENGTH", pdu.length # the length of the pdu
  12. ser.write('AT+CMGS=%d\r' % pdu.length)
  13. print ser.readlines()
  14. time.sleep(1)
  15. # write the PDU and send a Ctrl+z escape
  16. print "PDU", pdu.pdu # the pdu string
  17. ser.write('%s\x1a' % pdu.pdu) # this i about where my app stops and throws a writeTimeout
  18. print "sent pdu"
  19. time.sleep(1)
  20. print ser.readlines()
the error i get is:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Users\Andreas\Documents\My Dropbox\Programmering\Projects\SMSTerminal\src\", line 52, in <module>
  3.     send_text('41603627', 'r'*200)
  4.   File "C:\Users\Andreas\Documents\My Dropbox\Programmering\Projects\SMSTerminal\src\", line 36, in send_text
  5.     ser.write('%s\x1a\r' % pdu.pdu)
  6.   File "c:\Python26\lib\site-packages\serial\", line 260, in write
  7.     raise writeTimeoutError
  8. 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.

Oct 6 '10 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 622
Expand|Select|Wrap|Line Numbers
  1. ser = serial.Serial('COM10',
Do you have 10 serial ports? Also, pyserial uses either
ser = serial.Serial(0) # open first serial port
ser = serial.Serial('/dev/ttyS0')
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()
Oct 6 '10 #2

P: 47
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 :)
Oct 7 '10 #3

Expert 100+
P: 622
I would add a print statement for the length and type, and send the CTRL-Z separately to isolate everything.
Expand|Select|Wrap|Line Numbers
  1. print "PDU", pdu.pdu # the pdu string
  2. print len(pdu.pdu), type(pdu.pdu)
  3. ser.write('%s' % pdu.pdu) # this i about where my 
  4. print "pdu.pdu sent"
  5. ser.write('\x1a') 
Oct 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.