Help needed with dT timestamp for streamed data with a LabJack U3


Recommended Posts

I'm posting this as a follow-up to my last thread and I'm still trying to add a dT timestamp to my streamed data from a LabJack U3 LV. My problem is that using the a logging function doesn't give me the correct resolution for dT in the logging file, it only writes the dT values (same is true for my AIN0 test channel) every now but the AIN4..6 channel data looks to be good and updating like it should.

So to try to remedy the problem I created a write_file sequence writing direcly via File. functions and a variable stepping up the time interval between individual samples looking like this:

//private zero_time=AIN4.Time[0]

private add_t=0

while(1)

//dT.AddValue(inserttime(AIN4.Time[0]-zero_time, AIN4.Time[0],-1))

add_t=add_t+(1/scanrate)

try

private handle = file.Open("c:\mydata_1.csv",0,1,1,1)

private string out = FormatDateTime("%c",systime())

out += ";" + add_t

out += ";" + AIN4[0]

out += ";" + AIN5[0]

out += ";" + AIN0[0]

file.write(handle,out)

file.Close(handle)

catch()

? strLastError

endcatch()

wait(1/scanrate)

endwhile

and the scanrate variable is the real straming scanrate from the Start_Stream sequence... but... doing this does not update the channel values at the correct rate(getting like 7-10 lines of the same data).

So now I've got a logging function that can't log the time correctly and a write to file sequence that can't save the channel data correctly and I don't really know what to pull out of the hat anymore, it is really confusing and real help would be very much appreciated :) , I've attached the .ctl file which is my modification of an old U3 streaming example posted by Azeotech.

FYI: Data is added to AIN0 and dT under the AIN6 channel event.

U3_Streaming_w_logging_and_write_to_file_funtionality.ctl

Link to comment
Share on other sites

The thing about streaming data is that it comes in in blocks, not as individual readings. So, where a non-streamed channel will get a new data point every Timing interval, a streamed channel might get data every 0.1 seconds, even though the scan rate might be 100hz. Every 0.1 seconds it would get a block of ten values, each with the appropriate time stamp. This is why you get the duplicate data, you are reading the same value while waiting for the next block.

Probably the easiest way to do this is to stream some random extra channel and then apply a conversion to it that calcs the dt. So, if you are streaming AI4 and AI5, stream AI6 too, or pick one of the ancillary U3 stream channels. Create a channel for it, then create a Conversion. The conversion would be something like:

getTime(Value) - startTime

where startTime is the variable that holds time 0. Apply that conversion to your channel, then include the channel in the logging set. Now, whenever a new value streams in on that channel, it will be replaced with the dt value.

Note that you can't duplicate a channel you want to keep. In other words, if you are streaming in AI4, you can't create two channels for #4 and apply the conversion to only one.

Link to comment
Share on other sites

That technique worked great, many thanks!

Now my final question is how to get my AINO test channel which gets its data from the streaming AIN4 to fill with all the AIN4 data and not a single value every 10th row or something(similar problem to my dT issue)?

I've been using an event for AIN4 looking like AIN0.AddValue(AIN4[0]) but just like you already pointed out, this doesn't work for streaming data.

I should say that I need the test channel to hold a tared AIN4 value... I've tried using a conversion like value.addValue(AIN4[0]) for the test channel but it doesn't work, I still get the same "slow" data output rate for the test channel (that approach did however generate two logging files where one is named after the previously logged file and one assumes the true logging file path name :) !)

Regards

Marcus

Link to comment
Share on other sites

Also on your post about dt timestamp for stream data using U3

The random channel I pick for streaming to apply the conversion too, is not connect to anything from the LabJack, is this ok?

Also, is the getTime the created channel name or is it startTime?

You also say "Apply that conversion to your channel, then include the channel in the logging set." Am I supposed to create a logging set under logging?

Thanks for your help

Link to comment
Share on other sites

Marcus:

Yeah, events don't really work for streaming data because they are triggered every block, not every data point. You should use a conversion, but you need to remember that a conversion is an expression, not script, so you can't put a statement like value.addvalue(), not to mention "value" isn't technically an object with an addValue() function to call.

Anyhow, I have to ask, are you logging the tared value? And if so, are you logging the non-tared value? If you aren't logging it, then you can just subtract in expressions elsewhere (like in your graph).

Link to comment
Share on other sites

Neither. As I said, getTime() is a global function. StartTime should be a global variable. "Value" is the value from the channel you apply the conversion to, which should be your created channel. You should not specify the created channel by name anywhere in the conversion.

Link to comment
Share on other sites

Azeotech:

The tared value is what I want to log (and present in the graph) but I'm currently logging the un-tared value in the example file.

Using a tare button with a quick sequence looking like (I'll use the streaming AIN4 in this example) : AIN4_tare=mean(AIN4[0,9]) and then using a conversion applied to the AIN4 channel looking like Value-AIN4_tare is not a stable way of doing the tare, it'll only work fine once, and that is the reason why I'd like to use a test channel where I can put the AIN4 data together with the tare value looking something like:

test_channel_AIN4_tared=AIN4-AIN4_tare, this way I can use the tare as many times as I need without any problems and it'll always bring my tared signal down to zero.

How would you write an expression in the conversion for the test channel to do this if it is possible? I've been using events and .addValue() functions when I wasn't streaming (in other DaqF programs), but like you say, that doesn't work anymore...

Regards

Marcus

Link to comment
Share on other sites

You can't easily do it. But I'm not sure why you say its not a stable way of doing tare. Just do this:

1) initialize AIN4_tare to 0 in startup

2) when you want to apply a tare, you do this:

AIN4_tare = mean(AIN4[0,9]) + AIN4_tare

This will back out the tare from the mean so you can assign a new tare.

Link to comment
Share on other sites

Your syntax skills are greater than mine, no doubt about that :rolleyes:

There's one more thing and I guess based on your previous answer it might not be that easy to do. In my real application I'll be streaming logging and taring two channels but I also want to (at the same time and to the same logging file) log the quotient between the two signals. I was thinking adding a test channel and a conversion where the streamed quotient AIN4 / AIN5 somehow could be placed but is that possible and if so how?

Thanks for all the input, I really appreciate it!

Marcus

Link to comment
Share on other sites

That is much harder to do. You'd have to create an event that looks for a block of new data by storing the timestamp of the last data point processed (can't use index as that changes). The sequence would process through this new data, pushing the quotient to a test channel with the appropriate time stamps, and then resetting the time of the last data processed so it can pick up a new block. I'd probably use the search() function to find the last data point processed. I'd put this event in the channel that is last in your list of streaming channels as this should be called after all the channels have received their blocks of data.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.