47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using Sick.SafetyScanners.Helpers;
|
|
|
|
namespace Sick.SafetyScanners.Cola2.Commands;
|
|
|
|
/// <summary>
|
|
/// Command to read a variable from the sensor by index
|
|
/// </summary>
|
|
public sealed class VariableCommand : CommandBase
|
|
{
|
|
private readonly ushort _variableIndex;
|
|
|
|
public VariableCommand(ushort variableIndex)
|
|
: base(0x52, 0x49) // 'R' and 'I' in ASCII (Read by Index)
|
|
{
|
|
_variableIndex = variableIndex;
|
|
}
|
|
|
|
public ushort VariableIndex => _variableIndex;
|
|
|
|
public override bool CanBeExecutedWithoutSessionId => false;
|
|
|
|
protected override ReadOnlyMemory<byte> AddTelegramData()
|
|
{
|
|
var data = new byte[2];
|
|
var span = data.AsSpan();
|
|
|
|
// Variable index (2 bytes, little endian)
|
|
ReadWriteHelper.WriteUint16LittleEndian(span, 0, _variableIndex);
|
|
|
|
return data;
|
|
}
|
|
|
|
protected override bool ProcessReplyInternal(ReadOnlyMemory<byte> replyData,
|
|
byte replyCommandType, byte replyCommandMode)
|
|
{
|
|
// Reply should be 'R' (0x52) and 'A' (0x41) for Acknowledge
|
|
if ((replyCommandType == 0x52 && replyCommandMode == 0x41) ||
|
|
(replyCommandType == 'R' && replyCommandMode == 'A'))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|