0 votes
412 views
by
retagged by

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

1 Answer

0 votes
by (8.7k points)
selected by
 
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.
by (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
by (14.5k 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

Categories

FAQ questions

Installation and License


Coding


Eye-tracking


EEG Analysis


Visual Stimuli


Runtime and Data Collection


Hardware

...