Skip to content
Discussion options

You must be logged in to vote

Presuming the error is because you fall through the loop and data has no data, maybe what you want is:

# read serial data
#   if data present, convert and check length
#       if length is expected, stop
#   keep trying
while True:
    if (data:=ser.read()):
        var_sbms = data.decode("utf-8")
        if len(var_sbms) == 61:
            break

In your original walrus form, the loop will break on the first read where ser.read() returns None/empty string- returning an empty data string. Check the file and line-numbers to see when the string reference is failing.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@davefes
Comment options

Answer selected by davefes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants