54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using Sick.SafetyScanners.Helpers;
|
|
|
|
namespace Sick.SafetyScanners.Cola2.Commands;
|
|
|
|
/// <summary>
|
|
/// Command to make the scanner flash/blink to help locate it
|
|
/// </summary>
|
|
public sealed class FindMeCommand : MethodCommand
|
|
{
|
|
private readonly ushort _blinkTime;
|
|
|
|
public FindMeCommand(ushort blinkTime)
|
|
: base(14) // Method index for FindMe
|
|
{
|
|
_blinkTime = blinkTime;
|
|
}
|
|
|
|
public ushort BlinkTime => _blinkTime;
|
|
|
|
public override bool CanBeExecutedWithoutSessionId => true;
|
|
|
|
protected override ReadOnlyMemory<byte> AddTelegramData()
|
|
{
|
|
// Base method index (2 bytes) + blink time (2 bytes)
|
|
var data = new byte[2 + 2];
|
|
var span = data.AsSpan();
|
|
|
|
// Write base method index (from MethodCommand.AddTelegramData)
|
|
ReadWriteHelper.WriteUint16LittleEndian(span, 0, MethodIndex);
|
|
|
|
// Write blink time (offset 2, 2 bytes, little endian)
|
|
ReadWriteHelper.WriteUint16LittleEndian(span, 2, _blinkTime);
|
|
|
|
return data;
|
|
}
|
|
|
|
protected override bool ProcessReplyInternal(ReadOnlyMemory<byte> replyData,
|
|
byte replyCommandType, byte replyCommandMode)
|
|
{
|
|
// According to C++ reference, this inverts the result from base class
|
|
// Error response: 'E' (0x45) and 'I' (0x49)
|
|
if ((replyCommandType == 0x45 && replyCommandMode == 0x49) ||
|
|
(replyCommandType == 'E' && replyCommandMode == 'I'))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Success: 'A' (0x41) and 'I' (0x49)
|
|
return (replyCommandType == 0x41 && replyCommandMode == 0x49) ||
|
|
(replyCommandType == 'A' && replyCommandMode == 'I');
|
|
}
|
|
}
|
|
|