Skip to content
Snippets Groups Projects
Commit 57c4a260 authored by Charles JAVERLIAT's avatar Charles JAVERLIAT
Browse files

Update README.md

parent 09dd6989
No related branches found
No related tags found
No related merge requests found
# Serial framing protocol
This library provides a way to frame data safely (including a corruption check).
## How-to-use
### Framing data
```python
# The data to be framed
data = bytearray([0x12, 0x34, 0x56])
# Frame and store the result in framed_data
framed_data = bytearray()
frame_data(data, framed_data)
# Print the hexadecimal representation of the result
# This will return b'7e0003123456bf127f'
print(binascii.hexlify(framed_data))
```
The actual byte sent are `0x7e 0x0 0x3 0x12 0x34 0x56 0xbf 0x12 0x7f`.
In those bytes:
- `0x7e` is the start of frame flag (1 byte)
- `0x0 0x3` is the data size (2 bytes)
- `0x12 0x34` is the data we are sending (n bytes)
- `0xbf 0x12` is the cyclic redundancy check (2 bytes), it helps checking for any corruption of the data
- `0x7f` is the end of frame flag (1 byte)
### Unframing data
```python
# The frame to unframe the data from
framed_data = bytearray([0x7e, 0x0, 0x3, 0x12, 0x34, 0x56, 0xbf, 0x12, 0x7f])
# Unframe and store the result in unframed_data
unframed_data = bytearray()
unframe_data(framed_data, unframed_data)
# Print the hexadecimal representation of the result
# This will return b'123456'
print(binascii.hexlify(unframed_data))
```
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment