private void ProcessInputData(IReadOnlyList <INidaqMetric> listeningPorts, NILoop.HandleInfo taskInfo, IntPtr buffer, int sample_size_bytes, int hPoll) { var result = NILoop.read_buffer(hPoll, taskInfo.handle, buffer, sample_size_bytes * (taskInfo.samples_per_chan * listeningPorts.Count)); switch (result) { case 3: case 1: // task not found SessionGraph.AsyncEmergencyStop(null); _stopThread = true; break; case 2: // queue empty, ignore Thread.Sleep(1); break; case 0: var channelData = buffer; foreach (var port in listeningPorts) { ((IMetricInput)port).DistributeData(channelData, taskInfo.samples_per_chan); channelData = IntPtr.Add(channelData, sample_size_bytes * taskInfo.samples_per_chan); } break; default: // read error System.Diagnostics.Debug.WriteLine(NidaQmxHelper.GetError(result)); SessionGraph.AsyncEmergencyStop(null); _stopThread = true; break; } }
public NidaqException(int code) : base(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); }