Skip to content

Commit

Permalink
Update session variables
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed May 15, 2018
1 parent 67017d8 commit 87c3183
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 82 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This is Open Source software. We use the `GNU General Public License version 3 <

1. Duplicate *user_settings.py.template* and save it as *user_settings.py*

Define the SERIAL_PORT attribute with your machine serial port where Bpod is connected to
Define the PYBPOD_SERIAL_PORT attribute with your machine serial port where Bpod is connected to
Define the API_LOG_LEVEL with logging.DEBUG if you want detailed logging for the API

2. On the project root folder run:
Expand Down
5 changes: 2 additions & 3 deletions docs/source/about/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ Maintenance team

The current and past members of the **pybpod-api** team.

* `@cajomferro <https://github.com/cajomferro/>`_ Carlos Mão de Ferro
* `@JBauto <https://github.com/JBauto>`_ João Baúto
* `@UmSenhorQualquer <https://github.com/UmSenhorQualquer/>`_ Ricardo Ribeiro
* `@sergio-copedo <https://bitbucket.org/sergio-copeto/>`_ Sérgio Copeto

Questions?
==========
If you have any questions or want to report a problem with this library please fill a issue `here <https://bitbucket.org/fchampalimaud/pybpod-api/issues>`_.
If you have any questions or want to report a problem with this library please fill a issue `here <https://bitbucket.org/fchampalimaud/pybpod/issues>`_.


.. Changes log
Expand Down
65 changes: 29 additions & 36 deletions docs/source/getting_started/installing.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. pybpodapi documentation master file, created by
.. pybpodapi documentation master file, created by
sphinx-quickstart on Wed Jan 18 09:35:10 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Expand All @@ -9,26 +9,21 @@
Installing
**********

.. note::

To install the **full pybpod package**, please follow the instructions located @ `Pybpod <http://pybpod.readthedocs.org>`_.


.. warning::
This project uses Python 3!

Download project
Clone the project from Bitbucket
================


Option A. Clone project from Bitbucket:
---------------------------------------

::

git clone https://bitbucket.org/fchampalimaud/pybpod-api


Option B. Download zip
----------------------

https://bitbucket.org/fchampalimaud/pybpod-api/get/master.zip

Install files
=============

Expand All @@ -45,27 +40,25 @@ Settings file

::

# list of python libraries to interfaces bpod modules.
PYBPOD_API_MODULES = [
'pybpod_rotaryencoder_module'
]

# folder where the bpod output files are be saved
WORKSPACE_PATH = 'BPOD-WORKSPACE'

# name of the session file
PROTOCOL_NAME = now()

# serial port settings
BAUDRATE = 1312500
SYNC_CHANNEL = 255
SYNC_MODE = 1
SERIAL_PORT = '/dev/ttyACM0'

# enable or disable bpod ports
BPOD_BNC_PORTS_ENABLED = [True, True]
BPOD_WIRED_PORTS_ENABLED = [True, True]
BPOD_BEHAVIOR_PORTS_ENABLED = [True, True, True, True, True, True, True, True]



# list of python libraries to interfaces bpod modules.
PYBPOD_API_MODULES = [
'pybpod_rotaryencoder_module'
]

PYBPOD_SERIAL_PORT = '/dev/ttyACM0' # serial port settings
PYBPOD_NET_PORT = '' # network port to receive remote commands like softcodes.

# enable or disable bpod ports
BPOD_BNC_PORTS_ENABLED = [True, True]
BPOD_WIRED_PORTS_ENABLED = [True, True]
BPOD_BEHAVIOR_PORTS_ENABLED = [True, True, True, True, True, True, True, True]

PYBPOD_PROTOCOL = '' # Executed protocol
PYBPOD_CREATOR = '' # Name of the user
PYBPOD_PROJECT = '' # Name of the project
PYBPOD_EXPERIMENT = '' # Name of the experiment
PYBPOD_BOARD = '' # Board name
PYBPOD_SETUP = '' # Setup name
PYBPOD_SESSION = '' # Name of the session file
PYBPOD_SESSION_PATH = '' # Folder where the bpod output files are be saved
PYBPOD_SUBJECTS = [] # List of subjects to be saved in the session file.
6 changes: 3 additions & 3 deletions docs/source/getting_started/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Example of *'examples/user_settings.py'* file:

PYBPOD_API_LOG_LEVEL = None
WORKSPACE_PATH = 'BPOD-WORKSPACE'
PYBPOD_SESSION_PATH = 'SESSION-WORKSPACE'

# if you do not define the next variable, the PROTOCOL_NAME
# if you do not define the next variable, the PYBPOD_SESSION
# will assume the current datetime value.
PROTOCOL_NAME = 'PROTOCOL-NAME'
PYBPOD_SESSION = 'SESSION-NAME'

SERIAL_PORT = '/dev/ttyACM0'

Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Welcome to pybpod-api's documentation!

What is pybpod-api?
===================
**pybpod-api** is a Python library that enables communication with the latest `Bpod device <https://sanworks.io/shop/viewproduct?productID=1011>`_ version. You can use it directly as a CLI (Command Line Interface) or use your favorite GUI to interact with it.
**pybpod-api** is a Python library that enables communication with the latest `Bpod device <https://sanworks.io/shop/viewproduct?productID=1011>`_ version. You can use it directly as a CLI (Command Line Interface) or use your favorite `GUI <http://pybpod.readthedocs.io>`_ to interact with it.

This library is maintained by a team of SW developers at the `Champalimaud Foundation <http://research.fchampalimaud.org>`_. Please find more information on section :ref:`Project Info <project-info-label>`.

Expand All @@ -43,7 +43,7 @@ Python is one of the most popular programming languages today `[1] <https://pypl

Questions?
==========
If you have any questions or want to report a problem with this library please fill in an issue `here <https://bitbucket.org/fchampalimaud/pybpod-api/issues>`_.
If you have any questions or want to report a problem with this library please fill in an issue `here <https://bitbucket.org/fchampalimaud/pybpod/issues>`_.

.. high level toc tree
Expand Down
10 changes: 3 additions & 7 deletions examples/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
PYBPOD_API_LOG_FILE = 'pybpod-api.log'


PYBPOD_SESSION_PATH = 'PYBPOD_SESSION_PATH'

PYBPOD_SESSION = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

SERIAL_PORT = '/dev/ttyACM0'
#SERIAL_PORT = '/dev/tty.usbmodem3174431'

PYBPOD_SESSION_PATH = 'PYBPOD_SESSION_PATH'
PYBPOD_SESSION = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

PYBPOD_SERIAL_PORT = '/dev/ttyACM0'

BPOD_BNC_PORTS_ENABLED = [True, True]
BPOD_WIRED_PORTS_ENABLED = [True, True]
Expand Down
40 changes: 24 additions & 16 deletions pybpodapi/bpod/bpod_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class ChannelNames(ChannelName): pass
def __init__(self, serial_port=None, sync_channel=None, sync_mode=None, net_port=None):
self._session = self.create_session()

self.serial_port = serial_port if serial_port is not None else settings.SERIAL_PORT
self.baudrate = settings.BAUDRATE
self.sync_channel = sync_channel if sync_channel is not None else settings.SYNC_CHANNEL
self.sync_mode = sync_mode if sync_mode is not None else settings.SYNC_MODE
self.net_port = net_port if net_port is not None else settings.NET_PORT
self.serial_port = serial_port if serial_port is not None else settings.PYBPOD_SERIAL_PORT
self.baudrate = settings.PYBPOD_BAUDRATE
self.sync_channel = sync_channel if sync_channel is not None else settings.PYBPOD_SYNC_CHANNEL
self.sync_mode = sync_mode if sync_mode is not None else settings.PYBPOD_SYNC_MODE
self.net_port = net_port if net_port is not None else settings.PYBPOD_NET_PORT
self._hardware = Hardware() # type: Hardware
self.bpod_modules = None # type: BpodModules
self.bpod_start_timestamp = None
Expand All @@ -73,21 +73,21 @@ def __init__(self, serial_port=None, sync_channel=None, sync_mode=None, net_port

self.session_timestamps = [] #Store the session timestamps in case bpod is using live_timestamps


self._hardware.sync_channel = self.sync_channel # 255 = no sync, otherwise set to a hardware channel number
self._hardware.sync_mode = self.sync_mode # 0 = flip logic every trial, 1 = every state

self.session += SessionInfo( self.session.INFO_SERIAL_PORT, self.serial_port )
if self.net_port:
self.session += SessionInfo( self.session.INFO_NET_PORT, self.net_port )

self.session += SessionInfo(self.session.INFO_CREATOR_NAME, settings.PYBPOD_CREATOR)
self.session += SessionInfo(self.session.INFO_PROJECT_NAME, settings.PYBPOD_PROJECT)
self.session += SessionInfo(self.session.INFO_SERIAL_PORT, self.serial_port )
self.session += SessionInfo(self.session.INFO_PROTOCOL_NAME, settings.PYBPOD_PROTOCOL)
self.session += SessionInfo(self.session.INFO_CREATOR_NAME, settings.PYBPOD_CREATOR)
self.session += SessionInfo(self.session.INFO_PROJECT_NAME, settings.PYBPOD_PROJECT)
self.session += SessionInfo(self.session.INFO_EXPERIMENT_NAME, settings.PYBPOD_EXPERIMENT)
self.session += SessionInfo(self.session.INFO_BOARD_NAME, settings.PYBPOD_BOARD)
self.session += SessionInfo(self.session.INFO_SETUP_NAME, settings.PYBPOD_SETUP)
self.session += SessionInfo(self.session.INFO_BOARD_NAME, settings.PYBPOD_BOARD)
self.session += SessionInfo(self.session.INFO_SETUP_NAME, settings.PYBPOD_SETUP)
self.session += SessionInfo(self.session.INFO_BPODGUI_VERSION, settings.PYBPOD_BPODGUI_VERSION)

if self.net_port:
self.session += SessionInfo( self.session.INFO_NET_PORT, self.net_port )

for subject_name in settings.PYBPOD_SUBJECTS:
self.session += SessionInfo(self.session.INFO_SUBJECT_NAME, subject_name)

Expand Down Expand Up @@ -147,8 +147,8 @@ def open(self):
if firmware_version > int(settings.TARGET_BPOD_FIRMWARE_VERSION):
raise BpodErrorException('Error: Future firmware detected. Please update the Bpod python software.')

self._hardware.firmware_version = firmware_version
self._hardware.machine_type = machine_type
self._hardware.firmware_version = firmware_version
self._hardware.machine_type = machine_type
#########################################################


Expand Down Expand Up @@ -576,6 +576,14 @@ def __update_timestamps(self, sma, state_change_indexes):
trial_end_timestamp, discrepancy = self._bpodcom_read_timestamps()
current_trial.trial_end_timestamp = trial_end_timestamp

self.session += SessionInfo(
self.session.INFO_TRIAL_BPODTIME,
trial_end_timestamp-self.trial_start_timestamp,
start_time=self.trial_start_timestamp,
end_time =trial_end_timestamp
)


if discrepancy>1:
self.session += WarningMessage( "Bpod missed hardware update deadline(s) on the past trial by ~{milliseconds}ms".format(milliseconds=discrepancy) )

Expand Down
2 changes: 2 additions & 0 deletions pybpodapi/bpod/bpod_com_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def _bpodcom_hardware_description(self, hardware):
outputs = self._arcom.read_char_array(array_len=n_outputs) # type: list(str)
logger.debug("Read outputs: %s", outputs)

print('max_states', max_states)
print('----------------------')
hardware.max_states = max_states
hardware.cycle_period = cycle_period
hardware.max_serial_events = max_serial_events
Expand Down
2 changes: 1 addition & 1 deletion pybpodapi/bpod/bpod_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, serial_port=None, workspace_path=None, session_name=None, syn

self.session += SessionInfo("This is a PYBPOD file. Find more info at http://pybpod.readthedocs.io")
self.session += SessionInfo( Session.INFO_BPODAPI_VERSION, pybpodapi.__version__)
self.session += SessionInfo( Session.INFO_PYBPOD_SESSION_NAME, self.session_name )
self.session += SessionInfo( Session.INFO_SESSION_NAME, self.session_name )
self.session += SessionInfo( Session.INFO_SESSION_STARTED, self.session.start_timestamp )

def create_session(self):
Expand Down
7 changes: 4 additions & 3 deletions pybpodapi/com/messaging/session_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ class SessionInfo(BaseMessage):
MESSAGE_TYPE_ALIAS = 'INFO'
MESSAGE_COLOR = (150,150,255)

def __init__(self, infoname, infovalue=None):
super(SessionInfo, self).__init__(infoname)
def __init__(self, infoname, infovalue=None, start_time=None, end_time=None):
super(SessionInfo, self).__init__(infoname, host_timestamp=start_time)
self._infovalue = infovalue
self._endtime = end_time

def tolist(self):
return [
self.MESSAGE_TYPE_ALIAS,
self.pc_timestamp,
self.host_timestamp,
None,
self._endtime,
self.content,
self._infovalue
]
Expand Down
2 changes: 1 addition & 1 deletion pybpodapi/com/messaging/state_occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def tolist(self):
self.start_timestamp,
self.end_timestamp,
self.content,
None
self.end_timestamp-self.start_timestamp
]

@classmethod
Expand Down
5 changes: 4 additions & 1 deletion pybpodapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ class Session(object):
MSGTYPE_WARNING = 'warning'
MSGTYPE_STATE = 'STATE'

INFO_PYBPOD_SESSION_NAME = 'PROTOCOL-NAME'
INFO_SESSION_NAME = 'SESSION-NAME'
INFO_SESSION_STARTED = 'SESSION-STARTED'
INFO_SESSION_ENDED = 'SESSION-ENDED'
INFO_SERIAL_PORT = 'SERIAL-PORT'
INFO_NET_PORT = 'NET-PORT'
INFO_BPODAPI_VERSION = 'BPOD-API-VERSION'

INFO_PROTOCOL_NAME = 'PROTOCOL-NAME'
INFO_CREATOR_NAME = 'CREATOR-NAME'
INFO_PROJECT_NAME = 'PROJECT-NAME'
INFO_EXPERIMENT_NAME = 'EXPERIMENT-NAME'
Expand All @@ -80,6 +81,8 @@ class Session(object):
INFO_SUBJECT_NAME = 'SUBJECT-NAME'
INFO_BPODGUI_VERSION = 'BPOD-GUI-VERSION'

INFO_TRIAL_BPODTIME = 'TRIAL-BPOD-TIME'


def __init__(self, path=None):
self.ostdout = sys.stdout
Expand Down
15 changes: 7 additions & 8 deletions pybpodapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@
#TARGET_BPOD_FIRMWARE_VERSION = "17" # 0.9
TARGET_BPOD_FIRMWARE_VERSION = "21"

SERIAL_PORT = None
NET_PORT = None
BAUDRATE = 1312500
SYNC_CHANNEL = 255
SYNC_MODE = 1
PYBPOD_SERIAL_PORT = None
PYBPOD_NET_PORT = None
PYBPOD_BAUDRATE = 1312500
PYBPOD_SYNC_CHANNEL = 255
PYBPOD_SYNC_MODE = 1


BPOD_BNC_PORTS_ENABLED = [True, True]
BPOD_WIRED_PORTS_ENABLED = [True, True]
BPOD_BEHAVIOR_PORTS_ENABLED = [True, True, True, True, True, True, True, True]

#SERIAL_PORT = '/dev/ttyACM0'

PYBPOD_SERIAL_PORT = ''

PYBPOD_PROTOCOL = ''
PYBPOD_CREATOR = ''
PYBPOD_PROJECT = ''
PYBPOD_EXPERIMENT = ''
PYBPOD_BOARD = ''
PYBPOD_SETUP = ''
PYBPOD_TASK = ''
PYBPOD_SESSION = ''
PYBPOD_SESSION_PATH = ''
PYBPOD_BPODGUI_VERSION = ''
Expand Down

0 comments on commit 87c3183

Please sign in to comment.