At first I'm using PYthon 2.7.5, pySerial in last version for Python 2.7.x, Windows 7 (64) and FTDIFT232RL (so not real RS232 Serial port). Just for the tests I created this code:
class cProduction:
g_comPort_name = "COM1"
g_comPort = 0
# Instance of object -------------------------------------------------------
def __init__(self, portName):
self.data = []
self.g_comPort_name = portName
# Main functions -----------------------------------------------------------
def start(self):
""" Open port, configure port, set pins of serial line to default state
DTR true, RTS false """
try:
self.g_comPort = serial.Serial(
port = self.g_comPort_name,
baudrate = 9600,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 10,
dsrdtr = False,
xonxoff = False,
rtscts = False)
if self.g_comPort.isOpen():
return True
else:
return False
except:
return False
return False
Main:
prod = cProduction("COM33")
if prod.start():
print Style.BRIGHT + Fore.YELLOW + "Open" + Style.RESET_ALL
while True:
key = raw_input('key: ')
if key == "R":
prod.g_comPort.setRTS(True)
if key == "r":
prod.g_comPort.setRTS(False)
if key == "D":
prod.g_comPort.setDTR(True)
if key == "d":
prod.g_comPort.setDTR(False)
else:
print Style.BRIGHT + Fore.RED + "Error while starting production module" + Style.RESET_ALL
RTS is working well but I have a problem with DTR. When I set DTR to False I can see on osciloscope that DTR was really set to low level, but after ~700ms it is return back to high level (without any interrupt from my side). In this time setDTR(False) is not working anymore. I have to first call setDTR(True) and after it setDTR(False) is working again (but again after 700ms it goes back to high level). The time 700ms is allwas the same. I tried to change configuration of 'dsrdtr' or 'rtscts' but it was not helpful.
I have Qt application based on C++ which is working with my device correctly and now I'm just trying to rewrite it to Python so I'm on 100% sure that my device is correct.
Edit: I tried it with real RS232 COM port on my laptop and it is working corectly. So it seems that pySerial has a problem with Virtual COM port with FTDI chip...