0

I am having trouble connecting to a 3G usb modem using python.

when I try, in python interpreter:

import serial
ser = serial.Serial("/dev/ttyUSB1", timeout=2)

I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 236, in __init__
     self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 286, in open
     self._update_dtr_state()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 612, in _update_dtr_state
     fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
  IOError: [Errno 32] Broken pipe

but running

cu -l /dev/ttyUSB1

is able to connect just fine. And I am able to send AT commands and get responses.

Serial object printed out is:

Serial<id=0x76add9b0, open=True>(port='/dev/ttyUSB1', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False)

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

You need to disable the flow control. You can see it failing on a ioctl TIOCM_DTR_str.

ser = serial.Serial("/dev/ttyUSB1", timeout=2, xonxoff=False, rtscts=False, dsrdtr=False)

You may need a timeout 0 too, you'll see how it goes.

0

After looking at the offending code, I tried setting dsrdtr to True will skip the code that tries to update the DTR line (that causes the broken pipe).

Basically, I just added:

ser.dsrdtr = True

and it works. I do not understand why the code will skip setting the DTR line if dsrdtr is True, though. I expected a False value will skip, not a True value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.