72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using DTS.Common.Enums.DASFactory;
|
|
using DTS.Common.ICommunication;
|
|
using DTS.Common.Utilities;
|
|
|
|
namespace DTS.DASLib.Command.SLICE.RealtimeCommands
|
|
{
|
|
public class RetrieveSingleSample : RealtimeCommandBase
|
|
{
|
|
protected override Commands _Command => Commands.RetrieveSingleSample;
|
|
|
|
public short[] _data;
|
|
public short GetChannelData(int zeroBasedChannel)
|
|
{
|
|
return _data[zeroBasedChannel];
|
|
}
|
|
|
|
public ushort Channels
|
|
{
|
|
get
|
|
{
|
|
if (null == _data) return 0;
|
|
return (ushort)_data.Length;
|
|
}
|
|
}
|
|
|
|
public RetrieveSingleSample(DTS.Common.Interface.DASFactory.ICommunication sock)
|
|
: base(sock)
|
|
{
|
|
}
|
|
|
|
public RetrieveSingleSample(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec)
|
|
: base(sock, timeoutMillisec)
|
|
{
|
|
}
|
|
|
|
protected override CommandReceiveAction WholePackage()
|
|
{
|
|
try
|
|
{
|
|
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
|
|
{
|
|
// Figure out the number of samples returned
|
|
var unsignedData = new ushort[response.Parameter.Length / 2];
|
|
_data = new short[response.Parameter.Length / 2];
|
|
for (var i = 0; i < response.Parameter.Length / 2; i++)
|
|
{
|
|
response.GetParameter(2 * i, out unsignedData[i]);
|
|
if (unsignedData[i] > 32768)
|
|
{
|
|
_data[i] = (short)(unsignedData[i] - 65536);
|
|
}
|
|
else
|
|
{
|
|
_data[i] = (short)unsignedData[i];
|
|
}
|
|
}
|
|
return CommandReceiveAction.StopReceiving;
|
|
}
|
|
}
|
|
catch { }
|
|
return CommandReceiveAction.StopReceiving;
|
|
}
|
|
|
|
public override void ResponseToString(ref List<List<string>> lines)
|
|
{
|
|
base.ResponseToString(ref lines);
|
|
lines.Add(new List<string> { $"Channels: {Channels}, Data: {ArrayToString.ArrayObjectToString(_data)}" });
|
|
}
|
|
}
|
|
}
|