Data Buffer

EyeLink data retrieval and buffering.

This module provides the DataBuffer class for managing sample and raw data retrieval and buffering from the EyeLink tracker.

class pyelink.data.DataBuffer(device, buffer_length=0, use_buffer=False, read_from_tracker_buffer=True, record_raw_data=False)[source]

Bases: object

Handles data retrieval and buffering from EyeLink tracker.

This class manages: - Sample and raw data retrieval from tracker - Buffering data in a ring buffer - Background threads for continuous data collection

Parameters:
  • device (EyeLink)

  • buffer_length (int)

  • use_buffer (bool)

  • read_from_tracker_buffer (bool)

  • record_raw_data (bool)

__init__(device, buffer_length=0, use_buffer=False, read_from_tracker_buffer=True, record_raw_data=False)[source]

Initialize sample buffer.

Parameters:
  • device (EyeLink) – Connected EyeLink instance

  • buffer_length (int) – Number of samples to store in ring buffer (0 = no buffering)

  • use_buffer (bool) – Store data from tracker buffer in RingBuffer

  • read_from_tracker_buffer (bool) – Use getNextData() instead of getNewestSample() (the former draws from an internal buffer and should miss fewer samples)

  • record_raw_data (bool) – Whether raw pupil/CR data is being recorded

Return type:

None

get_timestamp()[source]

Get timestamp of latest sample.

Return type:

float

Returns:

Timestamp in milliseconds, or np.nan if not connected

get_sample(write_to_edf=False)[source]

Get the latest gaze sample over the link.

The link must have been activated first: tracker.startRecording(0, 0, 1, 1) If both eyes are used, the left one is chosen by default.

Eye indices:

0 - left eye 1 - right eye 2 - binocular (returns [lx, ly, lpupil, rx, ry, rpupil])

Parameters:

write_to_edf (bool) – Write gaze data to edf-file as messages

Returns:

(timestamp, sample_info)
  • timestamp: Sample timestamp or -1 if no sample

  • sample_info: List of sample data or None

Return type:

tuple[int | float, list | None]

get_sample_from_buffer(write_to_edf=False)[source]

Get the latest gaze sample from the EyeLink buffer.

Uses getNextData() which draws from an internal buffer and should miss fewer samples than getNewestSample().

Data type constants from pylink:

200 - Sample data 4 - ENDBLINK event 8 - ENDFIX event 0x3F/0 - No data available

Parameters:

write_to_edf (bool) – Write gaze data to edf-file as messages

Returns:

(timestamp, sample_info)

Return type:

tuple[int | float, list | None]

get_raw_sample(write_to_edf=False)[source]

Get the latest raw sample over the link.

The link must have been activated first: tracker.startRecording(0, 0, 1, 1)

Parameters:

write_to_edf (bool) – Write data to edf-file as messages

Returns:

(timestamp, raw_data)

Return type:

tuple[int | float, list | None]

get_raw_sample_from_buffer(write_to_edf=False)[source]

Get the latest raw sample from the EyeLink buffer.

Data type constants from pylink:

200 - Sample data 0x3F/0 - No data available

Parameters:

write_to_edf (bool) – Write data to edf-file as messages

Returns:

(timestamp, raw_data)

Return type:

tuple[int | float, list | None]

start_sample_thread()[source]

Start the sample thread for continuous sampling.

Return type:

None

stop_sample_thread()[source]

Stop sample thread and wait for it to finish.

Return type:

None

start_raw_thread()[source]

Start the raw thread for continuous raw data collection.

Return type:

None

stop_raw_thread()[source]

Stop raw thread and wait for it to finish.

Return type:

None

shutdown()[source]

Shutdown the thread pool executor gracefully.

Return type:

None

flush_samples()[source]

Clear the sample buffer.

Return type:

None