48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using Sick.SafetyScanners.Helpers;
|
|
|
|
namespace Sick.SafetyScanners.Cola2.Commands;
|
|
|
|
/// <summary>
|
|
/// Base command for method calls to the sensor
|
|
/// Thread-safe implementation
|
|
/// </summary>
|
|
public abstract class MethodCommand : CommandBase
|
|
{
|
|
private readonly ushort _methodIndex;
|
|
|
|
protected MethodCommand(ushort methodIndex)
|
|
: base(0x4D, 0x49) // 'M' and 'I' in ASCII (Method by Index)
|
|
{
|
|
_methodIndex = methodIndex;
|
|
}
|
|
|
|
public ushort MethodIndex => _methodIndex;
|
|
|
|
public override bool CanBeExecutedWithoutSessionId => false;
|
|
|
|
protected override ReadOnlyMemory<byte> AddTelegramData()
|
|
{
|
|
var data = new byte[2];
|
|
var span = data.AsSpan();
|
|
|
|
// Method index (2 bytes, little endian)
|
|
ReadWriteHelper.WriteUint16LittleEndian(span, 0, _methodIndex);
|
|
|
|
return data;
|
|
}
|
|
|
|
protected override bool ProcessReplyInternal(ReadOnlyMemory<byte> replyData,
|
|
byte replyCommandType, byte replyCommandMode)
|
|
{
|
|
// Reply should be 'A' (0x41) and 'I' (0x49) for Acknowledge
|
|
if ((replyCommandType == 0x41 && replyCommandMode == 0x49) ||
|
|
(replyCommandType == 'A' && replyCommandMode == 'I'))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|