02-04-2009 07:45 PM
I am trying to set up a system which needs to take several samples per day at set times (irregular intervals), and then repeat this each day for a week or so. So far I have been trying to use an array of TimeStamp controls, but am not getting far. Does anyone have any ideas on how to do this, or can point me to an example I have missed in my searching.
Thanks
Solved! Go to Solution.
02-04-2009 10:47 PM
Does this application need to be doing other stuff while waiting for the next timing interval to come up, or can it simply go to sleep until the appointed time?
Mike...
02-04-2009 11:52 PM
Hello Mike,
Most of the time the application will be waiting around for the next timed event to happen. The PC will be used exclusively to run this experimental equipment, so there won't be other applications running in the background either. I hope to run 5 sets of the experimental apparatus, each with its own set of timed events to occur. An 'event' is turning on a motor for a few seconds to deliver a measured amount of feed to animals at set times through the day. The shortest time interval between feeds is 1 hour, so even with 5 sets, it won't be working too hard.
02-05-2009 09:13 PM
Then what I would do is create an event loop with only one event - a timeout. Driving this event, would be an array of times when an action needs to be performed. When the loop starts, remove the first element and subtract the current time from the time target. This will give you the time in seconds until the event. Multiply it by 1000 to get the number of milliseconds until the target time. Feed that value to the timeout. Then each time the timeout event fires, index out the next element and calculate a new delay.
Mike...
02-05-2009 10:33 PM
02-05-2009 10:40 PM
Good point, thanks...
Mike...
02-17-2009 05:53 PM
Thanks Mike - I tried using an event structure and it works well. Getting this going has now brought to light another problem. I am feeding the event with an array of 24 timestamps. The problem is that if the user only wants say 6 time events, the rest of the array is filled with either default values or values from a previous run. Is there any way to programmatically let the user shrink the array size, or to fill it with null values or something?
02-17-2009 06:21 PM
Why are you stuck with 24 timestamps? Write the logic building the timeout array to only create as many elements as there are timeouts required.
Mike...
02-17-2009 07:10 PM
The maximum number of timeout events required is 24, so I have created an array of 24 Timestamp controls on the front panel. I have been looking at using other methods of getting users to enter times (such as tables), and then creating an array from this, but so far without success.
02-17-2009 07:21 PM
Ok, starting with an array of 24 empty timeout events, let the user edit the list to insert the appropriate timing data. When they click a button to start the tesst, trim off the end of the array any elements into which they haven't entered any data.
Mike...