Code Debugging Required


Msrivas

Recommended Posts

private curenttime=GetTime(ChannelA[0])

private time =2

 

while (GetTime(ChannelA[0])<currenttime + time)

? "hello"

endwhile

 

What is wrong with the above code? I am using U6 to stream data into Daqfactory and I want the stream over a period of 2 seconds.

Link to comment
Share on other sites

Several things:

 

1) you have a while() loop with a delay(), which will run at full speed.

2) you have ? inside this super fast while loop which will dump a whole lot of stuff to the command / alert window, probably bogging down DAQFactory

3) you are basing the end time on the time of ChannelA.  If ChannelA doesn't get any new values with a time stamp past two seconds from now, the while() loop will go forever.  I'd recommend using systime() instead.

 

But, if all you want to do is stream for 2 seconds, just do:

 

//  .. script to start stream

delay(2)

// .. script to end stream

Link to comment
Share on other sites

If the history is big enough, you can easily capture 2 seconds just by subsetting by time.  Something like this:

 

global capturedData = channelA[systime(), systime()-2]

 

That will capture 2 seconds worth of data starting at the instant the code is run, and going back two seconds.

Link to comment
Share on other sites

Archived

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