Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

using AnalogMultiChannelReader to fill dynamically generated TextBox's

Solved!
Go to solution

I have adapted the C# NationalInstruments.Examples.TdmsContAcqVoltageSamples_IntClk pre-packaged example.  I am dynamically creating TextBoxes, rather than using the original DataGridView.  I found the example program worked for what i needed, the form filled in and updated continuously with my IO.  I found the DataGridView hard to configure, so I switched to the TextBoxes.  Below is a portion of the adapted code where i create the TextBoxes and try to populate them with the continuously streamed data.  I'm definitely not defining the datatype correctly for analogDataIn, and i'm not sure how to index into the channels using the AnalogMultiChannelReader method.  Here's the code.

 

public void InitializeDataTable(AIChannelCollection channelCollection)
        {
            int numOfChannels = channelCollection.Count;
            TextBox[] channelNames = new TextBox[numOfChannels];
            GroupBox channelBox = new GroupBox();
            Label[] labelNames = new Label[numOfChannels];
            //****************IN QUESTION**********************
AnalogMultiChannelReader reader = new AnalogMultiChannelReader(runningTask.Stream); double[,] analogDataIn = null;
//************************************************* for (int currentChannelIndex = 0; currentChannelIndex < numOfChannels; currentChannelIndex++) { //*************IN QUESTION******************** analogDataIn = reader.ReadMultiSample(-1);
//******************************************** var txt = new TextBox(); channelNames[currentChannelIndex] = txt; txt.Name = channelCollection[currentChannelIndex].PhysicalName; txt.Text = analogDataIn.ToString(); txt.Size = new Size(150, 20); txt.Location = new Point(200, 32 + (currentChannelIndex * 28)); txt.Visible = true; this.channelBox.Controls.Add(channelNames[currentChannelIndex]); }

I've also copied a screenshot of what the Form looks like once I execute the code and it iterates thru the channel list.  The Virtual Channel names get populated correctly and the TextBoxes are all created from PhysicalChanNames of in the Task.  

 

2019-07-31_18-43-43.jpg

 

Any help would be much appreciated.

Thanks!

 

 

0 Kudos
Message 1 of 3
(1,796 Views)

Hey beneeto,

 

  1. Where do you define runningTask
  2. Also what is the specific error we are receiving when you try to execute this code? Is it at compile time or run-time?

 

Finally, I'm sure you've found this already, but I thought I'd share the DAQmx Driver .NET Help Documentation.

Best regards,

Ryan B.
Technical Support Engineer
National Instruments
0 Kudos
Message 2 of 3
(1,751 Views)
Solution
Accepted by topic author beneeto

My apologies, i fixed this issue by indexing into the 2D array of data properly.  Here's a functional code snippet for what i did.  

 

int numOfChannels = channelCollection.Count;
                    double[,] analogDataIn = null;
                    
                    analogDataIn = analogInReader.ReadMultiSample(1);

                    for (int currentChannelIndex = 0; currentChannelIndex < numOfChannels; currentChannelIndex++)
                    {

                        var val = analogDataIn[currentChannelIndex, 0];
                        myTextboxList[currentChannelIndex].Text = val.ToString("F2");

                    }
0 Kudos
Message 3 of 3
(1,736 Views)