Code Debugging Required


Msrivas

Recommended Posts

Posted
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.

Posted

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

Posted

Actually I am streaming continuously. I want to  capture a 2 second window of data at 1000 times per second. The ? was just a debugging mechanism. My input stream is continuous and I have a feeling that execution never gets inside the loop.

Posted

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.

Archived

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