Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-jam committed Feb 19, 2016
1 parent f5f421b commit 64ec85a
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 51 deletions.
62 changes: 62 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
12 changes: 1 addition & 11 deletions parallel_port_trigger/info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ controls:
label: "Value"
name: "value_widget"
tooltip: "Value to set port"
type: "spinbox"
min_val: 1
max_val: 255
type: "line_edit"
var: "pp_value"
-
label: "Duration"
name: "duration_widget"
tooltip: "Expecting a value in milliseconds"
type: "spinbox"
min_val: 0
max_val: 1000000000
var: "pp_duration"
-
label: "Port Adress"
name: "port_widget"
Expand Down
82 changes: 42 additions & 40 deletions parallel_port_trigger/parallel_port_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from libopensesame.item import item
from libqtopensesame.items.qtautoplugin import qtautoplugin

from openexp.keyboard import keyboard

if os.name == 'posix':
# import the local modified version of pyparallel
# that allows for non-exclusive connections to the parport
Expand Down Expand Up @@ -61,16 +59,16 @@ class parallel_port_trigger(item):
"""

# Provide an informative description for your plug-in.
description = u'Experiment Manager Plugin'
description = u'Parallel Port Trigger Plug-in'

def reset(self):

"""Resets plug-in to initial values."""

# Set default experimental variables and values
self.var.pp_value = 0
self.var.pp_duration = 500
self.var.pp_dummy = u'no'

if os.name == 'nt':
self.var.pp_port = u'0x378'
else:
Expand All @@ -80,29 +78,30 @@ def reset(self):
# --debug argument.
debug.msg(u'Parallel Port Trigger plug-in has been initialized!')


def prepare(self):

"""Preparation phase"""

# Call the parent constructor.
item.prepare(self)

if self.var.pp_dummy == u'no':
try:
if os.name == 'nt':
self.pp = windll.dlportio
else:
self.pp = parallel.Parallel()
except OSError:
print(u'Could not access the parallel port on address: %s' % self.var.pp_port)
if self.pp_dummy == u'no':
if not hasattr(self.experiment, "pp"):
try:
if os.name == 'nt':
self.experiment.pp = windll.dlportio
else:
self.experiment.pp = parallel.Parallel()

self.experiment.cleanup_functions.append(self.close)
self.python_workspace[u'pp'] = self.experiment.pp
except:
raise osexception(
_(u'Could not access the Parallel Port'))
elif self.var.pp_dummy == u'yes':
print(u'Dummy mode enabled, prepare phase')
debug.msg(u'Dummy mode enabled, prepare phase')
else:
print(u'Error with dummy mode, mode is: %s' % self.var.pp_dummy)

# create keyboard object
self.kb = keyboard(self.experiment, keylist=['escape'])
debug.msg(u'Error with dummy mode, mode is: %s' % self.var.pp_dummy)

def run(self):

Expand All @@ -113,32 +112,35 @@ def run(self):

# Set the pp value

if self.var.pp_dummy == u'no' and self.var.pp_duration != 0:
if self.var.pp_dummy == u'no':
## turn trigger on
if os.name == 'nt':
self.set_item_onset(self.pp.DlPortWritePortUchar(int(self.var.pp_port,0), self.var.pp_value))
self.set_item_onset(self.experiment.pp.DlPortWritePortUchar(int(self.var.pp_port,0), self.var.pp_value))
else:
self.set_item_onset(self.pp.setData(self.var.pp_value))
print(u'Sending value %s for %s ms to the parallel port on address: %s' % (self.var.pp_value,self.var.pp_duration,self.var.pp_port))

# use keyboard as timeout, allowing for Escape presses to abort experiment
self.kb.get_key(timeout=self.var.pp_duration)

# turn trigger off
if os.name == 'nt':
self.pp.DlPortWritePortUchar(int(self.var.pp_port,0), 0)
else:
self.pp.setData(0)
elif self.var.pp_dummy == u'no' and self.var.pp_duration == 0:
print(u'Duration is set to 0, so not doing anything')
elif self.var.pp_dummy == u'yes' and self.var.pp_duration != 0:
print(u'Dummy mode enabled, NOT sending value %s for %s ms to the parallel port on address: %s' % (self.var.pp_value,self.var.pp_duration,self.var.pp_port))
elif self.var.pp_dummy == u'yes' and self.var.pp_duration == 0:
print(u'Dummy mode enabled, duration is set to 0, so not doing anything')
self.set_item_onset(self.experiment.pp.setData(self.pp_value))
debug.msg(u'Sending value %s to the parallel port on address: %s' % (self.var.pp_value,self.var.pp_port))
elif self.var.pp_dummy == u'yes':
debug.msg(u'Dummy mode enabled, NOT sending value %s to the parallel port on address: %s' % (self.var.pp_value,self.var.pp_port))
else:
print(u'Error with dummy mode or duration')
# Report success
return True
debug.msg(u'Error with dummy mode!')

def close(self):

"""
desc:
Neatly close the connection to the buttonbox.
"""

if not hasattr(self.experiment, "bb") or \
self.experiment.bb is None:
debug.msg("no active Buttonbox")
return
try:
self.experiment.bb.close()
self.experiment.bb = None
debug.msg("buttonbox closed")
except:
debug.msg("failed to close buttonbox")


class qtparallel_port_trigger(parallel_port_trigger, qtautoplugin):
Expand Down
Binary file added parallel_port_trigger/parallel_port_trigger.pyc
Binary file not shown.
Binary file added parallel_port_trigger/parallelppdev.pyc
Binary file not shown.

0 comments on commit 64ec85a

Please sign in to comment.