Jump to content

Alright, so I have some code which converts "raw data" from my serial port to a proper format. Here is what I mean:

 

This line

b'\xdb0\xc30\xc30\xc3\x98\x98\x00\x00mm'

Gets changed into this

db 30 c3 30 c3 30 c3 98 98 00 00 6d 6d

Here is the big issue though. I need to be able to grab the last digit from that string (6d) and turn that into a variable so I can do stuff with it. I can't figure out how to do this with no matter what research I do. 

 

Any help would be appreciated. 

 

Current Code:

 

import serial
import time

port = serial.Serial("/dev/ttyS0",
                     baudrate=9600
                     
                     
)

while True: 
    raw_output = port.read(13)
    for a in raw_output:
        print(format(a, "02x"), end=" ")
    print()
     

 

Tech enthusiast and CS Student

 

 

 

 

 

Link to comment
https://linustechtips.com/topic/889577-python-help-parsing/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×