I have a persisting latency between my arduino and pyserial. Consider the following code:
import serial
import time
port_usb_serie = serial.Serial(port ="COM3",baudrate =115200)
def read_port():
port_usb_serie.write(b'i')
# port_usb_serie.flush()
time.sleep(.1)
a = port_usb_serie.in_waiting
b = port_usb_serie.read(a)
b = b.decode()
b = b.split('\r\n')
return b
c = read_port()
print(c)
I I don't put at least a 100ms time sleep, the serial port does not return anything. I tried to modify the latency timer of the COM port, as indicated here (How to set the serial port latency timer for faster response in Windows) but I don't have access to it (advanced settings just show the standard FIFO menu). I wonder whether the problem could be my usb cable that connects the arduino to my computer (I do not use a certified high speed usb cable, just a standard one).
A number of Arduinos are reset when you open the serial port which in turn activates the bootloader. On those Arduinos, the bootloader waits for an upload or times out after a few seconds.
You don't mention which Arduino you're using; so the above might not be relevant. And you don't show your Arduino code.
Some ideas are in these two related topics by Robin2
I don't think your usb cable is the cause of the problem, if you can use that same cable to upload a sketch to Arduino, it will be ok.
Your python code will need to wait for the Arduino to respond. Rather than waiting for a fixed period, it would be better to detect when the complete message has been received from the Arduino. What message is being sent? Can you post an example (use serial monitor in Arduino IDE).