Table of Contents

Class SpanExtensions

Namespace
FluentModbus
Assembly
FluentModbus.dll

Contains extension methods to read and write data from the Modbus registers.

public static class SpanExtensions
Inheritance
SpanExtensions

Methods

Cast<TFrom, TTo>(Memory<TFrom>)

Casts a memory of one primitive type to a memory of another primitive type.

public static Memory<TTo> Cast<TFrom, TTo>(this Memory<TFrom> memory) where TFrom : struct where TTo : struct

Parameters

memory Memory<TFrom>

The source slice to convert.

Returns

Memory<TTo>

The converted memory.

Type Parameters

TFrom

The type of the source memory.

TTo

The type of the target memory.

Get(Span<byte>, int)

Reads a single bit from the buffer.

public static bool Get(this Span<byte> buffer, int address)

Parameters

buffer Span<byte>

The source buffer.

address int

The Modbus address.

Returns

bool

GetBigEndian<T>(Span<short>, int)

Reads a single big-endian value of type T from the registers.

public static T GetBigEndian<T>(this Span<short> buffer, int address) where T : unmanaged

Parameters

buffer Span<short>

The source buffer.

address int

The Modbus register address.

Returns

T

Type Parameters

T

The type of the value to read.

GetLittleEndian<T>(Span<short>, int)

Reads a single little-endian value of type T from the registers.

public static T GetLittleEndian<T>(this Span<short> buffer, int address) where T : unmanaged

Parameters

buffer Span<short>

The source buffer.

address int

The Modbus register address.

Returns

T

Type Parameters

T

The type of the value to read.

GetMidLittleEndian<T>(Span<short>, int)

Reads a single mid-little-endian value of type T from the registers.

public static T GetMidLittleEndian<T>(this Span<short> buffer, int address) where T : unmanaged

Parameters

buffer Span<short>

The source buffer.

address int

The Modbus register address.

Returns

T

Type Parameters

T

The type of the value to read.

Set(Span<byte>, int, bool)

Writes a single bit to the buffer.

public static void Set(this Span<byte> buffer, int address, bool value)

Parameters

buffer Span<byte>

The target buffer.

address int

The Modbus address.

value bool

The value to set.

SetBigEndian<T>(Span<short>, int, T)

Writes a single value of type T to the registers and converts it to the big-endian representation if necessary.

public static void SetBigEndian<T>(this Span<short> buffer, int address, T value) where T : unmanaged

Parameters

buffer Span<short>

The target buffer.

address int

The Modbus register address.

value T

The value to write.

Type Parameters

T

The type of the value to write.

SetLittleEndian<T>(Span<short>, int, T)

Writes a single value of type T to the registers and converts it to the little-endian representation if necessary.

public static void SetLittleEndian<T>(this Span<short> buffer, int address, T value) where T : unmanaged

Parameters

buffer Span<short>

The target buffer.

address int

The Modbus register address.

value T

The value to write.

Type Parameters

T

The type of the value to write.

SetMidLittleEndian<T>(Span<short>, int, T)

Writes a single value of type T to the registers and converts it to the mid-little-endian representation.

public static void SetMidLittleEndian<T>(this Span<short> buffer, int address, T value) where T : unmanaged

Parameters

buffer Span<short>

The target buffer.

address int

The Modbus register address.

value T

The value to write.

Type Parameters

T

The type of the value to write.

Toggle(Span<byte>, int)

Toggles a single bit in the buffer.

public static void Toggle(this Span<byte> buffer, int address)

Parameters

buffer Span<byte>

The source buffer.

address int

The Modbus address.