I'm having similar issues, but haven't been able to find a solution for a while. Looks like this is possible on Windows with some hackery, but the issue lies deeper on posix.
Ideally you should be able to setDTR before you open the connection. Like this:
import sys,serial
ser = serial.Serial()
ser.baudrate=57600
ser.port = sys.argv[1]
ser.dsrdtr = True
ser.setDTR(level=False)
ser.open();
print ser.readline()
But that throws a portNotOpenError in serialposix.py:
def setDTR(self,on=1):
"""set terminal status line"""
if not self.fd: raise portNotOpenError
if on:
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
else:
fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_DTR_str)
I took a dive into serialposix.py, and you'll see where the root issue lies. That self.fd defined above is actually:
self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
If you write a little script that opens your device using os.open(device, flags)
, you'll see it resets, even if you open it as read only with the flag os.O_RDONLY
.
Digging deeper into the meaning of the os.open
flags- we find that the open command actually wraps the unix command open(2). The man pages are here.
Let me know if you ever find a more satisfactory solution.