In the python serial port program, What should I do with 'b'?

Question:

The serial port program attempted to print the data from the Python
Let me show you the code I used.

import serial
import time

ser =serial.Serial(port="COM1",
                   baudrate=926100,
                   bytesize=serial.EIGHTBITS,
                   parity=serial.PARITY_NONE,
                   timeout=20)


ser.isOpen()                    ## open port 



print ("Sensortag's connected Succesfully!.")



while 1:

    res1 =ser.readline()

    res3=res1[13:21]          
    time.sleep(1.0)
    if res3 >=250:               
       print("Sensor has invalid value Please wait a moment.")
    elif res3 < 250 & res3>=200:
        print("The user's movements are abnormal. Please check.")
    else:
        print("The user Your movements are normal.")



print(res3)

First of all, what I want is to print numbers in a program and see if they exceed a certain range.But here’s the problem.

Traceback (most recent call last):
      File "C:UsersSEOIAppDataLocalProgramsPythonPython37-32ㅋㅋㅋㅋ.py",     line 37, in <module>
        if res3 >=250:               ## 3).When UART outputs a value, it outputs     the required parts
TypeError: '>=' not supported between instances of 'bytes' and 'int'

In the following questions, you have identified an error because the value i can receive in the program is not numeric
However, it is not possible to know how 'b' should remove the part from the part that is output from the file

We used sliding to solve the following problem, but 'b' as shown in the picture has been output.
I’ll attach the picture to the printout section of B mentioned above.

enter image description here

++)I just checked, and I can’t see the image of B in the right direction, so I’ll leave it in writing.

b’0253.787′
b’0261.909′
b’0268.000′
b’0263.939′
b’0261.909′
b’0259.878′
b’0257.848′
b’0255.818′
b’0253.787′
b’0290.333′
b’0282.212′
b’0276.121′
b’0270.030′
b’0265.969′
b’0263.939′
b’0261.909′
b’0259.878′
b’0261.909′
b’0263.939′
b’0261.909′
b’0259.878′
b’0257.848′
b’0255.818′
b’0253.787′
b’0300.484′
b’0485.242′
b’0633.454′

Asked By: 임종훈

||

Answers:

b'... '

Is python’s way of representing a string of bytes. The error is telling you that you can’t use >= to compare bytes and an integer.

You need to convert your byte strings to integers before that line. There is an easy way of doing this, as pointed out by DeepSpace

integer = float(res3)
Answered By: strava
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.