Reputation: 11
I have a Silicon Labs CP2102 USB to UART Bridge device. I am writing some python to script writing/reading data to a serial device with pyserial on Windows 10.
It works fine without flow control. However, it fails to read and times out if I enable either DSR/DTR or RTS/CTS.
import serial
ser = serial.Serial()
ser.baudrate = 230400
ser.port = "COM13"
ser.dtr = 1
ser.dsrdtr = True
ser.write_timeout = 1
ser.timeout = 1
ser.open()
n = ser.write(bytes([1]))
n += ser.write(bytes([2]))
n += ser.write(bytes([3]))
print("bytes written ", n)
byte_read = []
byte_read += ser.read(1)
byte_read += ser.read(1)
byte_read += ser.read(1)
print(byte_read)
ser.close()
The same device works fine with TS232 terminal tools, like Termite or TeraTerm, on Windows 10.
It seems like an issue with pyserial.
Upvotes: 1
Views: 775
Reputation: 5
The pyserial documentation appears to allude that hardware flow control is not supported with Windows.
set_output_flow_control(enable)
Platform: Posix (HW and SW flow control)
Platform: Windows (SW flow control only)
However, Amulek1416 appears to have come up with a solution that might work if you want to manually toggle the flow control:
import time
import serial
#Since we are doing the RTS and CTS logic ourselves, keep rtscts=False
mySerial = serial.Serial(port='COMX', baudrate=9600, rtscts=False)
# To send some information:
dataToSend = 'HelloWorld!'
mySerial.setRTS(True)
# Wait for CTS signal
while not mySerial.getCTS():
pass
mySerial.write(bytes(dataToSend, 'ascii'))
time.sleep(0.25) # Wait for the data to have sent before disabling RTS
mySerial.setRTS(False)
Upvotes: 0