Timers in events and the experiment

0 votes
7 views
asked Apr 8, 2016 by igrenn
retagged Apr 9, 2016 by qandaadmin

How can I get time, elapsed from the beginning of an experiment or from some event?

1 Answer

0 votes
answered Apr 9, 2016 by Maria Molodova (8,320 points)
selected Apr 9, 2016 by qandaadmin
 
Best answer
Each EventIDE event has a dedicated status property, called "Elapsed Time", which returns a number of milliseconds, passed since the onset of the event. The property value is updated automatically (while an event is active) and, therefore, it can be used as a local timer. The global experiment object also has the "Elapsed Time" property, accessible by HQ ribbon tab. This property returns a number of milliseconds passed since the start of experiment, and, therefore, can be used anywhere as a global timer.
commented Dec 6, 2016 by moeller (100 points)
Hi Maria,

I am about to implement a small state machine in the main control loop (to control two valves/pumps that need to be pulsed in potentially ant event of the experiment). To control on and off times I would like to access a high resolution time, I believe the experiments "Elapsed Time" property will just do fine, but will I need to create a proxy variable from the variable Experiments tab or can I directly access the most recent time information from a snippet without first needing to define tat proxy variable?

Many thanks in advance & best Regards
commented Dec 6, 2016 by Ilia Korjoukov (7,460 points)

Sebastian hi,

I think, the 'Elapsed Time' property is the most recommended for your scenario and, it can be accessed only via a proxy variable, sorry! The Elapsed Time has sub-millisecond precision but be aware that the Control Loop snippet is typically called once per 1 millisecond. Moreover, the 1 ms calling rate is not guaranteed, since it can drop significantly, if EventIDE core is occupied with other task.  

Still, you can access the high-precision timer in the snippets, using the Stopwatch class in C#,e.g.:

System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
for (int i=0;i<100;i++)
	{
	long TimerValue = sw.ElapsedMilliseconds;
	}

Note that the Stopwatch instance has to be declared in the snippets with the full namespace- System.Diagnostics.Stopwatch

Personally, I would recommend to implement the pump state machine with the EventIDE events. For instance, you can create  2 recurrent non-visual sub-events for the ON and OFF states of the pump, and control timing by the events' Duration properties. It may give you the better timing precision in comparison to any implementation in the code snippets. 

 

Welcome to EventIDE Q&A forum where you can ask questions about EventIDE software and receive answers from other members of the community

FAQ questions

Installation and License


Coding


Eye-tracking


EEG Analysis


Visual Stimuli


Runtime and Data Collection


Hardware

...