Hence you should loop untill the number of written bytes is equal to the number of bytes you wanted to write: toWrite = "the command\r\n" But the write() functions returns the number of bytes successfully written to the buffer. This can happen if the output buffer is already full. There is no guarantee that all the data you are attempting to write will be written by the write() function, either with or without the for loop. The problem is that both the methods are error prone: This implies that the buffer is always empty before writing, hence the odds the write will fail are lower. The first method is less likely to fail because the output buffer is reset before attempting a write. Well, from the pySerial documentation the function flushInput has been renamed to reset_input_buffer and flushOutput to reset_output_buffer:įlush input buffer, discarding all it’s contents.Ĭhanged in version 3.0: renamed from flushInput()Ĭlear output buffer, aborting the current output and discarding all that is in the buffer.Ĭhanged in version 3.0: renamed from flushOutput() Note: Please note that self.port is serial.Serial object. I want to understand the difference between these and know if the second one prone to errors. I don't understand what flushes do there. #Python flush serial port buffer codeAnd as I said the second code fails after some time( it is unclear, if these methods are the problem). The major difference I first encounter is that the first one splitting the command in to letters then send it. I want to understand the difference because I want to use the second one, but it results in port becoming unresponsive after some time, I wonder if it causes a kind of overloading. I am using two libraries to connect with a port, and two of them uses different styles in writing these commands.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |