Class DataTransfer
Helper class for SPI data transfers
Inherited Members
Namespace: DuetControlServer.SPI
Assembly: DuetControlServer.dll
Syntax
public static class DataTransfer
Properties
PacketsToRead
Returns the number of packets to read
Declaration
public static int PacketsToRead { get; }
Property Value
Type | Description |
---|---|
int |
ProtocolVersion
Currently-used protocol version
Declaration
public static int ProtocolVersion { get; }
Property Value
Type | Description |
---|---|
int |
Methods
Diagnostics(StringBuilder)
Print diagnostics to the given string builder
Declaration
public static void Diagnostics(StringBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
StringBuilder | builder | Target to write to |
DumpMalformedPacket()
Write the last packet + content for diagnostic purposes
Declaration
public static void DumpMalformedPacket()
FlashFirmwareSegment(Stream)
Flash another segment of the firmware via the IAP binary
Declaration
public static bool FlashFirmwareSegment(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | Stream of the firmware binary |
Returns
Type | Description |
---|---|
bool | Whether another segment could be sent |
GetCodeSize(Code)
Calculate the size of a binary G/M/T-code
Declaration
public static int GetCodeSize(Code code)
Parameters
Type | Name | Description |
---|---|---|
Code | code | Code to write |
Returns
Type | Description |
---|---|
int | Code size in bytes |
GetMaxFullTransferDelay()
Get the maximum time between two full transfers
Declaration
public static double GetMaxFullTransferDelay()
Returns
Type | Description |
---|---|
double | Time in ms |
GetMaxPinWaitDuration(bool)
Get the maximum time to wait for the transfer ready pin to be toggled and reset the counter
Declaration
public static double GetMaxPinWaitDuration(bool fullTransferCounter)
Parameters
Type | Name | Description |
---|---|---|
bool | fullTransferCounter | Query and reset the full transfer duration |
Returns
Type | Description |
---|---|
double | Time in ms |
HadReset()
Check if the controller has been reset
Declaration
public static bool HadReset()
Returns
Type | Description |
---|---|
bool | Whether the controller has been reset |
Init()
Set up the SPI device and the controller for the transfer ready pin
Declaration
public static void Init()
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Failed to connect to board |
PerformFullTransfer(bool)
Perform a full data transfer synchronously
Declaration
public static void PerformFullTransfer(bool connecting = false)
Parameters
Type | Name | Description |
---|---|---|
bool | connecting | Whether this an initial connection is being established |
ReadAbortFile(out CodeChannel, out bool)
Read the content of an AbortFileHeader packet
Declaration
public static void ReadAbortFile(out CodeChannel channel, out bool abortAll)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Code channel where all files are supposed to be aborted |
bool | abortAll | Whether all files are supposed to be aborted |
ReadCheckFileExists(out string)
Read a request to check if a file exists
Declaration
public static void ReadCheckFileExists(out string filename)
Parameters
Type | Name | Description |
---|---|---|
string | filename | Name of the file |
ReadCloseFile(out uint)
Read a request to close a file
Declaration
public static void ReadCloseFile(out uint handle)
Parameters
Type | Name | Description |
---|---|---|
uint | handle | File handle |
ReadCodeBufferUpdate(out ushort)
Read a code buffer update
Declaration
public static void ReadCodeBufferUpdate(out ushort bufferSpace)
Parameters
Type | Name | Description |
---|---|---|
ushort | bufferSpace | Buffer space |
ReadCodeChannel(out CodeChannel)
Read a code channel
Declaration
public static void ReadCodeChannel(out CodeChannel channel)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Code channel that has acquired the lock |
ReadDeleteFileOrDirectory(out string)
Read a request to delete a file or directory
Declaration
public static void ReadDeleteFileOrDirectory(out string filename)
Parameters
Type | Name | Description |
---|---|---|
string | filename | Name of the file |
ReadDoCode(out CodeChannel, out string)
Read a code request
Declaration
public static void ReadDoCode(out CodeChannel channel, out string code)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Channel to execute this code on |
string | code | Code to execute |
ReadEvaluationResult(out string, out object?)
Read the result of an expression evaluation request
Declaration
public static void ReadEvaluationResult(out string expression, out object? result)
Parameters
Type | Name | Description |
---|---|---|
string | expression | Evaluated expression |
object | result | Result |
ReadFileChunkRequest(out string, out uint, out int)
Read a chunk of a FileChunk packet
Declaration
public static void ReadFileChunkRequest(out string filename, out uint offset, out int maxLength)
Parameters
Type | Name | Description |
---|---|---|
string | filename | Filename |
uint | offset | File offset |
int | maxLength | Maximum chunk size |
ReadFileRequest(out uint, out int)
Read a request to read data from a file
Declaration
public static void ReadFileRequest(out uint handle, out int maxLength)
Parameters
Type | Name | Description |
---|---|---|
uint | handle | File handle |
int | maxLength | Maximum data length |
ReadLegacyConfigResponse(out ReadOnlySpan<byte>)
Read the legacy result of a GetObjectModel request
Declaration
public static void ReadLegacyConfigResponse(out ReadOnlySpan<byte> json)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | json | JSON data |
ReadMacroRequest(out CodeChannel, out bool, out string)
Read the content of a ExecuteMacroHeader packet
Declaration
public static void ReadMacroRequest(out CodeChannel channel, out bool isSystemMacro, out string filename)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Channel requesting a macro file |
bool | isSystemMacro | Indicates if this code is not bound to a code being executed (e.g. when a trigger macro is requested) |
string | filename | Filename of the requested macro |
ReadMessage(out MessageTypeFlags, out string)
Read an incoming message
Declaration
public static void ReadMessage(out MessageTypeFlags messageType, out string reply)
Parameters
Type | Name | Description |
---|---|---|
MessageTypeFlags | messageType | Message type flags of the reply |
string | reply | Code reply |
ReadNextPacket()
Read the next packet
Declaration
public static PacketHeader? ReadNextPacket()
Returns
Type | Description |
---|---|
PacketHeader? | The next packet or null if none is available |
ReadObjectModel(out ReadOnlySpan<byte>)
Read the result of a GetObjectModel request
Declaration
public static void ReadObjectModel(out ReadOnlySpan<byte> json)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | json | JSON data |
ReadOpenFile(out string, out bool, out bool, out long)
Read an open file request
Declaration
public static void ReadOpenFile(out string filename, out bool forWriting, out bool append, out long preAllocSize)
Parameters
Type | Name | Description |
---|---|---|
string | filename | Filename to open |
bool | forWriting | Whether the file is supposed to be written to |
bool | append | Whether data is supposed to be appended in write mode |
long | preAllocSize | How many bytes to allocate if the file is created or overwritten |
ReadPrintPaused(out uint, out PrintPausedReason)
Read the content of a PrintPausedHeader packet
Declaration
public static void ReadPrintPaused(out uint filePosition, out PrintPausedReason reason)
Parameters
Type | Name | Description |
---|---|---|
uint | filePosition | Position where the print has been paused |
PrintPausedReason | reason | Reason why the print has been paused |
ReadSeekFile(out uint, out long)
Read a request to seek in a file
Declaration
public static void ReadSeekFile(out uint handle, out long offset)
Parameters
Type | Name | Description |
---|---|---|
uint | handle | File handle |
long | offset | New file position |
ReadTruncateFile(out uint)
Read a request to truncate a file
Declaration
public static void ReadTruncateFile(out uint handle)
Parameters
Type | Name | Description |
---|---|---|
uint | handle | File handle |
ReadWriteRequest(out uint, out ReadOnlySpan<byte>)
Read a request to write data to a file
Declaration
public static void ReadWriteRequest(out uint handle, out ReadOnlySpan<byte> data)
Parameters
Type | Name | Description |
---|---|---|
uint | handle | File handle |
ReadOnlySpan<byte> | data | Data to write |
ResendPacket(PacketHeader, out Request)
Resend a packet back to the firmware
Declaration
public static void ResendPacket(PacketHeader packet, out Request sbcRequest)
Parameters
Type | Name | Description |
---|---|---|
PacketHeader | packet | Packet holding the resend request |
Request | sbcRequest | Content of the packet to resend |
StartIap()
Instruct the firmware to start the IAP binary
Declaration
public static void StartIap()
VerifyFirmwareChecksum(long, ushort)
Send the CRC16 checksum of the firmware binary to the IAP program and verify the written data
Declaration
public static bool VerifyFirmwareChecksum(long firmwareLength, ushort crc16)
Parameters
Type | Name | Description |
---|---|---|
long | firmwareLength | Length of the written firmware in bytes |
ushort | crc16 | CRC16 checksum of the firmware |
Returns
Type | Description |
---|---|
bool | Whether the firmware has been written successfully |
WaitForIapReset()
Wait for the IAP program to reset the controller
Declaration
public static void WaitForIapReset()
WriteCheckFileExistsResult(bool)
Send back whether a file exists or not
Declaration
public static bool WriteCheckFileExistsResult(bool exists)
Parameters
Type | Name | Description |
---|---|---|
bool | exists | Whether the file exists |
Returns
Type | Description |
---|---|
bool | If the packet could be written |
WriteCode(Code)
Request a code to be executed
Declaration
public static bool WriteCode(Code code)
Parameters
Type | Name | Description |
---|---|---|
Code | code | Code to send |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteDeleteLocalVariable(CodeChannel, string)
Delete a local variable at the end of the current code block
Declaration
public static bool WriteDeleteLocalVariable(CodeChannel channel, string varName)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | G-code channel |
string | varName | Name of the variable excluding var prefix |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteEmergencyStop()
Request an emergency stop
Declaration
public static bool WriteEmergencyStop()
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteEvaluateExpression(CodeChannel, string)
Write a request for an expression evaluation
Declaration
public static bool WriteEvaluateExpression(CodeChannel channel, string expression)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Where to evaluate the expression |
string | expression | Expression to evaluate |
Returns
Type | Description |
---|---|
bool | Whether the evaluation request has been written successfully |
WriteFileChunk(Span<byte>, long)
Write another chunk of the file being requested
Declaration
public static bool WriteFileChunk(Span<byte> data, long fileLength)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | data | File chunk data |
long | fileLength | Total length of the file in bytes |
Returns
Type | Description |
---|---|
bool | Whether the firmware has been written successfully |
WriteFileDeleteResult(bool)
Send back whether a file or directory could be deleted
Declaration
public static bool WriteFileDeleteResult(bool success)
Parameters
Type | Name | Description |
---|---|---|
bool | success | Whether the file operation was successful |
Returns
Type | Description |
---|---|
bool | If the packet could be written |
WriteFileReadResult(Span<byte>, int)
Write requested read data from a file
Declaration
public static bool WriteFileReadResult(Span<byte> data, int bytesRead)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | data | File data |
int | bytesRead | Number of bytes read or negative on error |
Returns
Type | Description |
---|---|
bool | If the packet could be written |
WriteFileSeekResult(bool)
Tell RRF if the seek operation was successful
Declaration
public static bool WriteFileSeekResult(bool success)
Parameters
Type | Name | Description |
---|---|---|
bool | success | If the seek operation succeeded |
Returns
Type | Description |
---|---|
bool | If the packet could be written |
WriteFileTruncateResult(bool)
Tell RRF if the seek operation was successful
Declaration
public static bool WriteFileTruncateResult(bool success)
Parameters
Type | Name | Description |
---|---|---|
bool | success | If the seek operation succeeded |
Returns
Type | Description |
---|---|
bool | If the packet could be written |
WriteFileWriteResult(bool)
Tell RRF if the last file block could be written
Declaration
public static bool WriteFileWriteResult(bool success)
Parameters
Type | Name | Description |
---|---|---|
bool | success | If the file data could be written |
Returns
Type | Description |
---|---|
bool | If the packet could be written |
WriteGetLegacyConfigResponse()
Write the legacy request for the config response
Declaration
public static bool WriteGetLegacyConfigResponse()
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteGetObjectModel(string, string)
Request the key of a object module of a specific module
Declaration
public static bool WriteGetObjectModel(string key, string flags)
Parameters
Type | Name | Description |
---|---|---|
string | key | Object model key to query |
string | flags | Object model flags to query |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteIapSegment(Stream)
Write another segment of the IAP binary
Declaration
public static bool WriteIapSegment(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | IAP binary |
Returns
Type | Description |
---|---|
bool | Whether another segment could be written |
WriteInvalidateChannel(CodeChannel)
Called when a code channel is supposed to be invalidated (e.g. via abort keyword)
Declaration
public static bool WriteInvalidateChannel(CodeChannel channel)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Code channel that requires the lock |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteLockAllMovementSystemsAndWaitForStandstill(CodeChannel)
Request the movement systems to be locked and wait for standstill
Declaration
public static bool WriteLockAllMovementSystemsAndWaitForStandstill(CodeChannel channel)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Code channel that requires the lock |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteMacroCompleted(CodeChannel, bool)
Notify the firmware about a completed macro file. This function is only used for macro files that the firmware requested
Declaration
public static bool WriteMacroCompleted(CodeChannel channel, bool error)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Code channel of the finished macro |
bool | error | Whether an error occurred |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteMacroStarted(CodeChannel)
Notify RepRapFirmware that a macro file could be started
Declaration
public static bool WriteMacroStarted(CodeChannel channel)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Code channel that requires the lock |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteMessage(MessageTypeFlags, string)
Write a message
Declaration
public static bool WriteMessage(MessageTypeFlags flags, string message)
Parameters
Type | Name | Description |
---|---|---|
MessageTypeFlags | flags | Message flags |
string | message | Message content |
Returns
Type | Description |
---|---|
bool | Whether the firmware has been written successfully |
WriteOpenFileResult(uint, long)
Write the new file handle and file length of the file that has just been opened
Declaration
public static bool WriteOpenFileResult(uint fileHandle, long length)
Parameters
Type | Name | Description |
---|---|---|
uint | fileHandle | New file handle or noFileHandle if the file could not be opened |
long | length | Length of the file |
Returns
Type | Description |
---|---|
bool | If the packet could be written |
WritePrintFileInfo(GCodeFileInfo)
Notify the firmware that a file print has started
Declaration
public static bool WritePrintFileInfo(GCodeFileInfo info)
Parameters
Type | Name | Description |
---|---|---|
GCodeFileInfo | info | Information about the file being printed |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WritePrintStopped(PrintStoppedReason)
Notify that a file print has been stopped
Declaration
public static bool WritePrintStopped(PrintStoppedReason reason)
Parameters
Type | Name | Description |
---|---|---|
PrintStoppedReason | reason | Reason why the print has been stopped |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteReset()
Request a firmware reset
Declaration
public static bool WriteReset()
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteSetVariable(CodeChannel, bool, string, string)
Set a global or local variable
Declaration
public static bool WriteSetVariable(CodeChannel channel, bool createVariable, string varName, string expression)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | G-code channel |
bool | createVariable | Whether the variable should be created or updated |
string | varName | Name of the variable including global or var prefix |
string | expression | New value of the variable |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |
WriteUnlock(CodeChannel)
Release all acquired locks again
Declaration
public static bool WriteUnlock(CodeChannel channel)
Parameters
Type | Name | Description |
---|---|---|
CodeChannel | channel | Code channel that releases the locks |
Returns
Type | Description |
---|---|
bool | True if the packet could be written |