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.
Inheritance
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>, Int32, 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.Int32 | extruder | Extruder drive |
System.String | filamentName | Filament name |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
WriteBoolean(Span<Byte>, Boolean)
Write an arbitrary boolean value
Declaration
public static int WriteBoolean(Span<byte> to, bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.Boolean | value | Boolean value |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
Code | code | Code to write |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
Exceptions
Type | Condition |
---|---|
System.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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
CodeChannel | channel | Channel for the lock request |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
CodeChannel | channel | Source of this request |
System.String | varName | Name of the variable excluding var prefix |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
CodeChannel | channel | Where to evaluate the expression |
System.String | expression | Expression to evaluate |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
WriteFileChunk(Span<Byte>, Span<Byte>, Int64)
Write a file chunk
Declaration
public static int WriteFileChunk(Span<byte> to, Span<byte> data, long fileLength)
Parameters
Type | Name | Description |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.Span<System.Byte> | data | File chunk data |
System.Int64 | fileLength | Total length of the file in bytes |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
WriteFileReadResult(Span<Byte>, Span<Byte>, Int32)
Write read file data
Declaration
public static int WriteFileReadResult(Span<byte> to, Span<byte> data, int bytesRead)
Parameters
Type | Name | Description |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.Span<System.Byte> | data | Read file data |
System.Int32 | bytesRead | Number of bytes read |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.String | key | Key to the object model part |
System.String | flags | Object model flags |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
WriteMacroCompleted(Span<Byte>, CodeChannel, Boolean)
Write notification about a completed macro file
Declaration
public static int WriteMacroCompleted(Span<byte> to, CodeChannel channel, bool error)
Parameters
Type | Name | Description |
---|---|---|
System.Span<System.Byte> | to | Destination |
CodeChannel | channel | Channel where the macro file has finished |
System.Boolean | error | Whether an error occurred when trying to open/process the macro file |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
MessageTypeFlags | type | Message flags |
System.String | message | Message content |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
WriteOpenFileResult(Span<Byte>, UInt32, Int64)
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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.UInt32 | handle | File handle |
System.Int64 | fileSize | File length |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
WritePacketHeader(Span<Byte>, Request, UInt16, Int32)
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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
Request | request | Packet type |
System.UInt16 | id | Packet ID |
System.Int32 | 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
GCodeFileInfo | info | Information about the file being printed |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
Exceptions
Type | Condition |
---|---|
System.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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
PrintStoppedReason | reason | Reason why the print has been stopped |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
WriteSetObjectModel(Span<Byte>, String, Object)
Request the update of an object model field to an arbitrary value via a SetObjectModel request
Declaration
public static int WriteSetObjectModel(Span<byte> to, string field, object value)
Parameters
Type | Name | Description |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.String | field | Path to the object model field |
System.Object | value | New value |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |
Remarks
value must be of type DataType
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Unsupported data type |
WriteSetVariable(Span<Byte>, CodeChannel, Boolean, 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
CodeChannel | channel | Source of this request |
System.Boolean | createVariable | Create a new variable |
System.String | varName | Name of the variable including prefix |
System.String | expression | Content to assign to the variable |
Returns
Type | Description |
---|---|
System.Int32 | 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 |
---|---|---|
System.Span<System.Byte> | to | Destination |
System.String | data | String data |
Returns
Type | Description |
---|---|
System.Int32 | Number of bytes written |