Initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Sick.Tim781s.Colab.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Command to write a value to the scanner (sWN - Write by Name)
|
||||
/// </summary>
|
||||
public sealed class WriteCommand : CommandBase
|
||||
{
|
||||
public WriteCommand(string variableName, string value)
|
||||
: base($"sWN {variableName} {value}")
|
||||
{
|
||||
VariableName = variableName;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string VariableName { get; }
|
||||
public string Value { get; }
|
||||
|
||||
public override bool ProcessReply(ReadOnlyMemory<byte> replyData)
|
||||
{
|
||||
// Parse reply: "sWA <variableName>" (Write Acknowledge), "sEA <eventName> <value>" (Event Acknowledge), "sAN <methodName> <result>" (Answer), or "sFA <errorCode>" (Error)
|
||||
var replyString = Encoding.ASCII.GetString(replyData.Span);
|
||||
|
||||
// Check if reply starts with "sFA" (Error) - this indicates command failed
|
||||
if (replyString.StartsWith("sFA", StringComparison.Ordinal))
|
||||
{
|
||||
WasSuccessful = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if reply starts with "sWA" (Write Acknowledge), "sEA" (Event Acknowledge), or "sAN" (Answer)
|
||||
if (replyString.StartsWith("sWA", StringComparison.Ordinal) ||
|
||||
replyString.StartsWith("sEA", StringComparison.Ordinal) ||
|
||||
replyString.StartsWith("sAN", StringComparison.Ordinal))
|
||||
{
|
||||
WasSuccessful = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
WasSuccessful = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user