Reputation: 15862
I am just wondering how the buffers work on a com port.. The code below is a snip of how I am reading a com port. I am wondering if by doing serial_connection.close()
and serial_connection.open()
I would be losing any data, or would it remain in the buffer? You might ask why I am closing and opening the comport.. The reason being is that it is actually a virtual port and for what ever reason when I stay connected to it for a length of time data stops transmitting...
import serial
serial_connection = serial.Serial(
port = self.SERIAL_PORT,
baudrate = self.BAUD_RATE,
timeout = 10
)
while true:
serial_connection.close()
serial_connection.open()
line = serial_connection.readline()
print line
Upvotes: 2
Views: 5024
Reputation: 86718
PySerial has a separate thread that sits there listening for data to make sure that nothing gets lost. However, the OS itself does not buffer data. There is a slim chance that you could lose some data for the brief period of time between when you close the port and open it again.
Upvotes: 4