Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

TDMS Logging Mode LogAndRead

My application requires that I sample 8 AI channels at 100 kHz/channel for several hours and log the data.  The snippet below is an example of what I am attempting to do.

The analog channels are configured, scaled, etc. in NIMAX as a task and loaded in.  If I confgure logging with LoggingMode.Log and comment out the AppendAnalogWaveforms method call in the event handler, everything runs great and all the data is logged.  However, I would like to display 1 sample value form each channel every half second.  So when I switch to LoggingMode.LogAndRead and append the data as shown, I get the "Unknow Error Exception" from TDMS after about a dozen or so appends to the TDMS file.  My thoughts are that I'm getting in the way of sampling and writing due to the high sample rate.  Any suggestions?  Is there a better way to do this?

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using NationalInstruments.DAQmx;
using NationalInstruments.Tdms;
using NationalInstruments;

namespace Production_Test
{
    public static class AnalogInput
    {
        private static Task _analogInputTask;
        private static NationalInstruments.UI.WindowsForms.NumericEdit _numEdit;
        private static TdmsFile _logFile;
        private static TdmsChannelGroup _tdmsGroup;
        private static TdmsChannel[] _tdmsChannels;
        private static AnalogMultiChannelReader _channelReader;

        public static void Start(NationalInstruments.UI.WindowsForms.NumericEdit numEdit)
        {
            _numEdit = numEdit;

            _analogInputTask = DaqSystem.Local.LoadTask("MyVoltageTask");

            _analogInputTask.ConfigureLogging("E:\\MyTestData.tdms", TdmsLoggingOperation.CreateOrReplace, LoggingMode.LogAndRead);

            _analogInputTask.EveryNSamplesReadEventInterval = 50000;
            _analogInputTask.EveryNSamplesRead += new EveryNSamplesReadEventHandler(_analogInputTask_EveryNSamplesRead);

            _analogInputTask.Start();

            _logFile = new TdmsFile(_analogInputTask.Stream.LoggingFilePath, new TdmsFileOptions());

            _tdmsGroup = _logFile.GetChannelGroup("MyVoltageTask");
            _tdmsChannels = new TdmsChannel[_tdmsGroup.GetChannels().Count];
            _tdmsGroup.GetChannels().CopyTo(_tdmsChannels, 0);
            _channelReader = new AnalogMultiChannelReader(_analogInputTask.Stream);
        }

        static void _analogInputTask_EveryNSamplesRead(object sender, EveryNSamplesReadEventArgs e)
        {
            try
            {
                _tdmsGroup.AppendAnalogWaveforms<double>(_tdmsChannels, _channelReader.ReadWaveform(-1));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        public static void Stop()
        {
            _analogInputTask.Stop();
            _analogInputTask.Dispose();
        }
    }
}

 

 

0 Kudos
Message 1 of 4
(5,945 Views)

Hi,

 

Have you tried running this with the LogAndRead enabled, but the appendanalogwaveforms commented out?

 

 

Mason M
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(5,921 Views)

Yes I have and it runs just fine, however no data is logged.

0 Kudos
Message 3 of 4
(5,914 Views)

Hello,

 

Have you checked out the TdmsContAcqVoltageSamples_IntClk example located in Start Menu-->National Instruments-->NI DAQ-->>NET 4.5 Examples-->Analog IN-->Measure Voltage?  It uses the logAndRead function as well and might help you out.

 

 

Mason M
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(5,898 Views)