Class Writer
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.
Inherited Members
Namespace: DuetControlServer.SPI.Serialization
Assembly: DuetControlServer.dll
Syntax
public static class Writer
Methods
InitTransferHeader(ref TransferHeader)
Initialize a transfer header
Declaration
public static void InitTransferHeader(ref TransferHeader header)
Parameters
Type | Name | Description |
---|---|---|
TransferHeader | header | Header reference to initialize |
WriteAssignFilament(Span<byte>, int, string)
Assign a filament name to the given extruder drive
Declaration
public static int WriteAssignFilament(Span<byte> to, int extruder, string filamentName)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
int | extruder | Extruder drive |
string | filamentName | Filament name |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteBoolean(Span<byte>, bool)
Write an arbitrary boolean value
Declaration
public static int WriteBoolean(Span<byte> to, bool value)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
bool | value | Boolean value |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteCode(Span<byte>, Code)
Write a parsed G/M/T code in binary format to a memory span
Declaration
public static int WriteCode(Span<byte> to, Code code)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
Code | code | Code to write |
Returns
Type | Description |
---|---|
int | Number of bytes written |
Exceptions
Type | Condition |
---|---|
ArgumentException | Unsupported data type |
WriteCodeChannel(Span<byte>, CodeChannel)
Write a G-code channel
Declaration
public static int WriteCodeChannel(Span<byte> to, CodeChannel channel)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
CodeChannel | channel | Channel for the lock request |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteDeleteLocalVariable(Span<byte>, CodeChannel, string)
Write a DeleteLocalVariableHeader to a memory span
Declaration
public static int WriteDeleteLocalVariable(Span<byte> to, CodeChannel channel, string varName)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
CodeChannel | channel | Source of this request |
string | varName | Name of the variable excluding var prefix |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteEvaluateExpression(Span<byte>, CodeChannel, string)
Write a request to evaluate an expression
Declaration
public static int WriteEvaluateExpression(Span<byte> to, CodeChannel channel, string expression)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
CodeChannel | channel | Where to evaluate the expression |
string | expression | Expression to evaluate |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteFileChunk(Span<byte>, Span<byte>, long)
Write a file chunk
Declaration
public static int WriteFileChunk(Span<byte> to, Span<byte> data, long fileLength)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
Span<byte> | data | File chunk data |
long | fileLength | Total length of the file in bytes |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteFileReadResult(Span<byte>, Span<byte>, int)
Write read file data
Declaration
public static int WriteFileReadResult(Span<byte> to, Span<byte> data, int bytesRead)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
Span<byte> | data | Read file data |
int | bytesRead | Number of bytes read |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteGetObjectModel(Span<byte>, string, string)
Request a part of the object model
Declaration
public static int WriteGetObjectModel(Span<byte> to, string key, string flags)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
string | key | Key to the object model part |
string | flags | Object model flags |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteMacroCompleted(Span<byte>, CodeChannel, bool)
Write notification about a completed macro file
Declaration
public static int WriteMacroCompleted(Span<byte> to, CodeChannel channel, bool error)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
CodeChannel | channel | Channel where the macro file has finished |
bool | error | Whether an error occurred when trying to open/process the macro file |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteMessage(Span<byte>, MessageTypeFlags, string)
Write a MessageHeader to a memory span
Declaration
public static int WriteMessage(Span<byte> to, MessageTypeFlags type, string message)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
MessageTypeFlags | type | Message flags |
string | message | Message content |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteOpenFileResult(Span<byte>, uint, long)
Write the result of an attempt to open a file
Declaration
public static int WriteOpenFileResult(Span<byte> to, uint handle, long fileSize)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
uint | handle | File handle |
long | fileSize | File length |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WritePacketHeader(Span<byte>, Request, ushort, int)
Write an arbitrary packet header to a memory span
Declaration
public static void WritePacketHeader(Span<byte> to, Request request, ushort id, int length)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
Request | request | Packet type |
ushort | id | Packet ID |
int | length | Length of the packet |
WritePrintFileInfo(Span<byte>, GCodeFileInfo)
Notify the firmware that a print has started
Declaration
public static int WritePrintFileInfo(Span<byte> to, GCodeFileInfo info)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
GCodeFileInfo | info | Information about the file being printed |
Returns
Type | Description |
---|---|
int | Number of bytes written |
Exceptions
Type | Condition |
---|---|
ArgumentException | One of the supplied values is too big |
WritePrintStopped(Span<byte>, PrintStoppedReason)
Notify the firmware that a print has been stopped
Declaration
public static int WritePrintStopped(Span<byte> to, PrintStoppedReason reason)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
PrintStoppedReason | reason | Reason why the print has been stopped |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteSetObjectModel(Span<byte>, string, object)
Request the update of an object model field to an arbitrary value via a GetObjectModel request
Declaration
public static int WriteSetObjectModel(Span<byte> to, string field, object value)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
string | field | Path to the object model field |
object | value | New value |
Returns
Type | Description |
---|---|
int | Number of bytes written |
Remarks
value must be of type DataType
Exceptions
Type | Condition |
---|---|
ArgumentException | Unsupported data type |
WriteSetVariable(Span<byte>, CodeChannel, bool, string, string)
Write a SetVariableHeader to a memory span
Declaration
public static int WriteSetVariable(Span<byte> to, CodeChannel channel, bool createVariable, string varName, string expression)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
CodeChannel | channel | Source of this request |
bool | createVariable | Create a new variable |
string | varName | Name of the variable including prefix |
string | expression | Content to assign to the variable |
Returns
Type | Description |
---|---|
int | Number of bytes written |
WriteStringRequest(Span<byte>, string)
Write a StringHeader to a memory span
Declaration
public static int WriteStringRequest(Span<byte> to, string data)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | to | Destination |
string | data | String data |
Returns
Type | Description |
---|---|
int | Number of bytes written |