From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQ to network to TDMS issue

Hi, I am new to Labview and have a task which requires acquiring data, sending it across a network, and writing it to a file. I am using a PXI-1031 to acquire 8 analog input channels (for the moment connected to a signal generator).

My current solution is structured as such (see attached jpegs):
- Capture data through a VI running on the PXI, using DAQmx blocks, reading every 1ms (see pxiVI.jpg)
- Write the data to a network variable (as an Analog 1D DBL NChan 1Samp)
- Read the network variable by a separate VI running on a host computer on the same network (see hostVI.jpg)
- Write these values to a TDMS file (one column per channel)

I have been successful in getting this to work, after much confusion regarding data types (dbl, arrays of dbl, dbl waveforms, dynamic data, clusters). My question is this: Is there a better or more elegant way to accomplish what I am trying to do? Particularly, I would like to know 1) what DAQmx-Read output format is best for sending data across a network (so as to avoid network collisions), and 2) what data type is best (in this case) as input for TDMS Write?

Bonus question: Is there a trick to launching the PXI VI programmatically from the host VI? I have had no luck using the block chain (Open Application Reference) - (Open VI Reference) - (Call By Reference Node).
Download All
0 Kudos
Message 1 of 5
(3,433 Views)

hfmvdl,

 

I see where you are going with this code, but the implementation is very convoluted and I believe you will be missing a LOT of samples.

 

First, let's start simple. In your pxi vi, there is no point in having that sequence structure. Remove it.  You also do not have to individually name each channel. Delete them, the build array, and the flatten vi. Right click on the 'channels' input of create virtual channel.vi, create constant, type 'PXISlot3ai0:7'  Your code is looking better already.

 

Next, the actual data acquisition. Your timed loop is doing NOTHING for you here. I see that you are trying to track missed samples, but this is not the proper way to do it.  I would read more than one sample at a time, lets say 100, and send that through the network variable, to be read from the client.  You can send arrays over network variables, and there is also buffering(look at the properties of the variable).

 

On your host side, you shouldn't have to use dynamic data.  When you say 'every 5ms show a sample', is this going to a graph? Reading those shared variables will take MUCH longer than 1ms to execute, why are you using shared variables here anyways(I see 4).

 

The main problem with this host is you have wait until mext ms multiple...so this means if it takes 4.5 seconds to execute(this code will take much longer than 1ms), it will take 5 seconds to read the next value in the buffer.  Continue this, and after a while the buffer overflows, and you lose data.

 

There are a few other points, but try implementing the major changes (read N samples, send 2D arrays instead of single values one at a time, eliminate timed loop) and I can help you out more.

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
Message 2 of 5
(3,385 Views)

In addition, the data type should not matter, dbl is just fine for both the daqmx read and the TDMS write.

 

Good luck with this, and welcome 🙂

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
0 Kudos
Message 3 of 5
(3,383 Views)

(from original poster 'tph', incorrectly logged in as 'hfmvdl' on first post)

 

Hi Rob, thank you very much for your answer.

 

On the host side, I used dynamic data because I could not wire an array of DBL to TDMS Write without it writing each set of data to one single channel sequentially. That is, instead of appending 1 value to each of 8 channels, 8 sequential values would be appended to a single channel. Coming from a MATLAB background, I would have expected something like a 'transpose 1D array' command would solve this problem, but converting to dynamic data was the only labview solution I could find. Do you know a better way to solve this?

 

Where it says 'every 5ms show a sample', the indicator is a graph, yes.

 

The local shared variables you see in the host vi (DAQ control, tdms file in, Stop Program, DAQ loop running) are used in other parts of the VI (for example, a user input event structure sets 'DAQ control'). This sounds like a really elementary question, but is there a quicker way to read/write to local variables in parallel loops (e.g. writing to a property node)?

 

Tom H

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

tph,

 

When you pass 2D arrays through your network variables, it should be easier to plot and save them, since the data will already be in rows and columns.

 

A faster way or calling variables would be using references. Right click on any control in the block diagram and select create->reference.  These go through DMA rather than the stack, and should update faster.  But you should still try and avoid using local variables/references as much as possible in your code by focusing on your data flow.

 

I'd be happy to help you out if you can post some more screenshots of your code.  There are so many optimizations to be made from your original post.

 

 

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
Message 5 of 5
(3,336 Views)