I'm doing some work with an NI ADC. I'm currently reading in voltages from the AO and AI into List<dynamic>
and I'm having some issues with console.writeLine.
I'm using the dynamic type because the program needs to decide what the data should be stored at, at runtime instead of compile time.
So, because of this whenever I want to print the contents of the list, it doesn't know what i'm asking so it returns the type being stored, not the selected element data.
public void createTask(DataGrid grid, List<Object> data, float sampleRate, int sampleAmount, ComboBox channel, float minRange, float maxRange)
{
using (Task myTask = new Task())
{
myTask.AIChannels.CreateVoltageChannel(channel.Text, "",
(AITerminalConfiguration)(-1), minRange, maxRange, AIVoltageUnits.Volts); // create the task to measure volts
myTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, // create the timing
SampleQuantityMode.ContinuousSamples, sampleAmount);
AnalogMultiChannelReader reader = new AnalogMultiChannelReader(myTask.Stream);
myTask.Control(TaskAction.Verify);
data.Add(reader.ReadSingleSample());
Console.WriteLine(data[0]);
}
}
Which in turn prints out System.Double[]
. How would I go about printing out what the element actually stores rather then its type? I've tried lots of different ways of trying to get what I'm after but I'm struggling with C# syntax (I use C++) - only been using it for three weeks.
I've tried;
<double>
list with CopyTo.I'm at a bit of a loss here.
1)You can iterate over the array
double[] data = new double[] { 1, 2, 3 };
foreach (var item in data)
Console.WriteLine(item.ToString());
2)Or
Console.WriteLine(string.Join(",", data));
The above solutions work if you already have an array of double. In your case ,if you are sure that data[0] is an array of double you can use the as operator
double[] temp = data[0] as double[];
Console.WriteLine(string.Join(",", temp));