timer control


ideasman

Recommended Posts

I am trying to use the date/time edit control only using the time part.

Basically I want to create a reusable timer so if you select time1 edit control this sets the on time and a second edit date/time control for the off time, which corresponds to a channel sending 0 or a 1.

In the control size tab there is an x, visible and another box for the sequence I cant work out which one to use for the code. Or does all this code go in the sequences part on the treeview.

Also if this control is to be reused on another project how do I go about it.

thanks

ideasman.

Link to comment
Share on other sites

This is the code I aM using so far,can you guys tell me why this is not working

while(1)
   if ((SysTime() > v.datone[1]) && (SysTime() < v.dattwo[2])) // comparing between a time span
	  v.dat[0] = 1 // led represents on when in time span off when not in time span
   else
	  v.dat[0] = 0

   endif
endwhile

cheers

Ideasman

Link to comment
Share on other sites

Sorry, I didn't get a chance to reply to your first email. First, I wouldn't use v channels. I'd use variables instead. There's nothing really wrong with V channels, they just are a little deprecated since variables came along. However, they do have the handy table (though the watch will achieve the same thing). OK, on to your code:

1) I think you want [0] on datone and dattwo as you want the most recent value, not the second and third most recent value. If you were using variables you wouldn't need this at all since it wouldn't form a history automatically

2) Are you using the full date of the date time edit, or just the time? If just the time, then you have to strip the date part out of systime() and the datone/dattwo channels. The easiest way is using modulus (%) to get the number of seconds in the day:

if ((systime() % 86400 > v.datone[0] % 86400) && (systime() % 86400 < v.dattwo[0] % 86400))

3) you don't need [0] when assigning a value. You just want v.dat = 1.

4) You technically could combine this into one statement:

v.dat = ((systime() % 86400 > v.datone[0] % 86400) && (systime() % 86400 < v.dattwo[0] % 86400))

because the boolean part (the if()) returns either 1 or 0.

5) you have an infinite loop without a delay(). This will likely hang DAQFactory. Add a delay(0.1) or similar just before the endwhile

Link to comment
Share on other sites

Well its pretty much the same, except you have to declare the variables (which you do in script) rather than create the V channel:

global datone = systime()
global dattwo = systime()
global dat = 0

while(1)
   if ((systime() % 86400 &gt; datone % 86400) &amp;&amp; (systime() % 86400 &lt; dattwo % 86400))
	  dat = 1 // led represents on when in time span off when not in time span
   else
	  dat = 0  
   endif
   delay(1)
endwhile

Then just have your date/time edit control edit the the datone and dattwo variables.

Link to comment
Share on other sites

Archived

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