The NewLine Serialization Method, or the NewLine Serialization Protocol, is a minimalistic communication protocol designed for various serial communication scenarios. It defines how the serial data stream is separated into individual packets. Due to its simplicity, it is most suited in embedded systems.
There are 4 (four) different characters defined in the ISLP specification.
HEX | DEC | OCT | Name | Description |
---|---|---|---|---|
0x0A | 10 | 0o12 | END | End Of Frame character |
0x0B | 11 | 0o13 | ESC | Escape character |
0x1A | 26 | 0o32 | ESC_END | Escaped End Of Frame character |
0x1B | 27 | 0o33 | ESC_ESC | Escaped Escape character |
When transmitting data, the sender will pre-process the data according to the following steps:
[... | x | ESC | x | ...] => [... | x | ESC | ESC_ESC | x | ...]
[... | x | END | x | ...] => [... | x | ESC | ESC_END | x | ...]
[... | x ] => [... | x | END ]
When receiving data, the receiver will process the data according to the following steps:
[... | x | ESC | ESC_ESC | x | ...] => [... | x | ESC | x | ...]
[... | x | ESC | ESC_END | x | ...] => [... | x | END | x | ...]
[... | x | END ] => [... | x ]
The Protocol needs to run under 8-bit data mode. (Will not work under 7-bit, 5-bit or other data modes).
The Protocol does not provide data validation. The integrity of data will be ensured by the upper protocols.
The END character is the newline character in ASCII character set, and frames will be separated into different lines in a serial monitor. This is easier to debug and more readable compared to SLIP and COBS.
Download the .zip
file and extract it into <Arduino_installation_path>/Sketchbook/libraries/
A simple echo program
#include "dotserializer.h"
using namespace rath;
uint8_t buffer[128];
void setup() {
Serializer.init(115200);
}
void loop() {
uint16_t rx_size = Serializer.receive(buffer, 128);
Serializer.transmit(buffer, rx_size);
}
pip install dotserializer
List all available ports
from dotserializer import Serializer
ports = Serializer.getAvailablePorts()
print(ports)
A simple echo program
import time
from dotserializer import Serializer
ser = Serializer(port="COM1", baudrate=115200)
# wait for serial device to initialize
time.sleep(2)
while True:
buffer = ser.receive()
print("recv", buffer)
ser.transmit(buffer)
Packet receiving timeout, blocking vs non-blocking
buffer = ser.receive(timeout=None) # blocking (default)
buffer = ser.receive(timeout=0) # non-blocking, return b"" if no data
buffer = ser.receive(timeout=1) # timeout for 1 sec, return b"" if no data