08-20-2021 11:43 AM
I've got 9 channels being read by a 1Chan, NSamp (Waveform) instance of the DAQmx Read node.
I'm taking 5000 samples at 51.3kSPS
I would like to log the data to a JSON file but I'm having trouble formatting the data output to json in a format like so:
[
{
"channel": "one",
"data": [
{
"time(ms)": 0.000,
"value": 12.2376
},
{
"time(ms)": 0.0194,
"value": 13.5832
},
...
]
},
{
"channel": "two",
"data": [
{
"time(ms)": 0.000,
"value": 12.2376
},
{
"time(ms)": 0.0194,
"value": 13.5832
},
...
]
},
...
]
the main issues being;
I can't extract the time of each sample, as I understand it, it's not necessarily 1/51300 of a second per sample.
I can't think of the best way to convert the data output to a something I can build a JSON object from.
Kind regards,
Henry
08-20-2021 12:20 PM
DAQmx data will be hardware timed to be evenly sampled, which is why waveforms have a delta-t value rather than individual timestamps.
08-20-2021 12:21 PM
@HenryHEXR wrote:
the main issues being;
I can't extract the time of each sample, as I understand it, it's not necessarily 1/51300 of a second per sample.
I can't think of the best way to convert the data output to a something I can build a JSON object from.
Assuming you are using hardware timing, which appears you are, then you can trust that sample rate being pretty accurate, at least enough that you would care.
@HenryHEXR wrote:
I've got 9 channels being read by a 1Chan, NSamp (Waveform) instance of the DAQmx Read node.
Why are you not putting all of the channels into a single task and only do 1 read? It would make things a lot simpler.
And why JSON? This seems likes a horribly inefficient format for storing your data. I would lean towards a TDMS or tab delimited text file, which are a lot more readable.
08-22-2021 09:02 AM
Hello both,
Noted on the timing thank you I'll just derive it from the sample rate. In that case a better format would be:
[
{
"channel": "one",
"data": [
12.2376,
13.5832,
...
]
},
{
"channel": "two",
"data": [
12.2376,
13.5832,
...
]
},
...
]
in JSON as I need to pipe the data into other software, in fact it's quite likely I'll be making a POST request with the data as the body.
I am doing one read using one 1Chan, NSamp (Waveform) instance of the DAQmx Read node so all the data is coming out of one node. I just don't know how to put it into the above (or similar) JSON format
Kind regards,
Henry
08-23-2021 11:13 PM - edited 08-23-2021 11:16 PM
In a single task, use the N Ch, N Sample version of DAQmx Read to read all the channels at once. You can then write the data to a cluster as shown. Note, I wasn't able to flatten any data structure that included the timestamp. Apparently, the Flatten to JSON does not like timestamps - who knew?
This code produces the JSON string as shown below:
08-25-2021 12:08 PM
Hi Doug,
I was able to get the timestamp value to flatten to JSON by first converting to string. When flattening to XML I could see that timestamp values in LabVIEW aren't a simple key:value pair so flatten to JSON struggles.
H