<commit_before>''' Devices used in the experiment.
'''


__all__ = ('DeviceStageInterface', 'Server', 'FTDIDevChannel', 'FTDIPinBase',
           'FTDIPinSim', 'FTDIPin', 'FTDIOdorsBase', 'FTDIOdorsSim',
           'FTDIOdors', 'DAQInDeviceBase', 'DAQInDeviceSim', 'DAQInDevice',
           'DAQOutDeviceBase', 'DAQOutDeviceSim', 'DAQOutDevice')

from functools import partial

from moa.compat import bytes_type, unicode_type
from moa.threads import ScheduledEventLoop
from moa.device import Device
from moa.device.digital import ButtonPort

from pybarst.core.server import BarstServer
from pybarst.ftdi import FTDIChannel
from pybarst.ftdi.switch import PinSettings, SerializerSettings
from pybarst.mcdaq import MCDAQChannel
from moadevs.ftdi import FTDIPinDevice, FTDISerializerDevice
from moadevs.mcdaq import MCDAQDevice

from kivy.properties import ConfigParserProperty, BooleanProperty, ListProperty
from kivy.app import App
from kivy.clock import Clock

from go_nogo_rig import device_config_name


class DeviceStageInterface(object):
    ''' Base class for devices used in this project. It provides the callback
    on exception functionality which calls :meth:`ExperimentApp.device_exception`
    when an exception occurs.
    '''

    exception_callback = None
    '''The partial function that has been scheduled to be called by the kivy
    thread when an exception occurs. This function must be unscheduled when
    stopping, in case there are waiting to be called after it already has been
    stopped.
    '''

    def handle_exception(self, exception, event):
        '''The overwritten method called by the devices when they encounter
        an exception.
        '''
        callback = self.exception_callback = partial(
            App.get_running_app().device_exception, exception, event)
        Clock.schedule_once(callback)

    def create_device(self):
        '''Called from the kivy thread to create the internal target of this
        device.
        '''
        pass

    def start_channel(self):
        '''Called from secondary thread to initialize the target device. This
        is typically called after :meth:`create_device` is called.
        This method typically opens e.g. the Barst channels on the server and
        sets them to their initial values.
        '''
        pass<commit_msg>Add cancel exception to devices.<commit_after>''' Devices used in the experiment.
'''


__all__ = ('DeviceStageInterface', 'Server', 'FTDIDevChannel', 'FTDIPinBase',
           'FTDIPinSim', 'FTDIPin', 'FTDIOdorsBase', 'FTDIOdorsSim',
           'FTDIOdors', 'DAQInDeviceBase', 'DAQInDeviceSim', 'DAQInDevice',
           'DAQOutDeviceBase', 'DAQOutDeviceSim', 'DAQOutDevice')

from functools import partial

from moa.compat import bytes_type, unicode_type
from moa.threads import ScheduledEventLoop
from moa.device import Device
from moa.device.digital import ButtonPort

from pybarst.core.server import BarstServer
from pybarst.ftdi import FTDIChannel
from pybarst.ftdi.switch import PinSettings, SerializerSettings
from pybarst.mcdaq import MCDAQChannel
from moadevs.ftdi import FTDIPinDevice, FTDISerializerDevice
from moadevs.mcdaq import MCDAQDevice

from kivy.properties import ConfigParserProperty, BooleanProperty, ListProperty
from kivy.app import App
from kivy.clock import Clock

from go_nogo_rig import device_config_name


class DeviceStageInterface(object):
    ''' Base class for devices used in this project. It provides the callback
    on exception functionality which calls :meth:`ExperimentApp.device_exception`
    when an exception occurs.
    '''

    exception_callback = None
    '''The partial function that has been scheduled to be called by the kivy
    thread when an exception occurs. This function must be unscheduled when
    stopping, in case there are waiting to be called after it already has been
    stopped.
    '''

    def handle_exception(self, exception, event):
        '''The overwritten method called by the devices when they encounter
        an exception.
        '''
        callback = self.exception_callback = partial(
            App.get_running_app().device_exception, exception, event)
        Clock.schedule_once(callback)

    def cancel_exception(self):
        '''Called to cancel the potentially scheduled exception, scheduled with
        :meth:`handle_exception`.
        '''
        Clock.unshcedule(self.exception_callback)
        self.exception_callback = None

    def create_device(self):
        '''Called from the kivy thread to create the internal target of this
        device.
        '''
        pass

    def start_channel(self):
        '''Called from secondary thread to initialize the target device. This
        is typically called after :meth:`create_device` is called.
        This method typically opens e.g. the Barst channels on the server and
        sets them to their initial values.
        '''
        pass
{'fraction_non_alphanumeric': 0.06868522657996343, 'fraction_numerical': 0.0, 'mean_word_length': 3.574349442379182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5487005', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1321, 'n_words': 476}