A .NET library for interfacing with Slamtec RPLidar A-series LiDAR sensors over a serial connection. Tested with real hardware (A1M8). Targets netstandard2.0 — compatible with .NET 6, 7, 8, and .NET Framework 4.6.1+.
Full documentation is available at asheesh1996.github.io/RpLidar.NET:
- Getting Started — Installation, platform setup, usage patterns
- API Reference — Every class, method, and property documented
- Support — How to report bugs and request features
| Model | Scan Mode | Max Range |
|---|---|---|
| A1M8 | Standard / Sensitivity | 12 m |
| A2M8 | Standard / Boost / Sensitivity | 18 m |
| A3M1 | Standard / Boost / Sensitivity | 25 m |
dotnet add package RpLidar.NETOr via the NuGet Package Manager in Visual Studio: search for RpLidar.NET.
using RpLidar.NET;
using RpLidar.NET.Entities;
// Replace with your actual port:
// Windows : "COM3"
// Linux : "/dev/ttyUSB0"
// macOS : "/dev/tty.usbserial-..."
using var lidar = new RPLidar("COM3");
lidar.LidarPointScanEvent += points =>
{
foreach (var p in points)
Console.WriteLine($"Angle: {p.Angle:F1}° Distance: {p.Distance:F0} mm Quality: {p.Quality}");
};
Console.WriteLine("Scanning — press Enter to stop.");
Console.ReadLine();The RPLidar constructor connects, starts the motor, and begins scanning immediately.
Scan data is delivered via LidarPointScanEvent approximately every 400 ms (configurable).
| Mode | Enum Value | Protocol | Description |
|---|---|---|---|
| Standard | ScanMode.Standard |
Scan (0x20) | Basic scan, ~2,000 samples/rev. All A-series. |
| Boost | ScanMode.Boost |
Express Scan (0x82, mode=3) | Higher frequency. A2/A3 only. |
| Sensitivity | ScanMode.Sensitivity |
Express Scan (0x82, mode=4) | Ultra-Capsule; highest density. Default. |
Use RpLidarSerialDevice directly for full control:
using RpLidar.NET;
using RpLidar.NET.Entities;
var settings = new LidarSettings
{
Port = "COM3",
BaudRate = 115200,
ScanMode = ScanMode.Sensitivity,
Pwm = 660, // Motor speed: 0 (stop) – 1023 (full)
MaxDistance = 25000, // mm — consumers can filter by this
ElapsedMilliseconds = 400, // Scan event fires at most every 400 ms
};
using var device = new RpLidarSerialDevice(settings);
device.LidarPointScanEvent += OnScan;
device.Start();
Console.ReadLine();
device.Stop();
static void OnScan(List<LidarPoint> points)
{
Console.WriteLine($"{points.Count} points");
}| Member | Description |
|---|---|
RPLidar(string port, int baudrate = 115200) |
Connect and start scanning. |
event LidarPointScanEvent |
Raised with batched scan points. |
Stop() |
Stop scanning and motor. |
Dispose() |
Stop and release all resources. |
| Member | Description |
|---|---|
Connect() |
Open the serial port. |
Disconnect() |
Close the serial port. |
StartMotor() |
Enable motor at the configured PWM. |
StopMotor() |
Set PWM to 0 and stop motor. |
StartScan() |
Start Standard scan and read thread. |
ForceScan() |
Force scan (no motor-sync check). |
ForceScanExpress() |
Start Express scan (Boost or Sensitivity). |
StopScan() |
Stop the read thread and motor. |
Start() |
Connect → StopScan → pick scan mode → start. |
Stop() |
StopScan. |
SendRequest(Command) |
Send a raw protocol command. |
event LidarPointScanEvent |
Raw point list, fired on timer. |
event LidarPointGroupScanEvent |
Angle-keyed LidarPointGroup, fired on timer. |
| Property | Type | Description |
|---|---|---|
Angle |
float |
Heading in degrees (0 – 360). |
Distance |
float |
Distance in millimetres. |
Quality |
ushort |
Measurement quality (higher = better). |
StartFlag |
bool |
true at the start of a new 360° revolution. |
IsValid |
bool |
true when Distance > 0. |
An angle-keyed collection (0.1° resolution) built from a batch of LidarPoint values.
Useful for per-angle lookups:
// Nearest obstacle directly ahead
var ahead = group[0]; // angle = 0°
if (ahead != null)
Console.WriteLine($"Obstacle at {ahead.Distance} mm");- Windows: Use
COMnport names (e.g.COM3). The USB-UART adapter appears in Device Manager. - Linux: Typically
/dev/ttyUSB0. You may need to add your user to thedialoutgroup:sudo usermod -aG dialout $USER - macOS:
/dev/tty.usbserial-*or/dev/tty.SLAB_USBtoUART.
git clone https://github.com/asheesh1996/RpLidar.NET.git
cd RpLidar.NET
dotnet build