I am making my first application with DAQmx and .NET and have an issue with setting sampling frequency.
The setup is
Rack: 9188
Slot1: 9237
Slot2: 9237
Slot3: 3201
Slot4: 9421
My idea was that all channels are set up as global channels in NI MAX. In this way a channel can be configured with the right custom scaling and test run in MAX.
The .NET program then creates a Task, and adds the right channels to it (the _channels object is just a container for all objects):
Dim analogTask As New DAQmx.Task _channels.analogTask = analogTask _channels.LoadChannel = analogTask.AddGlobalChannel(config.loadChannelName) _channels.TorqueChannel = analogTask.AddGlobalChannel(config.torqueChannelName) _channels.TransverseForceChannel = analogTask.AddGlobalChannel(config.transversalForceChannelName) _channels.TransversePosChannel = analogTask.AddGlobalChannel(config.transversalPosChannelName)
LoadChannel, TorqueChannel and TransverseForceChannel are Bridge type channels with custom scaling. The TransversePosChannel is Voltage type, also with custom scaling.
The sample clock is then configured and task is verified:
analogTask.Timing.ConfigureSampleClock(String.Empty, config.frequencyHz, _ DAQmx.SampleClockActiveEdge.Rising, DAQmx.SampleQuantityMode.ContinuousSamples, config.frequencyHz)
analogTask.Control(DAQmx.TaskAction.Verify)
I then create an AnalogMultiChannelReader and a callback. NUM_SAMPLES_PER_READ is 500.
_analogReader = New DAQmx.AnalogMultiChannelReader(_analogTask.Stream) _analogCallback = New AsyncCallback(AddressOf AnalogInCallback)
_analogReader.SynchronizeCallbacks = True _runAnalogSampling = True _analogReader.BeginReadWaveform(NUM_SAMPLES_PER_READ, _analogCallback, _analogTask)
The callback looks something like this:
Private Sub AnalogInCallback(ByVal ar As IAsyncResult) Try Dim timeLoadData() As measuredData If ar.AsyncState Is _analogTask Then _daqData = _analogReader.EndReadWaveform(ar) ... ... ...
... ... ... beginAnalogRead() End If Catch ex As Exception Try stopAllTasks() Finally RaiseEvent ErrorOccurred(Me, "DAQChannels.AnalogInCallback: " & ex.Message) End Try End Try End Sub
The issue is that the sampling frequency seems to be about 1.6 kHz no matter what I set in the ConfigureSampleClock call.
I have verified that 500 samples are returned at each call to the AnalogInCallback, but it is always called about three times / sec no matter what freqyency I have set.
I might have missed something obvious, but right now I am kind of stuck so I'd really appreciate your help here.