Table of Contents

Class Writer

Namespace
DuetControlServer.Link.Protocol
Assembly
DuetControlServer.dll

Static class for writing data for SPI transmissions. This class makes sure each data block is on a 4-byte boundary to guarantee efficient DMA transfers on the remote side.

public static class Writer
Inheritance
Writer
Inherited Members

Methods

Calculate the size of a binary G/M/T-code

public static int GetCodeSize(Code code, int bufferSize, int protocolVersion)

Parameters

code Code

Code to write

bufferSize int

Size of the buffer to write to

protocolVersion int

Protocol version

Returns

int

Code size in bytes

Exceptions

ArgumentException

Thrown if the code is too long to fit into the buffer

Initialize a transfer header

public static void InitTransferHeader(ref TransferHeader header)

Parameters

header TransferHeader

Header reference to initialize

Assign a filament name to the given extruder drive

public static int WriteAssignFilament(Span<byte> to, int extruder, string filamentName)

Parameters

to Span<byte>

Destination

extruder int

Extruder drive

filamentName string

Filament name

Returns

int

Number of bytes written

Write an arbitrary boolean value

public static int WriteBoolean(Span<byte> to, bool value)

Parameters

to Span<byte>

Destination

value bool

Boolean value

Returns

int

Number of bytes written

Write a parsed G/M/T code in binary format to a memory span

public static int WriteCode(Span<byte> to, Code code, int protocolVersion)

Parameters

to Span<byte>

Destination

code Code

Code to write

protocolVersion int

Protocol version

Returns

int

Number of bytes written

Exceptions

ArgumentException

Unsupported data type

Write a G-code channel

public static int WriteCodeChannel(Span<byte> to, CodeChannel channel)

Parameters

to Span<byte>

Destination

channel CodeChannel

Channel for the lock request

Returns

int

Number of bytes written

Write a DeleteLocalVariableHeader to a memory span

public static int WriteDeleteLocalVariable(Span<byte> to, CodeChannel channel, string varName)

Parameters

to Span<byte>

Destination

channel CodeChannel

Source of this request

varName string

Name of the variable excluding var prefix

Returns

int

Number of bytes written

Write a request to evaluate an expression

public static int WriteEvaluateExpression(Span<byte> to, CodeChannel channel, string expression)

Parameters

to Span<byte>

Destination

channel CodeChannel

Where to evaluate the expression

expression string

Expression to evaluate

Returns

int

Number of bytes written

Write a file chunk

public static int WriteFileChunk(Span<byte> to, Span<byte> data, long fileLength)

Parameters

to Span<byte>

Destination

data Span<byte>

File chunk data

fileLength long

Total length of the file in bytes

Returns

int

Number of bytes written

Write read file data

public static int WriteFileReadResult(Span<byte> to, Span<byte> data, int bytesRead)

Parameters

to Span<byte>

Destination

data Span<byte>

Read file data

bytesRead int

Number of bytes read

Returns

int

Number of bytes written

Request a part of the object model

public static int WriteGetObjectModel(Span<byte> to, string key, string flags)

Parameters

to Span<byte>

Destination

key string

Key to the object model part

flags string

Object model flags

Returns

int

Number of bytes written

Write notification about a completed macro file

public static int WriteMacroCompleted(Span<byte> to, CodeChannel channel, bool error)

Parameters

to Span<byte>

Destination

channel CodeChannel

Channel where the macro file has finished

error bool

Whether an error occurred when trying to open/process the macro file

Returns

int

Number of bytes written

Write a MessageHeader to a memory span

public static int WriteMessage(Span<byte> to, MessageTypeFlags type, string message)

Parameters

to Span<byte>

Destination

type MessageTypeFlags

Message flags

message string

Message content

Returns

int

Number of bytes written

Write the result of an attempt to open a file

public static int WriteOpenFileResult(Span<byte> to, uint handle, long fileSize)

Parameters

to Span<byte>

Destination

handle uint

File handle

fileSize long

File length

Returns

int

Number of bytes written

Write an arbitrary packet header to a memory span

public static void WritePacketHeader(Span<byte> to, Request request, ushort id, int length)

Parameters

to Span<byte>

Destination

request Request

Packet type

id ushort

Packet ID

length int

Length of the packet

Notify the firmware that a print has started

public static int WritePrintFileInfo(Span<byte> to, GCodeFileInfo info)

Parameters

to Span<byte>

Destination

info GCodeFileInfo

Information about the file being printed

Returns

int

Number of bytes written

Exceptions

ArgumentException

One of the supplied values is too big

Notify the firmware that a print has been stopped

public static int WritePrintStopped(Span<byte> to, PrintStoppedReason reason)

Parameters

to Span<byte>

Destination

reason PrintStoppedReason

Reason why the print has been stopped

Returns

int

Number of bytes written

Write the last result of a code executed by the SBC

public static int WriteSetLastCodeResult(Span<byte> to, CodeChannel channel, CodeResult result)

Parameters

to Span<byte>

Destination

channel CodeChannel

Code channel

result CodeResult

Code result

Returns

int

Number of bytes written

Request the update of an object model field to an arbitrary value via a GetObjectModel request

public static int WriteSetObjectModel(Span<byte> to, string field, object value)

Parameters

to Span<byte>

Destination

field string

Path to the object model field

value object

New value

Returns

int

Number of bytes written

value must be of type DataType

Exceptions

ArgumentException

Unsupported data type

Write a SetVariableHeader to a memory span

public static int WriteSetVariable(Span<byte> to, CodeChannel channel, bool createVariable, string varName, string expression)

Parameters

to Span<byte>

Destination

channel CodeChannel

Source of this request

createVariable bool

Create a new variable

varName string

Name of the variable including prefix

expression string

Content to assign to the variable

Returns

int

Number of bytes written

Write a StringHeader to a memory span

public static int WriteStringRequest(Span<byte> to, string data)

Parameters

to Span<byte>

Destination

data string

String data

Returns

int

Number of bytes written