Table of Contents

Class Reader

Namespace
DuetControlServer.Link.Protocol
Assembly
DuetControlServer.dll

Static class for reading data from SPI transmissions. It is expected that each data block occupies entire 4-byte blocks. Make sure to keep the data returned by these functions only as long as the underlying buffer is actually valid!

public static class Reader
Inheritance
Reader
Inherited Members

Methods

Read information about an abort file request

public static int ReadAbortFile(ReadOnlySpan<byte> from, out CodeChannel channel, out bool abortAll)

Parameters

from ReadOnlySpan<byte>

Origin

channel CodeChannel

Code channel running the file

abortAll bool

Whether all files are supposed to be aborted

Returns

int

Number of bytes read

Read a code buffer update from a memory span

public static int ReadCodeBufferUpdate(ReadOnlySpan<byte> from, out ushort bufferSpace)

Parameters

from ReadOnlySpan<byte>

Origin

bufferSpace ushort

Buffer space

Returns

int

Number of bytes read

Read a G-code channel

public static int ReadCodeChannel(ReadOnlySpan<byte> from, out CodeChannel channel)

Parameters

from ReadOnlySpan<byte>

Origin

channel CodeChannel

Channel that has acquired the lock

Returns

int

Number of bytes read

Read a DoCode request

public static int ReadDoCode(ReadOnlySpan<byte> from, out CodeChannel channel, out string code)

Parameters

from ReadOnlySpan<byte>

Origin

channel CodeChannel

Code channel

code string

Code to execute

Returns

int

Number of bytes read

Read a EvaluationResult request

public static int ReadEvaluationResult(ReadOnlySpan<byte> from, out CodeChannel channel, out string expression, out object? result)

Parameters

from ReadOnlySpan<byte>

Origin

channel CodeChannel

Channel where the evaluation was performed

expression string

Expression

result object

Evaluation result

Returns

int

Number of bytes read

Read a file chunk request`

public static int ReadFileChunkRequest(ReadOnlySpan<byte> from, out string filename, out uint offset, out int maxLength)

Parameters

from ReadOnlySpan<byte>

Origin

filename string

Filename to read from

offset uint

Offset in the file

maxLength int

Maximum chunk length

Returns

int

Number of bytes read

Read an arbitrary file handle

public static int ReadFileHandle(ReadOnlySpan<byte> from, out uint handle)

Parameters

from ReadOnlySpan<byte>

Origin

handle uint

File handle

Returns

int

Number of bytes read

Read a request to retrieve data from a file

public static int ReadFileRequest(ReadOnlySpan<byte> from, out uint handle, out int maxLength)

Parameters

from ReadOnlySpan<byte>

Origin

handle uint

File handle

maxLength int

Maximum buffer length

Returns

int

Number of bytes read

Read a legacy print pause event

public static int ReadLegacyPrintPaused(ReadOnlySpan<byte> from, out uint filePosition, out PrintPausedReason reason)

Parameters

from ReadOnlySpan<byte>

Origin

filePosition uint

Position at which the print has been paused

reason PrintPausedReason

Reason why the print has been paused

Returns

int

Number of bytes read

Read a macro file request from a memory span

public static int ReadMacroRequest(ReadOnlySpan<byte> from, out CodeChannel channel, out bool fromCode, out string filename)

Parameters

from ReadOnlySpan<byte>

Origin

channel CodeChannel

Code channel that requested the execution

fromCode bool

Whether the macro request came from the G/M/T-code being executed

filename string

Filename of the macro to execute

Returns

int

Number of bytes read

Read a message from a memory span

public static int ReadMessage(ReadOnlySpan<byte> from, out MessageTypeFlags messageType, out string reply)

Parameters

from ReadOnlySpan<byte>

Origin

messageType MessageTypeFlags

Message flags

reply string

Raw message

Returns

int

Number of bytes read

Read an open file request

public static int ReadOpenFile(ReadOnlySpan<byte> from, out string filename, out bool forWriting, out bool append, out long preAllocSize)

Parameters

from ReadOnlySpan<byte>

Origin

filename string

Filename to open

forWriting bool

Whether the file is supposed to be written to

append bool

Whether data is supposed to be appended in write mode

preAllocSize long

How many bytes to allocate if the file is created or overwritten

Returns

int

Number of bytes read

Read a packet header from a memory span

public static int ReadPacketHeader(ReadOnlySpan<byte> from, out PacketHeader packet)

Parameters

from ReadOnlySpan<byte>

Origin

packet PacketHeader

Read packet

Returns

int

Number of bytes read

Read a print pause event

public static int ReadPrintPaused(ReadOnlySpan<byte> from, out uint filePosition, out uint filePosition2, out PrintPausedReason reason)

Parameters

from ReadOnlySpan<byte>

Origin

filePosition uint

Position at which the print has been paused

filePosition2 uint

Position at which the second open file has been paused (if applicable)

reason PrintPausedReason

Reason why the print has been paused

Returns

int

Number of bytes read

Read a request to seek in a file

public static int ReadSeekFile(ReadOnlySpan<byte> from, out uint handle, out long offset)

Parameters

from ReadOnlySpan<byte>

Origin

handle uint

File handle

offset long

New file position

Returns

int

Number of bytes read

Read a UTF-8 encoded string request from a memory span

public static int ReadStringRequest(ReadOnlySpan<byte> from, out ReadOnlySpan<byte> data)

Parameters

from ReadOnlySpan<byte>

Origin

data ReadOnlySpan<byte>

UTF-8 string

Returns

int

Number of bytes read

Read a UTF-8 encoded string request from a memory span

public static int ReadStringRequest(ReadOnlySpan<byte> from, out string data)

Parameters

from ReadOnlySpan<byte>

Origin

data string

UTF-8 string

Returns

int

Number of bytes read