RpLidarSerialDevice
Namespace: RpLidar.NET
Low-level serial device implementation of ILidarService with full protocol control.
Table of Contents
- Definition
- Constructors
- Events
- Methods — Lifecycle
- Methods — Motor Control
- Methods — Scanning
- Methods — Protocol
- Remarks
- See Also
Definition
public class RpLidarSerialDevice : ILidarService
RpLidarSerialDevice implements the complete SLAMTEC serial protocol v2.1. It gives you explicit control over connection, disconnection, scan mode, motor speed, and request/response cycles.
Constructors
RpLidarSerialDevice(ILidarSettings settings)
Creates a new device instance. Does not connect to the port until Connect() is called.
| Parameter | Type | Description |
|---|---|---|
settings | ILidarSettings | Configuration: port, baud rate, scan mode, PWM, etc. |
var settings = new LidarSettings
{
Port = "/dev/ttyUSB0",
ScanMode = ScanMode.Standard
};
var device = new RpLidarSerialDevice(settings);
Events
LidarPointScanEvent
public event LidarPointScanEvenHandler LidarPointScanEvent;
Fired every settings.ElapsedMilliseconds (default 400 ms) with raw points from the current scan window.
LidarPointGroupScanEvent
public event LidarPointGroupScanEvenHandler LidarPointGroupScanEvent;
Fired alongside LidarPointScanEvent with the same points wrapped in a LidarPointGroup (angle-indexed at 0.1° resolution).
Methods — Lifecycle
Connect()
public void Connect()
Opens the serial port and initialises the device. Call before any other method.
Disconnect()
public void Disconnect()
Closes the serial port. Call after Stop().
Start()
public void Start()
Convenience method that:
- Calls
Connect()(if not already connected) - Sends
StopScan - Detects the scan mode from
settings.ScanMode - Starts the appropriate scan command
- Launches the background scan thread
Stop()
public void Stop()
Sends StopScan and terminates the background scan thread.
Dispose()
public void Dispose()
Stops the scan, stops the motor, disconnects, and releases all resources.
Methods — Motor Control
StartMotor()
public void StartMotor()
Sends the motor-start PWM command using settings.Pwm (default 660).
StopMotor()
public void StopMotor()
Sends the motor-stop command (PWM = 0). The sensor will stop rotating.
Methods — Scanning
StartScan()
public void StartScan()
Sends the standard Scan command (0x20). Compatible with all supported models.
ForceScan()
public void ForceScan()
Sends the ForceScan command (0x21). Bypasses the motor-sync check — use when motor synchronisation is not needed.
ForceScanExpress()
public void ForceScanExpress()
Sends the ExpressScan command using settings.ScanMode. Issues the Boost (working_mode=3) or Sensitivity (working_mode=4) sub-mode as appropriate. Only supported on A2M8 and A3M1.
StopScan()
public void StopScan()
Sends the Stop command (0x25) to halt the current scan without stopping the motor.
Methods — Protocol
SendRequest(Command command)
public IDataResponse SendRequest(Command command)
Sends a single-response command and returns the parsed response.
| Parameter | Type | Description |
|---|---|---|
command | Command | The protocol command to send |
Returns IDataResponse — cast to InfoDataResponse or RpHealthResponse as appropriate.
var info = device.SendRequest(Command.GetInfo) as InfoDataResponse;
Console.WriteLine(info?.ModelId);
var health = device.SendRequest(Command.GetHealth) as RpHealthResponse;
Console.WriteLine(health?.Status); // 0=OK, 1=Warning, 2=Error
SendCommand(byte command, byte[] data = null)
public IDataResponse SendCommand(byte command, byte[] data = null)
Low-level raw command send. Prefer SendRequest with the Command enum for standard commands.
Read(int len, int timeout)
public byte[] Read(int len, int timeout)
Reads exactly len bytes from the serial port, waiting up to timeout milliseconds.
Remarks
- Call
Connect()before any other method (or callStart()which calls it internally). - All events fire on a background thread. Do not update UI controls directly from event handlers.
- To change scan mode after construction, create a new
RpLidarSerialDevicewith updated settings.
See Also
- RPLidar — simpler high-level wrapper
- ILidarSettings / LidarSettings — full settings reference
- Command — all available protocol commands