I can't see why it should be influenced by the size of the write buffer. Surely the number of characters allowable before generating the write_timeout exception should be related only to the baud rate and to the value specified in the write_timeout. However, all of this seems rather academic. I haven't experimented with different baud rates but I have no doubt you are right that the maximum number of characters allowable before generating a write_timeout exception will be related to baud rate. With write_timeout=0.001, I found that I could output 264 characters before generating a write_timeout exception. I can only guess that the difference between my results and yours has something to do with the size of our write buffers. Increasing to 273 characters generated a write_timeout exception. I played around with your program on my Pi3B+ and found that I could output a maximum of 272 characters at 9600 baud with write_timeout=0.01. Many thanks for your suggestions and for your code. So either I've completely misunderstood the write_timeout functionality, or it just doesn't seem to be doing anything. That is, only the first ten characters were read, the remainder were ignored. What's interesting is that when I changed the read timeout to 10ms (i.e., timeout=0.01), the program behaved exactly as you would expect: What on earth is going on? I tried several different values for write_timeout but it made no difference - the entire string was always transmitted. To my surprise, the protocol analyser displayed the entire string and the program returned: (Incidentally, the third line is there simply to confirm that the write_timeout has been set and recognised correctly). I tested the program in 'loopback' mode (TX connected to RX) with a logic/protocol analyser connected to TX. Now, at 9600 baud, the character time is roughly 1ms, so my idea was that by setting write_timeout to 10ms, only the first ten characters of the "Hello World! Hello World!" string would be transmitted. Ser = serial.Serial(port='/dev/ttyS0', baudrate=9600, timeout=1, write_timeout=0.01)
![does pyserial have an output buffer of 64 bytes does pyserial have an output buffer of 64 bytes](https://s3.manualzz.com/store/data/025597926_1-a4a994aa0864a62a799354a1d6cacd40-360x466.png)
(I can't actually think of any reason why you would wish to do this, but I'm sure there must be a use for it somewhere).Įager to test the write_timeout function, I wrote the following simple program: In other words, I took it to mean that write_timeout allowed us to specify a 'time window' during which bytes would be transmitted and at the end of the window transmission would cease. I interpreted this to imply that, following a write command, characters would be transmitted only for the time duration specified by write_timeout, and that any subsequent characters waiting in the output buffer would be omitted. Read or write current write timeout setting. Getter: Get current write timeout setting The PySerial 3.4 documentation defines "write_timeout" thus: I'm slowly working my way through it, having lots of fun, but when I get to "write_timeout" I find it doesn't seem to do anything. I'm using a Pi3B+ to test the commands and functionality of PySerial.