From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

6323 PCIe board, using c# to read two analog inputs, question

Hi NI Community,

Not sure if this is the right place to start.  But, someone must have had a similar issue.

 

We are using C# to talk to our NI 6323 board.  

We have two analog inputs that need to be read.  (No problem setting that up.)

Here  are the inputs:

static private Task SensorInput;   //needs to be read 10,000 per second

static private Task InputVoltage;    //needs input every 2 seconds

 

reader = new AnalogMultiChannelReader(SensorInput.Stream);
data = reader.ReadWaveform(10,000);

 

Trouble is we need the "InputVoltage" to be read every two seconds and it sometimes gets "locked out" by the 10,000 samples per second stream going on for the "SensorInput"

 

Is there a way to raise the "priority" of the InputVoltage task so that it always reads a value.  Often we only get the exception NationalInstruments.DAQmx.DaqException: The specified resource is reserved. The operation could not be completed as specified.

 

Brian

 

 

 

0 Kudos
Message 1 of 5
(3,330 Views)

Hello,

 

What exactly do you mean by being locked out? How are you architecting the system for it to read?

 

Generally, there is not a way to set a priority to be higher than another. What you can do, however, is set up the task to be hardware timed before starting the task. Then, what you can do is have a loop that does not wait for necessaryily 10,000 samples to come in, but instead just set each task to read "-1" samples, which reads all that are available. This will allow the tasks to never stop to wait, and the code will continue to flow.

 

Best,

 

Shamik C

Applications Engineer 

National Instruments 

http://www.ni.com/support 

0 Kudos
Message 2 of 5
(3,297 Views)

To be more precise, the two tasks are run on separate threads, one fires every 1 second and reads 10,000 samples (and averages them), the other reads every 2 seconds and read 10 samples (and averages them)

The thread reading every two seconds encounters an exception thrown by daqmx (resource is unavailable) because of the 10,000 sample per second task hogging access to the board.

 

What you're suggesting is read them in the same thread, I assume.  

 

Please provide a c# code snippet for setting "hardware timing".

0 Kudos
Message 3 of 5
(3,295 Views)

When you set up the tasks, you can configure the timing similar to below.

 

 // Create a new task
                    myTask = new Task();

                    // Create a virtual channel
                    myTask.AIChannels.CreateVoltageChannel(physicalChannelComboBox.Text, "",
                        (AITerminalConfiguration)(-1), Convert.ToDouble(minimumValueNumeric.Value),
                        Convert.ToDouble(maximumValueNumeric.Value), AIVoltageUnits.Volts);

                    // Configure the timing parameters
                    myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(rateNumeric.Value),
                        SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);

                    // Verify the Task
                    myTask.Control(TaskAction.Verify);

                    myTask.Stream.

What exception is being thrown? Could you possibly send a screenshot?

 

 

0 Kudos
Message 4 of 5
(3,280 Views)

This is the exception:

 

10/22/2016 12:54:57:6859 Error: Input Averaging Ex:   NationalInstruments.DAQmx.DaqException: The specified resource is reserved. The operation could not be completed as specified.

Task Name: _unnamedTask<C>

Status Code: -50103
at nNIMSSAIL100.StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100:: DotNetApi> >.CheckWithName(StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100:: DotNetApi> >* , tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* pName)
at nNINETAI2005100.ReadAnlWfmGeneric(Task task, Int32 samplesPerChannel, Double timeout, WaveformAttributeModes mode)
at NationalInstruments.DAQmx.Internal.AnalogMultiChannelReaderImpl.ReadWaveformGeneric(Int32 samplesPerChannel)
at NationalInstruments.DAQmx.AnalogMultiChannelReader.ReadWaveform(Int32 samplesPerChannel)
at WindowsFormsApplication5.Form1.InputAveraging() in C:\DEV\Test1011\trunk\Form1.cs:line 6844

 

 

0 Kudos
Message 5 of 5
(3,277 Views)