示例#1
0
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                button4.Enabled = false;
                NationalInstruments.AnalogWaveform <double>[] generatedData = new NationalInstruments.AnalogWaveform <double> [anlog_OutputComponent1.NumberOfChannelsToWrite];

                // TODO: Populate data to write.
                //throw new System.NotImplementedException("You must populate the data to write before writing the data.");

                int numberOfPoints = 100;
                AnalogWaveform <double> analogWaveform = new AnalogWaveform <double>(numberOfPoints);

                for (int i = 0; i < numberOfPoints; i++)
                {
                    analogWaveform.Samples[i].Value = 3;
                }

                generatedData[0] = analogWaveform;
                generatedData[1] = analogWaveform;


                anlog_OutputComponent1.WriteAsync(generatedData);
                waveformGraph2.PlotWaveforms(generatedData);
            }
            catch (NationalInstruments.DAQmx.DaqException ex)
            {
                MessageBox.Show(ex.Message, "DAQ Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                button4.Enabled = true;
            }
        }
示例#2
0
        public double ReadTemperature()
        {
            // Reads data from the analogue input channel.
            data = reader.ReadWaveform(samplesPerChannel);
            // Converts data into a filtered voltage.
            double voltage = Program.filterVoltage(data.Samples[1].Value);
            // Calculates temperature based on voltage and set constants.
            double B  = 0.0;
            double R0 = 0.0;
            double T0 = 298.15;

            if (channelText == "Ainport0")
            {
                B  = 3380;
                R0 = 10000;
            }
            if (channelText == "Ainport1")
            {
                B  = 4380;
                R0 = 100000;
            }
            if (channelText == "Ainport2")
            {
                B  = 3960;
                R0 = 5000;
            }
            double R    = (R0 * voltage) / (5.0 - voltage);
            double temp = (T0 * B) / ((T0 * Math.Log(R / R0)) + B);

            // Returns the temperature in degrees centigrade.
            return(temp - 273.15);
        }
示例#3
0
        public double ReadData()
        {
            data = reader.ReadWaveform(samplesPerChannel);

            double sum = 0;

            for (int i = 0; i < samplesPerChannel; i++)
            {
                sum += data.Samples[i].Value;
                //Console.WriteLine("Sample{0}=>time={1}, value={2}", i + 1, data.Samples[i].TimeStamp, data.Samples[i].Value);
            }



            return(sum / samplesPerChannel);


            //return reader.ReadSingleSample();
        }