using System.Collections.Generic; using DTS.Common.Enums.DASFactory; using DTS.Common.ICommunication; namespace DTS.DASLib.Command.SLICE.RealtimeCommands { public class GetRealtimeSamplesSLICE2 : GetRealtimeSamples { public GetRealtimeSamplesSLICE2(DTS.Common.Interface.DASFactory.ICommunication sock) : base(sock) { LogCommands = false; } public GetRealtimeSamplesSLICE2(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec) : base(sock, timeoutMillisec) { LogCommands = false; } protected override CommandReceiveAction WholePackage() { try { if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError) { // Figure out the number of samples returned var samplesReturned = (response.ParameterLength - 8) / (_channels * 2); _samplesReturned = samplesReturned; _data = new List(_channels); // Grab the sample number if (response.ParameterLength > 0) { response.GetParameter(0, out _sampleNumber); } // Create the data arrays by channel for (var i = 0; i < _channels; i++) { _data.Add(new short[samplesReturned]); } // Grab the data var parameter = 8; for (var sample = 0; sample < samplesReturned; sample++) { for (var channel = 0; channel < _channels; channel++) { response.GetParameter(parameter, out ushort val); //changed from unsigned to signed _data[channel][sample] = (short)((((val & 0x00FF) << 8) | ((val >> 8) & 0x00FF)) + 0x8000); parameter += 2; } } return CommandReceiveAction.StopReceiving; } } catch { _samplesReturned = 0; } return CommandReceiveAction.StopReceiving; } } }