Files
DP44/DataPRO/SLICECommands/.svn/pristine/2a/2a1656f37a9d7768157159baaf471491c337c6d5.svn-base
2026-04-17 14:55:32 -04:00

71 lines
2.6 KiB
Plaintext

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Interface.DASFactory;
namespace DTS.DASLib.Command.SLICE.RealtimeCommands
{
public class GetRealtimeSamplesTSRAIR : GetRealtimeSamples
{
public GetRealtimeSamplesTSRAIR(ICommunication sock)
: base(sock) { }
public GetRealtimeSamplesTSRAIR(ICommunication sock, int TimeoutMillisec)
: base(sock, TimeoutMillisec) { }
protected List<UInt64> _timestamps;
public List<UInt64> Timestamps => _timestamps;
protected override CommandReceiveAction WholePackage()
{
try
{
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
{
// Figure out the number of samples returned
int samples_returned = (response.ParameterLength - 8) / (_channels * 2);
_samplesReturned = samples_returned;
int data_bytes_returned = samples_returned * _channels * 2;
_data = new List<short[]>(_channels);
// Grab the sample number
if (response.ParameterLength > 0)
{
response.GetParameter(0, out _sampleNumber);
}
// Create the data arrays by channel
for (int i = 0; i < _channels; i++)
{
_data.Add(new short[samples_returned]);
}
// Grab the data
int parameter = 8;
for (int sample = 0; sample < samples_returned; sample++)
{
for (int channel = 0; channel < _channels; channel++)
{
response.GetParameter(parameter, out ushort uval);
//TSRAIR data is unsigned data. Convert sign, no need to normalize
_data[channel][sample] = (short)((((uval & 0x00FF) << 8) | ((uval >> 8) & 0x00FF)));
parameter += 2;
}
}
return CommandReceiveAction.StopReceiving;
}
}
catch
{
_samplesReturned = 0;
}
return CommandReceiveAction.StopReceiving;
}
}
}