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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Playing back a waveform

Solved!
Go to solution

So I have been tasked with taking a program I made using NI-Scope and a NI USB-5132 and making it so we can stream a waveform to disk at the same time it is being displayed (duration TBD).

 

Then using a seperate program we want to be able to playback that saved waveform, view, and analyze it just as if it were live data from the USB-5132.

 

I have the saving part figured out, but not the playback part and am looking for suggestions and examples.

 

So far I have just started playing with the read waveform vi and have this:

 

readwaveform.png

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 1 of 44
(3,090 Views)

I've never used the Read Waveforms from File function, so I'm guessing somewhat here.  Some curious things:

  • Ha!  I just figured out the curious Decrement on the While Index -- it's because you put in a "tricky" one-time Timeout to get the Filename for the file.  Why not put "initialization code" outside the While Loop and have it "initialize" the Shift Register?  Then you can simply wire "i" to Offset.
  • I'm curious why there's a First Waveform and All Waveforms output.  What happens if you (a) open the Waveform File, (b) read it and save "All Waveforms", and then (c) close the file?  No loops, possibly no need for an Event Loop here.  Now that you have all the Waveforms, you can do whatever you need to do with them (including playing them out one at a time, over-and-over as your need requires).
  • K.I.S.S. (and don't tell!).

Bob Schor

0 Kudos
Message 2 of 44
(3,045 Views)

Yeah I just threw this together, the iteration terminal and decrement was added later when I was trying something, so I had already painted myself into a corner 

 

There are two outputs First Waveform in Record and All Waveforms in Record.

 

I was guessing that First Waveform in Record would output whatever waveform the "offset(record)" input was set to, so I wired in the iteration counter expecting to see a waveform playback with each iteration showing the next record.

 

Apparently that is not the case...

 

I guess I am going to have to read out "All Waveforms in Record" and index each record to the display myself.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 44
(3,034 Views)

@RTSLVU wrote:

...

I guess I am going to have to read out "All Waveforms in Record" and index each record to the display myself.


Yes that will work provided you do the chart updates at the same rate it was collected.

 

In one project I had to do the same thing but in my case I wrote the waveforms as data log files. I pulled a new record at the rate the data was saved/displayed. The interesting twist on that project was they wanted to be able to back-up the plot like hitting the rewind on a video to run it in reverse. In that case I threw the entire set at the chart via the  chart>>> history and repeated that in a loop but truncated the data by one record each time it iterated. It worked better than I had expected and once the user backed up as far as they wanted to back-up, I could then resume forward in time by posting the updates as they came in originally.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 44
(3,028 Views)

Yeah the timing issue has been floating around in my head since I started, and to make matters worse I am also going to have to sync the waveform playback with a table of voltage, current, and power measurements taken at about 1 second intervals during the waveform capture.

 

Now I am thinking that maybe my VI works like I thought it should but just too fast?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 44
(3,020 Views)

@RTSLVU wrote:

Now I am thinking that maybe my VI works like I thought it should but just too fast?


Now that's a novel complaint!  The little peephole into your code afforded by your Snippet doesn't show from whence cometh the data -- I'm assuming a DAQmx acquisition loop.  You also mentioned a point every two seconds, which suggests a sampling rate of 0.5 Hz.

 

If I might make a suggestion, DAQ devices make excellent clocks (timing is important in these things, and they don't have Windows or Updates or Virus Scans running in the background).  If you really need 0.5 Hz data, I'd suggest setting your DAQ Task to acquire 10 points at 5 Hz, which "blocks" for 2 seconds and then gives you 10 points that you can Average, increasing S/N by a factor of several, basically costing you nothing.  You can easily embed this in a Producer/Consumer design to get the DAQ loop really isolated, leaving 99+% of the CPU for "everything else".

 

Bob Schor

0 Kudos
Message 6 of 44
(3,010 Views)

Well the waveform data was created using a NI USB-5132 USB oscilloscope. The USB-5132 is not programmed like a NI-DAQ device it uses NI-Scope. But in general I am saving every "sweep" to the waveform file.

 

Here's a screenshot, again I just kluged in the save to file part to get something to work with as I figured saving a waveform would be far easier than playing it back, and I was right...

O-SaveCapture.PNG

 

What I am running into now is "Write Waveform to File" says it wrote 1000 records.

 

But when I read the file I reach the "End of File" at 140 records?

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 44
(2,998 Views)

TDMS is written to a memory buffer and when it darn right feels like it, it will write the data.

I believe a TDMS flush will force writing the buffer to file.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 44
(2,994 Views)

Thank you all for the recommendations

 

Priorities have changed and I have to back burner this for a couple weeks.

 

Watch for this topic to rise from the grave. 😛

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 44
(2,982 Views)

Okay I am back on the project for the time being.

 

Currently I have:

  1. Modified the "save to file" portion to not close the file until all queued elements have been written to the file
    1. This solved the first issue of the files not having as many records as the should have.
  2. Playback is still too fast
    1. 2:30 seconds of recording plays back in just under 2:00 minutes
    2. I tried slowing the playback down by using "Waveform Duration" and waiting that amount of time before moving onto the next record
    3. Looking for suggestions on how to playback a waveform at the same speed it was recorded

playback1.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 44
(2,897 Views)