07-31-2019 08:46 PM - edited 07-31-2019 09:08 PM
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.
Any help would be much appreciated.
Thanks!
Solved! Go to Solution.
08-16-2019 12:01 PM
Hey beneeto,
Finally, I'm sure you've found this already, but I thought I'd share the DAQmx Driver .NET Help Documentation.
Best regards,
08-19-2019 08:08 PM
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"); }