Tscope5
timer.c File Reference

Definitions of timer functions. More...

Go to the source code of this file.

Functions

Program priority functions

You can increase your program's priority to get better timing accuracy.

int ts5_set_priority (int priority)
 Set the program's priority.
int ts5_get_priority ()
 Get the program's priority.
General timing functions

The general timing functions are mainly used to control stimulus timing.

You can either wait for a given amount of time, or until some time in the future.

double ts5_get_time ()
 Get the number of seconds since the program started.
void ts5_wait (double waittime)
 Wait for a number of seconds.
void ts5_wait_until (double deadline)
 Wait until a deadline.
Response registration

The response registration functions require you to define response buttons first using ts5_define_mouse_button(), ts5_define_keyboard_button(), ts5_define_joystick_button(), ts5_define_cedrusbox_button() or ts5_define_parport_button().

Each response button will get a response value. The first button that is defined will get number 1, etc.

Registration of responses is done asynchronously. All button presses that are defined will be buffered continuously during the program.

Waiting for a response to a stimulus will typically involve flushing all buffered responses that occurred before stimulus onset using ts5_flush_responses() and then checking for new responses using ts5_check_response(), ts5_wait_for_response(), ts5_wait_for_response_timed() or ts5_wait_for_response_until().

The response definition can be altered during the program using ts5_hide_response_button() or ts5_remove_response_buttons().

int ts5_hide_response_button (int button)
 Temporarily deactivates a response button.
void ts5_remove_response_buttons ()
 Completely removes the response button definition.
void ts5_flush_responses ()
 Flush the response queue.
int ts5_check_response (double *resptime, double *timing_error)
 Check for a reponse.
int ts5_wait_for_response (double *resptime, double *timing_error)
 Wait for a response.
int ts5_wait_for_response_timed (double *resptime, double *timing_error, double maxtime)
 Wait for a response for a given time.
int ts5_wait_for_response_until (double *resptime, double *timing_error, double deadline)
 Wait for a response until a deadline.
Trigger input/output

The trigger input functions require you to define trigger devices using ts5_define_parport_trigger_input() or ts5_define_serialport_trigger_input().

Registration of trigger input is done asynchronously. All triggers received on the parallel and/or serial port(s) will be buffered continuously during the program.

Waiting for a trigger is similar to waiting for a reponse. Old triggers that were not processed yet can be flushed using ts5_flush_triggers(). One can either wait for a trigger indefinitely, for a given amount of time or until some deadline has passed.

The value of the trigger is defined by the computer that sends the trigger.

During the development of the program it is not necessary to connect a computer that sends the triggers. Trigger input can be simulated using ts5_simulate_parport_trigger_input() or ts5_simulate_serialport_trigger_input().

At the end of the program all triggers can be written to a logfile using ts5_write_all_triggers().

Trigger output is simple, call ts5_send_parport_trigger() or ts5_send_serialport_trigger() each time you want to send a trigger.

void ts5_flush_triggers ()
 Flush the trigger queue.
int ts5_check_trigger (double *trigtime, double *timing_error)
 Check for a trigger.
int ts5_wait_for_trigger (double *trigtime, double *timing_error)
 Wait for a trigger.
int ts5_wait_for_trigger_timed (double *trigtime, double *timing_error, double maxtime)
 Wait for a trigger for a given time.
int ts5_wait_for_trigger_until (double *trigtime, double *timing_error, double deadline)
 Wait for a trigger until a deadline.
void ts5_write_all_triggers (char *filename)
 Write all triggers to an output file.

Detailed Description

Definitions of timer functions.

Definition in file timer.c.


Function Documentation

int ts5_set_priority ( int  priority)

Set the program's priority.

Parameters:
priorityPriority.
Returns:
The previous priority.

There are five possible settings:

  • TS5_HIGH_PRIORITY
  • TS5_ABOVE_NORMAL_PRIORITY
  • TS5_NORMAL_PRIORITY
  • TS5_BELOW_NORMAL_PRIORITY
  • TS5_LOW_PRIORITY.

The default priority is TS5_NORMAL_PRIORITY.

Examples:
timer02.c.

Definition at line 62 of file timer.c.

int ts5_get_priority ( )

Get the program's priority.

Returns:
The program's priority.

Definition at line 178 of file timer.c.

double ts5_get_time ( )

Get the number of seconds since the program started.

Returns:
The number of seconds since the program started (as a double precision float).
Examples:
parport03.c, serialport02.c, and timer01.c.

Definition at line 208 of file timer.c.

void ts5_wait ( double  waittime)
void ts5_wait_until ( double  deadline)

Wait until a deadline.

Examples:
parport03.c, serialport02.c, timer01.c, and timer02.c.

Definition at line 243 of file timer.c.

int ts5_hide_response_button ( int  button)

Temporarily deactivates a response button.

Parameters:
buttonThe button that has to be deactivated.
Returns:
The number of active buttons left.

This function also checks whether there are any active response left. Aborts if necessary.

Reactivating all defined buttons is possible by calling ts5_hide_response_button(0).

Examples:
timer04.c, and timer06.c.

Definition at line 307 of file timer.c.

void ts5_remove_response_buttons ( )

Completely removes the response button definition.

Definition at line 508 of file timer.c.

void ts5_flush_responses ( )

Flush the response queue.

Examples:
cedrusbox01.c, joystick01.c, keyboard01.c, mouse01.c, parport01.c, timer03.c, timer04.c, timer05.c, and timer06.c.

Definition at line 603 of file timer.c.

int ts5_check_response ( double *  resptime,
double *  timing_error 
)

Check for a reponse.

Parameters:
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
Returns:
The button that was pressed (0 if no button was pressed within the deadline).

This function checks for a response and returns immediately.

Definition at line 624 of file timer.c.

int ts5_wait_for_response ( double *  resptime,
double *  timing_error 
)

Wait for a response.

Parameters:
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
Returns:
The button that was pressed.
Examples:
mouse02.c.

Definition at line 797 of file timer.c.

int ts5_wait_for_response_timed ( double *  resptime,
double *  timing_error,
double  maxtime 
)

Wait for a response for a given time.

Parameters:
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
maxtimeMaximum time for a response.
Returns:
The button that was pressed (0 if no button was pressed within the maximum time).
Examples:
cedrusbox01.c, joystick01.c, keyboard01.c, mouse01.c, parport01.c, timer03.c, and timer06.c.

Definition at line 825 of file timer.c.

int ts5_wait_for_response_until ( double *  resptime,
double *  timing_error,
double  deadline 
)

Wait for a response until a deadline.

Parameters:
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
deadlineDeadline for a response.
Returns:
The button that was pressed (0 if no button was pressed within the deadline).
Examples:
timer04.c, and timer05.c.

Definition at line 865 of file timer.c.

void ts5_flush_triggers ( )

Flush the trigger queue.

Definition at line 935 of file timer.c.

int ts5_check_trigger ( double *  trigtime,
double *  timing_error 
)

Check for a trigger.

Parameters:
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error.
Returns:
The value of the trigger

This function checks for a trigger and returns immediately.

Definition at line 954 of file timer.c.

int ts5_wait_for_trigger ( double *  trigtime,
double *  timing_error 
)

Wait for a trigger.

Parameters:
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
Returns:
The button that was pressed.
Examples:
parport02.c, and serialport01.c.

Definition at line 1039 of file timer.c.

int ts5_wait_for_trigger_timed ( double *  trigtime,
double *  timing_error,
double  maxtime 
)

Wait for a trigger for a given time.

Parameters:
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
maxtimeMaximum time for a trigger.
Returns:
The button that was pressed (0 if no button was pressed within the maximum time).

Definition at line 1067 of file timer.c.

int ts5_wait_for_trigger_until ( double *  trigtime,
double *  timing_error,
double  deadline 
)

Wait for a trigger until a deadline.

Parameters:
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
deadlineDeadline for a trigger.
Returns:
The button that was pressed (0 if no button was pressed within the deadline).

Definition at line 1108 of file timer.c.

void ts5_write_all_triggers ( char *  filename)

Write all triggers to an output file.

Parameters:
filenamePath to the output file
Examples:
parport02.c, and serialport01.c.

Definition at line 1142 of file timer.c.