0

UART Data Protocol Specification

Hi there, I have a question on how to professionally implement pyserial to integrate US-D1 UAV Radar sensor - datasheet is provided. We can say that I'm already able to create a port for this sensor. How would I get the data

How would I implement the code best to show the altitude??

here is how my code currently looks like:

import serial
import time

ser = serial.Serial("/dev/ttyS0",baudrate = 115200, timeout=1) #open a port with 115200 baudrate

if ser.isOpen():
    # ser = serial.read(6) #read 6 bytes 
    packetHead = serial.read()
    versionID = serial.read()
    lsbAltitude = serial.read()
    msbAltitude = serial.read()
    snr = serial.read()
    checksum = serial.read()
    
    if packetHead == OxFE:
        check = (versionID + msbAltitude + lsbAltitude + snr) & 0xFF
        if check == 1:
            #bitwise operation
            res = (msb<<8) | lsb #bin

        else:
            res = "checksum not passed"

        print(res)
    
  • 1
    What is your program going to do when `packetHead != OxFE`? There is no guarantee that reads by your program will be synchronized/aligned with the data received. See https://stackoverflow.com/questions/16177947/identification-of-packets-in-a-byte-stream/16180135#16180135 – sawdust Mar 28 '22 at 04:58

0 Answers0