Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

CompactDaq AI with Visual Basic .NET

I thought I had to run one task per module on SCXI.  This is how I have been doing it with FiniteSamples for over a year.  Now I am running ContinuousSamples.  Should I make only one task?
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 101 of 115
(1,533 Views)
Michael,

Like the cDAQ chassis, there's only one analog input timing engine available on your E Series/M Series device.  In this case, there's also only one ADC, which is multiplexed between different modules.  So, a second task can only start after the first one ends, or else there's a conflict for the same resource (the ADC).  You should definitely be able to put channels from all modules in a chassis in the same task.

My theory (DISCLAIMER: hardware guy making claims about software) is that your original problem started and stopped your finite acquisitions quickly and they ran in sequence on your SCXI chassis.  Because of higher USB latency, this performed poorly on cDAQ.  The changes we made to your code to get cDAQ working broke your original setup, and require you to change to one task there also.  Once we get everything sorted out, I think the new code will be more predictable and reliably timed.

Regards,
Kyle
0 Kudos
Message 102 of 115
(1,537 Views)
Right on.

Once again, NI's customer support sees a problem through.  You guys are astounding.

Thank you.

Michael
SwRI
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 103 of 115
(1,533 Views)
I do have one more question, however.  Each time I increase the number of modules I get an error that makes me reduce my sample rate.  I'm down to 1000 S/s now.  Will it sample each channel at 1000 S/s, or is that the total sample rate now?  How is this calculated within the drivers to give me an allowable value that keeps decreasing?  Function of number of channels? number of modules? obviously the PCI board itself...
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 104 of 115
(1,529 Views)
Michael,

That's the sampling rate for every channel in the system, and it's limited by the multiplexer rate (the slower of the multiplexer on your PCI board and your SCXI system), and settling time performance of the PCI board.

Example for a 250 kS/s board:

1 channel -> 250 kS/s sampling rate
10 channels -> 25 kS/s sampling rate

Same aggregate data points taken either way, just spread out among more channels.

Regards,
Kyle
0 Kudos
Message 105 of 115
(1,525 Views)
I am trying to use this callback stuff for counters now.  I am using a 1 Hz trigger on a counter channel and it isn't passing the If runningTask(TaskNumber) Is ar.AsyncState Then
statement.  Any ideas?

Creating the counter:

    Public CtrCallback As AsyncCallback = New AsyncCallback(AddressOf CounterReadCallback)

        If DIChannelCount > 0 Then
            Try
                For cnt = 0 To DIChannelCount - 1
                    Tasks(14 + cnt) = New Task("Counter" & cnt)
                    With DIChannels(cnt)
                        Tasks(14 + cnt).CIChannels.CreateCountEdgesChannel(.Device & "/" & .Channel, "Count Edges", _
                        CICountEdgesActiveEdge.Rising, Convert.ToInt64(0), CICountEdgesCountDirection.Up)
                        Tasks(14 + cnt).Timing.ConfigureSampleClock(.Device & "/" & .Trigger, 1, SampleClockActiveEdge.Rising, _
                                SampleQuantityMode.ContinuousSamples, 1)
                    End With
                    runningTask(cnt) = Tasks(14 + cnt)
                    myCICounterReader(cnt) = New CounterReader(Tasks(14 + cnt).Stream)
                    myCICounterReader(cnt).SynchronizeCallbacks = True
                    myCICounterReader(cnt).BeginReadSingleSampleUInt32(CtrCallback, cnt)
                Next
            Catch exception As DaqException
                MsgBox("Counters" & vbNewLine & exception.Message)
                'Tasks(15).Dispose()
            End Try
        End If

Async Function

    Public Sub CounterReadCallback(ByVal ar As IAsyncResult)
        Dim TaskNumber As Byte
        TaskNumber = CType(ar.AsyncState, Integer)

        Try
            If runningTask(TaskNumber) Is ar.AsyncState Then
                Select Case TaskNumber
                    Case Is = 0
                        CTR1 = myCICounterReader(TaskNumber).EndReadSingleSampleUInt32(ar)
                    Case Is = 1
                        CTR2 = myCICounterReader(TaskNumber).EndReadSingleSampleUInt32(ar)
                End Select

                myCICounterReader(TaskNumber).BeginReadSingleSampleUInt32(CtrCallback, TaskNumber)
                pubString = TaskNumber & vbTab & CTR1
            Else
                pubString = TaskNumber & vbTab & "Not Asyncstate"
            End If
        Catch exception As DaqException
            Tasks(14 + TaskNumber).Dispose()
            MessageBox.Show(exception.Message)
            runningTask(TaskNumber) = Nothing
        End Try
    End Sub
End Module

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 106 of 115
(1,342 Views)
Hi Michael,

This is the first time I have looked into this issue. 

Looking at your code you have a 1 hz trigger, and it appears you are using this as your sample clock terminal.

Tasks(14 + cnt).Timing.ConfigureSampleClock(.Device & "/" & .Trigger, 1, SampleClockActiveEdge.Rising, _
                                SampleQuantityMode.ContinuousSamples, 1)

You have a 1 there, which I assume means you want to count at a rate of 1 hz?.

From what I can tell the way you have eveyrthing setup your problem will come from there not actually being a clock on the sample clock terminal you have defined for the counter.  When you say it doesn't pass the If runningTask,  does it ever timeout, or does it just sit there till you stop the execution? 

I think if I understand more clearly the nature of what the 1hz trigger is, and what you want the overall counter application to do I will be able to help you get this issue resolved.  For future reference what version of DAQmx are you using, and what board is the this counter on?

Have a great day,

Michael D
Applications Engineering
National Instruments
0 Kudos
Message 107 of 115
(1,321 Views)
I am using a PCI-6713.
I want to sample the clock each second.
I am using CTR1OUT to provide a 1 Hz signal to CTR0GATE. - This signal has been verified with o-scope.
I am using a function generator to provide a 1 kHz signal to CTR0SOURCE. - This signal has been verified with o-scope.
I did get a timeout before I provided the 1 Hz clock, but I no longer get timeouts.

I have placed flags in the async callback function and "If runningTask(TaskNumber) Is ar.AsyncState Then" is never returning True. 

"TaskNumber = CType(ar.AsyncState, Integer)" returns 0 because I am only using one of the two counters right now, so TaskNumber is 0.

I am using the latest version of the DAQ drivers, Measurement Studio 8.1 Enterprise, and Visual Studio 2005.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 108 of 115
(1,316 Views)
Why exactly does the example program make a copy of the Task and use it in the asyn callback reader?

Can you explain this statement?

If runningTask(TaskNumber) Is ar.AsyncState Then

ar.AsyncState.toString is 0, runningTask(TaskNumber).toString is "Task"
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 109 of 115
(1,313 Views)

Hi Michael, Guys.

I have been following this thread and i wish to say you guys heve done a great job in achieving your set objectives and am sure lots of other forum user will definitely benefit from your analytical and thoughtful discussion.

But one question i have is, can this codes work with a PCI-6023E card? Please i will like to know if instead of using it to read Temperature, how can i use it to read  the volume of 10 different tanks and have the outputs stored in a MS Access table  and also have the result displayed on Textboxes every second interval.

Thanks

Charlion

0 Kudos
Message 110 of 115
(1,308 Views)