The first line opens a serial port object for our use. However it presents a problem in that it will block even after there is no more # string type, which we can then properly print.ĭata = serial_port.read(bytes_to_read).decode() decode converts it from a type of " bytes" to a # This line reads the amount of data specified by bytes_to_read in. While bytes_to_read < serial_port.inWaiting(): # command it had to iterate through the loop twice before all the data arrived. # higher value than what is in bytes_to_read we know that more data is still coming in. This loop sleeps 1 second each iteration and updates bytes_to_read. # 9600 baud is not very fast so if you call serial_port.inWaiting() without sleeping at all it will likely just say # Give the line a small amount of time to receive data # Make sure there is not any lingering input - input in this case being data waiting to be received Serial_port = serial.Serial( 2, baudrate= 9600, timeout=None, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE, xonxoff=False)
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |