Python 3 non-blocking read with pySerial (Cannot get pySerial's “in_waiting” property to work)

前端 未结 1 1017
予麋鹿
予麋鹿 2021-01-06 20:53

For the life of me, I cannot figure out how to do a non-blocking serial read in Python 3 using my Raspberry Pi.

Here\'s my code:

import serial #for          


        
相关标签:
1条回答
  • 2021-01-06 21:34

    The documentation link you listed shows in_waiting as a property added in PySerial 3.0. Most likely you're using PySerial < 3.0 so you'll have to call the inWaiting() function.

    You can check the version of PySerial as follows:

    import serial
    print serial.VERSION
    

    If you installed PySerial using pip, you should be able to perform an upgrade (admin privileges may be required):

    pip install --upgrade pyserial
    

    Otherwise, change your code to use the proper interface from PySerial < 3.0:

    while (True):
        if (ser.inWaiting() > 0):
            ser.read(ser.inWaiting())
    
    0 讨论(0)
提交回复
热议问题