Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

CompactDaq AI with Visual Basic .NET

Does anyone have any code for doing analog input with CompactDAQ and VB.NET?  My SCXI code is returning ~-250 C on thermocouple readings.  If I reset the chassis with MAX and then read with MAX, I get normal readings.  If I try to run VB it won't work in either until I reset the chassis in MAX again.

This is the code I am using:

[vb]
            While ChannelCount < numChannels
                While AIChannels(ChannelCount).Device = Device
                    TasksChannelCount(TaskCount) += 1

                    With AIChannels(ChannelCount)
                        Select Case AIChannels(ChannelCount).Type
                            Case Is = "Temperature"
                                Tasks(TaskCount).AIChannels.CreateThermocoupleChannel(.Device & "/" & _
                                                .Channel, Trim(.Name), .Min, .Max, AIThermocoupleType.K, _
                                                AITemperatureUnits.DegreesC)
                                If Not .Device.Contains("cDAQ") Then
                                    Tasks(TaskCount).AIChannels(.Name).AutoZeroMode = AIAutoZeroMode.None
                                    Tasks(TaskCount).AIChannels(.Name).LowpassEnable = True
                                    Tasks(TaskCount).AIChannels(.Name).LowpassCutoffFrequency = 4
                                End If
                            Case Is = "Voltage"
                                Tasks(TaskCount).AIChannels.CreateVoltageChannel(.Device & "/" & .Channel, _
                                                .Name, AITerminalConfiguration.Differential, _
                                                .Min, .Max, AIVoltageUnits.Volts)
                                If Not .Device.Contains("cDAQ") Then
                                    Tasks(TaskCount).AIChannels(.Name).AutoZeroMode = AIAutoZeroMode.None
                                    Tasks(TaskCount).AIChannels(.Name).LowpassEnable = True
                                    Tasks(TaskCount).AIChannels(.Name).LowpassCutoffFrequency = 4
                                End If
                            Case Else
                                MsgBox("Error in channel configuration!", MsgBoxStyle.Critical, "Warning!")
                                frmD.txtMessage.Text = "Error in Channel Configuration.  Abort." & vbNewLine _
                                                        & frmD.txtMessage.Text
                                Exit Sub
                        End Select
                    End With
                    ChannelCount += 1

                End While

                Tasks(TaskCount).Timing.ConfigureSampleClock("", SampleRate, SampleClockActiveEdge.Rising, _
                                                             SampleQuantityMode.FiniteSamples, numSamples)
                Tasks(TaskCount).Control(TaskAction.Verify)
                Tasks(TaskCount).Control(TaskAction.Unreserve)

                reader(TaskCount) = New AnalogMultiChannelReader(Tasks(TaskCount).Stream)

                TaskCount += 1
                TasksChannelCount(TaskCount) = 0
                Device = AIChannels(ChannelCount).Device
            End While
[/vb]
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 115
(6,670 Views)
OK, I got it to read now, but I am having some speed issues.  It works very well using only one NI 9211.  On my SCXI applications I create one task per module, but that approach had problems on Compact DAQ.  I changed it to one task per chassis, and it is horribly slow now  I NEED to have these things update a chassis full of TC readings at 1 Hz (with some cushion time). 

What is the best approach for reading 8 modules full of TC readings on these 9211s? 
Why are they so slow?  (14 S/s)
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 2 of 115
(6,655 Views)
Thanks for posting to the NI forums.  What rate are you specifying for the acquisition?  Are you able to achieve 14 S/s on a single channel or only read 14 channels in a second?  If you increase the sampling rate do you get an error?  You should be able to achieve your desired sample rate of 1 Hz. Actually, if you scan at a higher rate the driver should still let you do so but samples will be repeated due to the long settling time of the 9211.  You should be able to scan at around 6 Hz without any repeated data.  Let me know if this does not resolved the issue.  Good luck with your application and have a happy holiday season.

Regards,

Neil S.
Applications Engineer
National Instruments
0 Kudos
Message 3 of 115
(6,639 Views)
I do not get errors when I request higher acquisition rates like I would for an E-series card.  I have requested rates from 14 to 500 and I still have trouble.  When I do one task per module, the first module behaves very oddly (every 5 or so seconds it reads correctly, but the other 4 readings are bad and it repeats the same pattern). When I do one task per chassis (1 chassis currently), I get no value for the first channel and my loop time is 3-4 seconds.  Will a single chassis return 2 real readings per second from 32 total channels?  Has anyone at NI tested these units using Measurement Studio and VB.NET?  Are there any plans for faster TC modules?

I think that I will write a program today to take one reading and throw all of the data into a table so I can set what it is returning and how long it is taking.

Thanks.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 4 of 115
(6,638 Views)
Michael,

The behavior you are seeing does seem odd indeed.  How many samples per channel are you acquiring on each iteration of the loop?  Could you post the code that you have contained in your loop?

Thanks,

Neil S.
Applications Engineer
National Instruments
0 Kudos
Message 5 of 115
(6,633 Views)
        For TaskCount = 0 To NumberOfModules - 1
            Tasks(TaskCount) = New Task("mod" & Trim(Str(TaskCount + 1)) & "task")
        Next

        Device = AIChannels(0).Device

        Try
            While ChannelCount < numChannels
                While AIChannels(ChannelCount).Device = Device
                    TasksChannelCount(TaskCount) += 1

                    With AIChannels(ChannelCount)
                        Select Case AIChannels(ChannelCount).Type
                            Case Is = "Temperature"
                                Tasks(TaskCount).AIChannels.CreateThermocoupleChannel(.Device & "/" & _
                                                .Channel, Trim(.Name), .Min, .Max, AIThermocoupleType.K, _
                                                AITemperatureUnits.DegreesC)
                                If Not .Device.Contains("cDAQ") Then
                                    Tasks(TaskCount).AIChannels(.Name).AutoZeroMode = AIAutoZeroMode.None
                                    Tasks(TaskCount).AIChannels(.Name).LowpassEnable = True
                                    Tasks(TaskCount).AIChannels(.Name).LowpassCutoffFrequency = 4
                                End If
                            Case Is = "Voltage"
                                Tasks(TaskCount).AIChannels.CreateVoltageChannel(.Device & "/" & .Channel, _
                                                .Name, AITerminalConfiguration.Differential, _
                                                .Min, .Max, AIVoltageUnits.Volts)
                                If Not .Device.Contains("cDAQ") Then
                                    Tasks(TaskCount).AIChannels(.Name).AutoZeroMode = AIAutoZeroMode.None
                                    Tasks(TaskCount).AIChannels(.Name).LowpassEnable = True
                                    Tasks(TaskCount).AIChannels(.Name).LowpassCutoffFrequency = 4
                                End If
                            Case Else
                                Removed to fit post
                                Exit Sub
                        End Select
                    End With
                    ChannelCount += 1
                    If ChannelCount = numChannels Then Exit While
                    If AIChannels(0).Device.Contains("cDAQ") Then
                        Device = AIChannels(ChannelCount).Device
                    End If
                End While
               
                Tasks(TaskCount).Timing.ConfigureSampleClock("", SampleRate, SampleClockActiveEdge.Rising, _
                                                             SampleQuantityMode.FiniteSamples, numSamples)
                Tasks(TaskCount).Control(TaskAction.Verify)
                Tasks(TaskCount).Control(TaskAction.Unreserve)
               
                reader(TaskCount) = New AnalogMultiChannelReader(Tasks(TaskCount).Stream)

                TaskCount += 1
                TasksChannelCount(TaskCount) = 0
                Device = AIChannels(ChannelCount).Device
            End While

Message Edited by SCXI and MS 2k3-VB.NET on 12-22-2006 12:44 PM

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 6 of 115
(6,635 Views)
Reading the data

                g = h = i = 0

                For Count = 0 To NumberOfModules - 1
                    Task1Data = reader(Count).ReadMultiSample(numSamples)
                    For h = i To i + TasksChannelCount(Count) - 1
                        sum(h) = 0
                    Next

                    For h = i To i + TasksChannelCount(Count) - 1
                        For g = 0 To numSamples - 1
                            sum(h) = sum(h) + Task1Data(h - i, g)
                        Next
                    Next

                    i = h
                Next

                For h = 0 To numChannels
                    With AIChannels(h)
                        average(h) = sum(h) / numSamples
                        value(h) = average(h) ^ 4 * .Quartic + _
                                   average(h) ^ 3 * .Cubic + _
                                   average(h) ^ 2 * .Quadratic + _
                                   average(h) * .Linear + _
                                   .Offset
                    End With
                Next
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 7 of 115
(6,629 Views)
Hi Michael,

You are experiencing very odd behavior and from looking at your code here, it has been difficult for us to determine what is wrong.  One suggestion I have is to use one task contianing your 8 thermocouple channels across the 8 devices instead of having 8 tasks each with one device, this may speed things up.

Also, did you have a chance to write a program to take one reading and throw all of the data into a table so we can see what it is returning and how long it is taking?

We have a shipping example located in the C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\DAQmx\Analog In\Measure Temperature\ContAcqThermocoupleSamples_IntClk\Vb folder.  This example has been tested and should work with the 9211 in reading Thermocouple channels.  Please take a look at it if you have not already.

If you are still having trouble getting the thermocouples to read properly, could you please attach all of your code, preferably in a .zip file contianing the project file and source files so we can run the code on our end?

Thanks for your patience Michael, I hope you are enjoying the holidays!

Regards,
Erik J.
Applications Engineer
National Instruments
0 Kudos
Message 8 of 115
(6,598 Views)
I will write the program to take readings and put them in a table tomorrow and after making a test run I will report back with my results.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 9 of 115
(6,596 Views)
Great!  Thanks Michael.  Your results should be interesting.  If you still have a 9211 speed issue after running your program, please post it you code so we can reproduce the results on our end.

Regards,
Erik J.
0 Kudos
Message 10 of 115
(6,585 Views)