Page 1 of 1

UART receive MAVLink messages micropython

Posted: Fri Jun 30, 2017 3:35 pm
by airborne
As the title says I'm trying to read MAVLink messages using Micropython.
I know the length of the message, so I was thinking of using - but that doesn't ensure I'm reading from the start of a message. Is there a way to specify start and stop bytes for UART read using Micropython? If I can't implement this in MicroPython, coding in C may be easier because headers for these messages can be auto-generated. However where the actual code for reading from UART using C is buried is beyond me. I've taken a look at files uart.c, uart.h and stream.c.

I've also read through /viewtopic.php?t=2848 and didn't find anything that helpful for me. Any ideas on how to proceed would be greatly appreciated.


Re: UART receive MAVLink messages micropython

Posted: Sat Jul 01, 2017 7:53 pm
by dhylands
I highly recommend that read one character at a time and build up the packet in memory. Doing multi-byte reads will cause all types of issues if a character ever gets dropped, or an extra one gets inserted.

For example, I wrote some code for sending/receiving packets to bioloid servos.

This is the code that processes a single byte from the UART: ...

This is an example of where it gets called: ...

I have low-level routines which work over USB: ...

or over a UART: ...

Re: UART receive MAVLink messages micropython

Posted: Sat Jul 01, 2017 9:42 pm
by airborne
Thanks for the tips Dave. I'll look through what you just posted and give that a try!