private bool RunTask(InOutPortFlags flags) { if (flags.HasFlag(InOutPortFlags.UseInput)) { var result = NidaQmxHelper.DAQmxStartTask(_device.InputTaskHandle); if (result < 0) { NidaQmxHelper.DAQmxClearTask(_device.InputTaskHandle); _device.ReportError(new DeviceErrorArgs(NidaQmxHelper.GetError(result))); return(false); } } //if (flags.HasFlag(InOutPortFlags.UseOutput)) { // var result = NidaQmxHelper.DAQmxStartTask(_device.OutputTaskHandle); // if (result < 0) { // NidaQmxHelper.DAQmxStopTask(_device.InputTaskHandle); // NidaQmxHelper.DAQmxClearTask(_device.InputTaskHandle); // NidaQmxHelper.DAQmxClearTask(_device.OutputTaskHandle); // _device.ReportError(new DeviceErrorArgs(NidaQmxHelper.GetError(result))); // return false; // } //} return(true); }
public void DestroyTask() { if (TaskHandle != 0) //throw new InvalidOperationException("Task not yet created. First create a task"); { NidaQmxHelper.DAQmxClearTask(TaskHandle); TaskHandle = 0; } SamplesPerChannel = 0; _nodes.Clear(); State = SessionTaskState.None; }
private bool ConfigureDevClock(InOutPortFlags flags) { if (flags.HasFlag(InOutPortFlags.UseInput)) { var result = NidaQmxHelper.DAQmxCfgSampClkTiming( activeEdge: NidaQmxHelper.DaQmxValRising, sampleMode: NidaQmxHelper.DaQmxValContSamps, sampsPerChan: (ulong)_device.SamplesPerChannelInput, taskHandle: _device.InputTaskHandle, source: "", rate: _device.SamplerateInput ); if (result < 0) { NidaQmxHelper.DAQmxClearTask(_device.InputTaskHandle); _device.ReportError(new DeviceErrorArgs(NidaQmxHelper.GetError(result))); return(false); } } if (flags.HasFlag(InOutPortFlags.UseOutput)) { var result = NidaQmxHelper.DAQmxCfgSampClkTiming( activeEdge: NidaQmxHelper.DaQmxValRising, sampleMode: NidaQmxHelper.DaQmxValContSamps, sampsPerChan: (ulong)_device.SamplesPerChannelOutput, taskHandle: _device.OutputTaskHandle, source: "", rate: _device.SamplerateOutput ); if (result < 0) { NidaQmxHelper.DAQmxClearTask(_device.InputTaskHandle); NidaQmxHelper.DAQmxClearTask(_device.OutputTaskHandle); _device.ReportError(new DeviceErrorArgs(NidaQmxHelper.GetError(result))); return(false); } result = NidaQmxHelper.DAQmxCfgOutputBuffer(_device.OutputTaskHandle, _device.SamplesPerChannelOutput); if (result < 0) { NidaQmxHelper.DAQmxClearTask(_device.InputTaskHandle); NidaQmxHelper.DAQmxClearTask(_device.OutputTaskHandle); _device.ReportError(new DeviceErrorArgs(NidaQmxHelper.GetError(result))); return(false); } } return(true); }
private void CleanupAndThrow(int code) { NidaQmxHelper.DAQmxClearTask(TaskHandle); TaskHandle = 0; SamplesPerChannel = 0; _nodes.Clear(); State = SessionTaskState.None; if (_counter != null) { _counter.Dispose(); } throw new NidaqException(code); }
public void StopSampling() { if (!Recording) { return; } NidaQmx2Singleton.Instance.Stop(); NidaQmxHelper.DAQmxClearTask(InputTaskHandle); NidaQmxHelper.DAQmxClearTask(OutputTaskHandle); CreateTaskHandle(); Recording = false; }
public void DestroyTask() { if (TaskHandle == 0) { throw new InvalidOperationException("Task not yet created. First create a task"); } NidaQmxHelper.DAQmxClearTask(TaskHandle); TaskHandle = 0; SamplesPerChannel = 0; _nodes.Clear(); if (_counter != null) { _counter.Dispose(); } State = SessionTaskState.None; }
private void CleanupAndThrow(int code, bool doThrow = true) { NidaQmxHelper.DAQmxClearTask(TaskHandle); TaskHandle = 0; SamplesPerChannel = 0; _nodes.Clear(); State = SessionTaskState.None; if (doThrow) { throw new NidaqException(code); } else { Parent.SessionGraph.Context.Notify( new NodeSystemLib2.Generic.GraphNotification( NodeSystemLib2.Generic.GraphNotification.NotificationType.Error, NidaQmxHelper.GetError(code) ) ); } }
private bool CreateVirtualChannel(InOutPortFlags flags) { // ------------------------------------ if (flags.HasFlag(InOutPortFlags.UseInput)) { var inputs = _device.ListeningPorts.Where(port => port.Direction == ChannelDirection.Input) .Select(port => port.Name); if (inputs.Any()) { var inputPortStrings = string.Join(",", inputs); var result = NidaQmxHelper.DAQmxCreateAIVoltageChan( maxVal: 10.0, minVal: -10.0, units: NidaQmxHelper.DaQmxValVolts, terminalConfig: NidaQmxHelper.DaQmxValRse, physicalChannel: inputPortStrings, taskHandle: _device.InputTaskHandle, nameToAssignToChannel: "chanI" + _device.Name, customScaleName: null ); if (result < 0) { NidaQmxHelper.DAQmxClearTask(_device.InputTaskHandle); _device.ReportError(new DeviceErrorArgs(NidaQmxHelper.GetError(result))); return(false); } } } // ------------------------------------ if (flags.HasFlag(InOutPortFlags.UseOutput)) { var outputs = _device.ListeningPorts.Where(port => port.Direction == ChannelDirection.Output) .Select(port => port.Name); if (outputs.Any()) { var outputPortStrings = string.Join(",", outputs); var channelNumber = 0; foreach (var output in _device.ListeningPorts.Where(port => port.Direction == ChannelDirection.Output)) { ((NidaQmxChannelOutput)output).ChannelNumber = channelNumber++; } var result = NidaQmxHelper.DAQmxCreateAOVoltageChan( maxVal: 10.0, minVal: -10.0, units: NidaQmxHelper.DaQmxValVolts, physicalChannel: outputPortStrings, taskHandle: _device.OutputTaskHandle, nameToAssignToChannel: "chanO" + _device.Name, customScaleName: null ); if (result < 0) { NidaQmxHelper.DAQmxClearTask(_device.OutputTaskHandle); _device.ReportError(new DeviceErrorArgs(NidaQmxHelper.GetError(result))); return(false); } } } // ------------------------------------ return(true); }