public void RunDAQ() { DigitalEdgeStartTriggerEdge triggerEdge = DigitalEdgeStartTriggerEdge.Rising; try { string s = string.Empty; s = _name == "/ai1" ? "etalon" : "measured"; inputTask = new NationalInstruments.DAQmx.Task(s); outputTask = new NationalInstruments.DAQmx.Task(s + "_output"); inputTask.AIChannels.CreateVoltageChannel(sInputName, "", AITerminalConfiguration.Pseudodifferential, inputDAQMinValue, inputDAQMaxValue, AIVoltageUnits.Volts); outputTask.AOChannels.CreateVoltageChannel(sOutputName, "", outputDAQMinValue, outputDAQMaxValue, AOVoltageUnits.Volts); inputTask.Timing.ConfigureSampleClock("", dRateIO, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, iInputOutputSamples); outputTask.Timing.ConfigureSampleClock("", dRateIO, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, iInputOutputSamples); outputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(terminalNameBase + "ai/StartTrigger", triggerEdge); inputTask.Control(TaskAction.Verify); outputTask.Control(TaskAction.Verify); outputData = fGen.Data; writer = new AnalogSingleChannelWriter(outputTask.Stream); writer.WriteMultiSample(false, outputData); StartTask(); outputTask.Start(); inputTask.Start(); //inputCallback = new AsyncCallback(InputReady); reader = new AnalogSingleChannelReader(inputTask.Stream); //------------ТЕСТОВЫЙ КУСОК------------ ЧТЕНИЕ В ЭТОМ ЖЕ ПОТОКЕ-- double[] data = reader.ReadMultiSample(iInputOutputSamples); BufReadDAQReceived?.Invoke(data); StopTask(); //---------------------------------------------------------------- /*// Use SynchronizeCallbacks to specify that the object * // marshals callbacks across threads appropriately. * reader.SynchronizeCallbacks = bSynchronizeCallbacks; * * reader.BeginReadMultiSample(iInputOutputSamples, inputCallback, inputTask);*/ } catch (Exception ex) { StopTask(); WarningDAQUpdate?.Invoke(ex.Message); } }
/// <summary> /// Включение постоянной генерации сигнала. Чтение и контроль ошибок при этом производится в CALLBACK. Для завершения генерации используй метод StopDAQGeneration() /// </summary> public void RunDAQGeneration() { DigitalEdgeStartTriggerEdge triggerEdge = DigitalEdgeStartTriggerEdge.Rising; try { string s = string.Empty; s = _name == "/ai1" ? "etalon" : "measured"; inputTask = new NationalInstruments.DAQmx.Task(s); outputTask = new NationalInstruments.DAQmx.Task(s + "_output"); inputTask.AIChannels.CreateVoltageChannel(sInputName, "", AITerminalConfiguration.Pseudodifferential, inputDAQMinValue, inputDAQMaxValue, AIVoltageUnits.Volts); outputTask.AOChannels.CreateVoltageChannel(sOutputName, "", outputDAQMinValue, outputDAQMaxValue, AOVoltageUnits.Volts); inputTask.Timing.ConfigureSampleClock("", dRateIO, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, iInputOutputSamples); outputTask.Timing.ConfigureSampleClock("", dRateIO, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, iInputOutputSamples); outputTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(terminalNameBase + "ai/StartTrigger", triggerEdge); inputTask.Control(TaskAction.Verify); outputTask.Control(TaskAction.Verify); outputData = fGen.Data; writer = new AnalogSingleChannelWriter(outputTask.Stream); writer.WriteMultiSample(false, outputData); StartTask(); outputTask.Start(); //inputTask.Start(); inputCallback = new AsyncCallback(AnalogInCallback); reader = new AnalogSingleChannelReader(inputTask.Stream); reader.SynchronizeCallbacks = true; //reader.BeginReadMultiSample(iInputOutputSamples, inputCallback, inputTask); reader.BeginReadWaveform(iInputOutputSamples, inputCallback, inputTask); //statusDAQtimer.Enabled = true; } catch (Exception ex) { StopTask(); WarningDAQUpdate?.Invoke(ex.Message); } }
void StopTask() { try { runningTask = null; inputTask.Stop(); outputTask.Stop(); inputTask.Dispose(); outputTask.Dispose(); } catch (Exception ex) { WarningDAQUpdate?.Invoke(ex.Message); } //Dispose(); }
private void InputReady(IAsyncResult ar) { try { if (runningTask != null && runningTask == ar.AsyncState) { double[] data = reader.EndReadMultiSample(ar); // Читаем данные BufReadDAQReceived?.Invoke(data); // Инициируем событие и передаем буфер в обработчик StopTask(); } } catch (Exception ex) { StopTask(); WarningDAQUpdate?.Invoke(ex.Message); } }
private void AnalogInCallback(IAsyncResult ar) { try { if (runningTask != null && runningTask == ar.AsyncState) { data = reader.EndReadWaveform(ar); //data.Samples BufReadDAQReceived(data.GetRawData()); reader.BeginMemoryOptimizedReadWaveform(iInputOutputSamples, inputCallback, inputTask, data); } } catch (DaqException ex) { WarningDAQUpdate?.Invoke(ex.Message); StopTask(); } }
string GetDAQDeviceName(string deviceName) { try { Device device = DaqSystem.Local.LoadDevice(deviceName); if (device.BusType != DeviceBusType.CompactDaq) { return(deviceName); } else { return(device.CompactDaqChassisDeviceName); } } catch (DaqException ex) { WarningDAQUpdate?.Invoke(ex.Message); return(null); } }
private void StatusDAQtimer_Tick(object sender, EventArgs e) { try { double[] data = reader.ReadMultiSample(iInputOutputSamples); BufReadDAQReceived?.Invoke(data); if (outputTask.IsDone) { statusDAQtimer.Enabled = false; StopTask(); } } catch (DaqException ex) { statusDAQtimer.Enabled = false; WarningDAQUpdate?.Invoke(ex.Message); StopTask(); } }