02-05-2019 01:42 PM
Hello,
We need to generate some complex waveforms. Therefore, instead of using LabVIEW directly, we decide to use Python to generate these waveforms and export them into some files, which can be read by LabVIEW. We think that our waveform files should be similar to waveform files generated by LabVIEW. However, we do not find any description on the structure of waveform files. From a simple example waveform generated by LabVIEW, we only guess that it is a binary file and there are some descriptions at the beginning of files. Could someone show me the structure of waveform files in ASCII? Thanks a lot!
Solved! Go to Solution.
02-05-2019 02:22 PM
What waveform file are you referring to? I have seen TDMS, CSV, text.
Personally, I would just save your data to a tab delimited text file and you can just use the Read Delimited Spreadsheet File to get your waveform data.
02-05-2019 05:37 PM
I guess you are talking about the read/write tools in the "waveform file IO" palette. (If not, please be more specific ;))
A waveform datatypes is basically a 1D array (numeric, digital, etc.) with timing information (i.e. equally spaced in time as defined by t0 and dt) and you can have arrays of such waveforms.
You can open the waveform file VIs and look at the code. From that you can see that arrays of waveforms are stored as datalog files with an array of waveforms as "datalog record" type. (details)
For some perspective, here's what I wrote ~11 years ago about datalog files. I would recommend to save in plain files as Tim already suggested.
02-05-2019 08:53 PM
Thanks for your reply. I do not know the file format exactly because there is no extension but it is not csv or TDMS. I just try to generate a waveform file with python which can be generated by "Write waveform to file" function of LabVIEW and can be read by "Read waveforms from file" function. (the waveform is too complex so it is a little bit difficult in LabVIEW)
02-05-2019 09:01 PM
Yes, exactly. I just want to generate a waveform file with Python which can be read by the "Read waveforms from file" function of LabVIEW but I do not know what a waveform file should look like. I try to explore the file structure using a waveform file generated by "Write waveforms to file" but it seems that it is a binary file. After I read it byte by byte, actually I do not see evident structure. If I write the waveforms into plain files, can it be read by LabVIEW?
02-06-2019 02:04 AM
02-06-2019 02:42 AM
@KK97 wrote:
If I write the waveforms into plain files, can it be read by LabVIEW?
LabVIEW is a full featured programming language and any file is nothing more than a linear sequence of bytes. Once you know the file structure, you can parse it into the desired data structure.
02-06-2019 03:24 AM
As Altenbach mentioned, Write waveform end up in a Write Datalog, which is a raw binary of the waveform. So if you play around with Waveforms and Flatten to string it should become apparent. It writes an away of waveforms, and looking at it:
[array size, 4 bytes (int)]
[datetime 16 bytes]
[dT 8 bytes]
[data array size 4 bytes]
[data array, x doubles of 8 bytes]
[filler? 1 byte ]
[Variant, X bytes with attributes, "data string 6" with empty variant]
/Y
02-06-2019 04:05 AM - edited 02-06-2019 04:08 AM
@Yamaeda wrote:
As Altenbach mentioned, Write waveform end up in a Write Datalog, which is a raw binary of the waveform. So if you play around with Waveforms and Flatten to string it should become apparent. It writes an away of waveforms, and looking at it:
[array size, 4 bytes (int)]
[datetime 16 bytes]
[dT 8 bytes]
[data array size 4 bytes]
[data array, x doubles of 8 bytes]
[filler? 1 byte ]
[Variant, X bytes with attributes, "data string 6" with empty variant]
That's all nice and good but likely way over the head of the topic creator. While the 16 bytes datetime is actually sort of parsable (it's a 64 bit signed integer containing the seconds, and a 64 bit unsigned integer containing the fractional seconds), there are other difficulties in this such as the fact that the Variant memory layout never has been fully documented. And also that all these numbers are stored in big endian format in the data stream.
There are better things to do with your time than trying to parse binary files so unless you write such things as your job every day or just really really want to tinker with such difficulties for the fun of it, I would advice to use a different file format to share data between LabVIEW and non-LabVIEW applications.
02-06-2019 07:32 AM
There is an example, where "Write Waveforms to File" is used in NI Example Finder. According to that VI the extension of file is .dat.