Initial commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user