Ejemplo n.º 1
0
        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);
        }