Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
RF: Swith from getters/setters to properties
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechenberger committed Dec 21, 2016
1 parent 0da239c commit 956f623
Showing 1 changed file with 88 additions and 56 deletions.
144 changes: 88 additions & 56 deletions pphelper/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,16 @@ def __init__(self, exp_name, participant, config_file,
If ``True``, the network connection to the PyCorder computer will
not actually be initialized.
Defaults to ``False``.
Attributes
----------
config_file
exp_name
participant
block
mode
recording
"""
self._test_mode = test_mode

Expand All @@ -1147,7 +1157,20 @@ def __init__(self, exp_name, participant, config_file,
self._socket = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
self._socket.settimeout(1)
self._connect()

self.config_file = config_file
self.exp_name = exp_name
self.participant = participant
self.mode = 'default'
self.block = None
self._recording = None

def __del__(self):
self._socket.close()
del self

def _connect(self):
try:
self._socket.connect((self._pycorder_host, self._pycorder_port))
except socket.error:
Expand All @@ -1158,18 +1181,6 @@ def __init__(self, exp_name, participant, config_file,
else:
pass

self._config_file = config_file
self._exp_name = exp_name
self._participant = participant
self._block = 1
self._mode = 'default'
self._recording = False
self._setup_pycorder()

def __del__(self):
self._socket.close()
del self

def _send(self, message):
# Append \r\n if it's not already part of the message: PyCorder
# uses these characters as command separators.
Expand All @@ -1181,7 +1192,20 @@ def _send(self, message):
else:
pass

def set_config_file(self, path):
@property
def config_file(self):
"""
The absolute path to the configuration file.
:getter: Return the currently set configuration file path.
:setter: Set the configuration file path. Must be an absolute path.
:type: string
"""
return self._config_file

@config_file.setter
def config_file(self, path):
"""
Set the path to the configuration file. An absolute path is required.
Expand All @@ -1202,81 +1226,77 @@ def set_config_file(self, path):

self._config_file = path

def set_exp_name(self, name):
@property
def exp_name(self):
"""
Set the name of the experiment or study.
The name will make up the first part of the EEG filename.
Parameters
----------
path : string
The name of the study or experiment, e.g., `'MyStudy2'`.
:type: string
The name of the experiment or study. The name will make up the first
part of the EEG filename.
"""
msg = '2%s' % name
return self._exp_name

@exp_name.setter
def exp_name(self, value):
msg = '2%s' % value
self._send(msg)
time.sleep(1.2)

self._exp_name = name
self._exp_name = value

def set_participant(self, participant):
@property
def participant(self):
"""
Set the participant identifier.
:type: int or string
This identifier will make up the center part of the EEG filename.
Parameters
----------
participant : int or string
The participant identifier, e.g., `123`.
The participant identifier.
"""
return self._participant

@participant.setter
def participant(self, participant):
msg = '3%s_%s' % (participant, self._block)
self._send(msg)
time.sleep(1.2)

self._participant = participant

def set_block(self, block):
@property
def block(self):
"""
Set the number of the current block.
:type: int or string
The number of the current block.
This number will make up the last part of the EEG filename.
Parameters
----------
block : int, or string
The block number, e.g., `1` or `2`.
"""
return self._block

@block.setter
def block(self, block):
msg = '3%s_%s' % (self._participant, block)
self._send(msg)
time.sleep(1.2)

self._block = block

def _setup_pycorder(self):
self.set_mode('default')
self.set_config_file(self._config_file)
self.set_exp_name(self._exp_name)
self.set_participant(self._participant)
self.set_block(self._block)

def set_mode(self, mode):
@property
def mode(self):
"""
Set the current mode.
:type: string
Parameters
----------
mode : string
The mode to switch to. `impedance` and `imp` will switch to
impedance mode, while `monitoring` and `mon` will switch to
monitoring mode. `default and `def` will exit impedance and
monitoring mode.
The current display and operational mode.
`impedance` and `imp` will select impedance mode, while `monitoring`
and `mon` will select monitoring mode. `default and `def` will exit
impedance and monitoring mode.
"""
return self._mode

@mode.setter
def mode(self, mode):
if (mode == 'impedance') or (mode == 'imp'):
self._mode = 'impedance'
msg = 'I'
Expand All @@ -1293,6 +1313,18 @@ def set_mode(self, mode):

self._send(msg)

@property
def recording(self):
"""
:type: bool
`True` if we're currently recording data, and `False` otherwise.
This property cannot be set directly. Use `start_recording()` and
`stop_recording` instead.
"""
return self._recording

def start_recording(self):
"""
Start recording EEG.
Expand Down

0 comments on commit 956f623

Please sign in to comment.