public AnalogWaveformCollection <double> Sample() { AnalogWaveformCollection <double> waveforms = null; ScopeSession.Measurement.Initiate(); waveforms = ScopeSession.Channels[_channelList].Measurement.FetchDouble(PrecisionTimeSpan.FromSeconds(-1), _recordLengthMin, waveforms); return(waveforms); }
public static void SaveBinaryWaveform(FileStream outputFileStream, AnalogWaveformCollection <double> waveforms) { try { new BinaryFormatter().Serialize(outputFileStream, waveforms); Console.WriteLine("Successfully saved acquired data to \"" + outputFileStream.Name + "\""); } catch (SecurityException ex) { Console.WriteLine("Unable to serialize the data: "); } catch (SerializationException ex) { Console.WriteLine("Unable to serialize the data: "); } finally { outputFileStream.Close(); } }
public static MeasurementResults MeasureChannel(NIScope scope, string channelName = "0") { MeasurementResults results = new MeasurementResults(); scope.Measurement.Initiate(); AnalogWaveformCollection <double> resultWaveform = new AnalogWaveformCollection <double>(); resultWaveform = scope.Channels[channelName].Measurement.FetchDouble(PrecisionTimeSpan.FromSeconds(5), -1, null); results.ResultsTrace = resultWaveform[0].GetRawData(); results.AverageValue_V = scope.Channels[channelName].Measurement.FetchScalarMeasurement(PrecisionTimeSpan.FromSeconds(5), ScopeScalarMeasurementType.VoltageAverage)[0]; scope.Measurement.Abort(); return(results); }
public void ArmAndWait() { lock (this) { try { //waveforms = scopeSession.Channels[channelName].Measurement.Read(timeout, recordLength, waveforms); waveforms = scopeSession.Channels[channelName].Measurement.FetchDouble(timeout, recordLength, waveforms, out waveformInfo); scopeSession.Measurement.Initiate(); } catch (Exception ex) { ShowError(ex); } } }
//读数据 private void readData(NIScope scopeSession) { //var channels = ((JArray)_staticConfig.ChannelConfig.ChannelName).ToObject<List<int>>(); var channels = ChannelNameTranslator.StringToListInt(_staticConfig.ChannelConfig.ChannelName); //开新线程等待读数据 //await Task.Run(() => //{ int totalReadDataLength = 0; PrecisionTimeSpan timeout = new PrecisionTimeSpan(1000000); //无timeOut AnalogWaveformCollection <double> scopeWaveform = null; double[,] readData = new double[_staticConfig.ChannelCount, _staticConfig.ClockConfig.TotalSampleLengthPerChannel]; //生成 channels string channelScope = null; //var sChannels = ((JArray)_staticConfig.ChannelConfig.ChannelName).ToObject<List<int>>(); var sChannels = ChannelNameTranslator.StringToListInt(_staticConfig.ChannelConfig.ChannelName); foreach (var s in sChannels) { channelScope += s + ","; } channelScope = channelScope.Substring(0, channelScope.Length - 1); //一次采完 //经过测试,发现在默认设置(不设置其它)情况下: // 1、如果多次 FetchDouble,则每 2 次的数据不连续(中间断一截) // 2、如果设置多个 records,则每 2 个 record 之间的数据不连续(中间断一截) //因此暂时只允许一个 record scopeWaveform = scopeSession.Channels[channelScope].Measurement.FetchDouble(timeout, _staticConfig.ClockConfig.TotalSampleLengthPerChannel, scopeWaveform); //一旦上面这里获取到数据,则表示采集开始 AIState = Status.Running; // i 是读取次数 // j 是通道计数 // k 是每一波的每个点 double[] temp; AnalogWaveform <double> waveform; for (int i = 0; i < _staticConfig.ClockConfig.TotalSampleLengthPerChannel / _staticConfig.ClockConfig.ReadSamplePerTime; i++) { //将一个通道的数据拷贝到 data[,] 的一行 for (int j = 0; j < _staticConfig.ChannelCount; j++) { waveform = scopeWaveform[i, j]; temp = waveform.GetRawData(); for (int k = 0; k < _staticConfig.ClockConfig.ReadSamplePerTime; k++) { readData[j, i *_staticConfig.ClockConfig.ReadSamplePerTime + k] = temp[k]; } } totalReadDataLength += _staticConfig.ClockConfig.ReadSamplePerTime; } GC.Collect(); Thread.Sleep(2000); //发布数据到达事件 OnDataArrival(readData); //发布停止任务事件 OnAITaskStopped(); //等待,让外部保证获取到 Running 状态 Thread.Sleep(2000); //}); }