Skip to content

Commit

Permalink
Merge branch 'feature/load-serial-messages-to-modules'
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Jan 18, 2018
2 parents d5b3279 + 1a47fb8 commit 6661c16
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
14 changes: 7 additions & 7 deletions pybpodapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# !/usr/bin/python3
# -*- coding: utf-8 -*-

__version__ = "1.5.3"
__author__ = ['Ricardo Ribeiro', 'Carlos Mão de Ferro', 'Joshua Sanders']
__credits__ = ["Ricardo Ribeiro", "Carlos Mao de Ferro"]
__license__ = "Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>"
__maintainer__ = ['Ricardo Ribeiro', 'Carlos Mão de Ferro','Joshua Sanders']
__email__ = ['ricardojvr@gmail.com', 'cajomferro@gmail.com', 'joshua21@gmail.com']
__status__ = "Development"
__version__ = "1.5.4"
__author__ = ['Ricardo Ribeiro', 'Carlos Mão de Ferro', 'Joshua Sanders']
__credits__ = ["Ricardo Ribeiro", "Carlos Mao de Ferro"]
__license__ = "Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>"
__maintainer__ = ['Ricardo Ribeiro', 'Carlos Mão de Ferro','Joshua Sanders']
__email__ = ['ricardojvr@gmail.com', 'cajomferro@gmail.com', 'joshua21@gmail.com']
__status__ = "Development"


from pysettings import conf
Expand Down
5 changes: 4 additions & 1 deletion pybpodapi/bpod/bpod_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pybpodapi.bpod.hardware.hardware import Hardware
from pybpodapi.bpod.hardware.channels import ChannelType
from pybpodapi.bpod.hardware.channels import ChannelName

from pybpodapi.bpod.hardware.events import EventName

from pybpodapi.com.messaging.end_trial import EndTrial
from pybpodapi.com.messaging.trial import Trial
Expand Down Expand Up @@ -39,6 +39,9 @@ class BpodBase(object):
:ivar bool new_sma_sent: whether a new state machine was already uploaded to Bpod box
"""

class Events(EventName): pass


CHECK_STATE_MACHINE_COUNTER = 0

def __init__(self, serial_port=None, sync_channel=None, sync_mode=None):
Expand Down
10 changes: 9 additions & 1 deletion pybpodapi/bpod/bpod_com_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pybpodapi.com.arcom import ArCOM, ArduinoTypes


from pybpodapi.bpod_modules.bpod_module import BpodModule
from pybpodapi.com.protocol.send_msg_headers import SendMessageHeader
from pybpodapi.com.protocol.recv_msg_headers import ReceiveMessageHeader

Expand Down Expand Up @@ -39,6 +39,8 @@ def __init__(self, serial_port=None, sync_channel=None, sync_mode=None):
self._arcom = None # type: ArCOM
self.bpod_com_ready = False

self.msg_id_list = [False for i in range(255)]#used to keep the list of msg ids sent using the load_serial_message function



def start(self):
Expand Down Expand Up @@ -348,6 +350,12 @@ def _bpodcom_load_serial_message(self, serial_channel, message_id, serial_messag
:param TODO
:rtype: bool
"""
self.__bpodcom_check_com_ready()

if isinstance(serial_channel, BpodModule):
serial_channel = serial_channel.serial_port

self.msg_id_list[message_id] = True

if len(serial_message) > 3:
raise BpodErrorException('Error: Serial messages cannot be more than 3 bytes in length.')
Expand Down
2 changes: 1 addition & 1 deletion pybpodapi/bpod/bpod_com_protocol_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _bpodcom_get_modules_info(self, hardware):
events_names.append(event_name)


bpod_modules += BpodModules.create_module(connected, module_name, firmware_version, events_names, n_serial_events)
bpod_modules += BpodModules.create_module(connected, module_name, firmware_version, events_names, n_serial_events, serial_port=i+1)


if (modules_requested_events.sum()+n_serial_events)>hardware.max_serial_events:
Expand Down
12 changes: 10 additions & 2 deletions pybpodapi/bpod_modules/bpod_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class BpodModule(object):

def __init__(self, connected=False, module_name='', firmware_version=0, events_names=[], n_serial_events=0):
def __init__(self, connected=False, module_name='', firmware_version=0, events_names=[], n_serial_events=0, serial_port=None):
self.name = module_name
self.serial_port = serial_port
self.connected = connected
self.firmware_version = firmware_version
self.event_names = events_names
Expand All @@ -18,7 +19,14 @@ def __str__(self):
return "{0} (connected: {1})(firmware: {2})".format(self.name, self.connected, self.firmware_version)



def load_message(self, msg):
for i in range(255):
if not self.bpod_modules.bpod.msg_id_list[i]:
msg_id = i
break

self.bpod_modules.bpod.load_serial_message(self.serial_port, msg_id+1, msg)
return msg_id+1

def start_module_relay(self):

Expand Down
6 changes: 3 additions & 3 deletions pybpodapi/bpod_modules/bpod_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __iter__(self):
return iter(self.modules)

@staticmethod
def create_module(connected, module_name, firmware_version, events_names, n_serial_events):
def create_module(connected, module_name, firmware_version, events_names, n_serial_events, serial_port):
from pybpodapi.bpod_modules.bpod_module import BpodModule #solve issue related with circular imports

if len(BpodModules.LOADED_MODULES)==0 and len(conf.PYBPOD_API_MODULES)>0:
Expand All @@ -35,9 +35,9 @@ def create_module(connected, module_name, firmware_version, events_names, n_seri

for mclass in BpodModules.LOADED_MODULES:
if mclass.check_module_type(module_name):
return mclass(connected, module_name, firmware_version, events_names, n_serial_events)
return mclass(connected, module_name, firmware_version, events_names, n_serial_events, serial_port)

return BpodModule(connected, module_name, firmware_version, events_names, n_serial_events)
return BpodModule(connected, module_name, firmware_version, events_names, n_serial_events, serial_port)


def activate_module_relay(self, module):
Expand Down
3 changes: 3 additions & 0 deletions pybpodapi/protocol/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pybpodapi.bpod import Bpod
from pybpodapi.state_machine import StateMachine
from pybpodapi.bpod.hardware.output_channels import OutputChannel

0 comments on commit 6661c16

Please sign in to comment.