More Code Debugging Required


Msrivas

Recommended Posts

private frequency = 1000

private time =10

private rat = 0

private summate = 0

global conc

private j = 0

 

while(1)

j=0

summate=0

while(j<=frequency*time)

 

try

   summate = summate + ChannelA[0]

   j= j+1

   delay(1/frequency)

catch() // catch any comm errors and ignore

 

endcatch

 

endwhile

rat = (j * 65535 - summate) / j

? rat

conc = 1.1 * (rat ^ 3) - 3.8 * (rat ^ 2) + 520 * rat + 0.62

? conc

endwhile

 

This code works alright for a while and then Daqfactory crashes. Here I am streaming a channel as in StreamOneChannel_UD. Could you suggest a replacement/improvement?

Link to comment
Share on other sites

Yeah, I'd imagine it does.  With a frequency of 1000, the delay is so small that the CPU won't even release.  Worse, if there is an error inside your try/catch(), the delay() never occurs.  Depending on your PC, this sort of loop could very likely kill DAQFactory because all your processor time is spent running your loop.

Link to comment
Share on other sites

Well, you aren't scanning.  You are just reading from the channel.  You aren't triggering the read of the channel.  I'm guessing from your other post that you are streaming.  Again, from your other post, are you just streaming for 2 seconds?  If so, I'd just do all the calculations after streaming is done.  Then you can use some array functions like sum() to do it without a loop.

Link to comment
Share on other sites

Archived

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