def OpenTriggerPort(port=0x0378): """ Opens connection to triggerport **Author** : Wanja Mössing, WWU Münster | [email protected] \n *August 2018* Parameters: ---------- port: hexadecimal port number. default is 0x0378 """ parallel.setPortAddress(port) parallel.setData(0) return(parallel)
def OpenTriggerPort(port=0x0378): """ Opens connection to triggerport **Author** : Wanja Mössing, WWU Münster | [email protected] \n *August 2018* Parameters: ---------- port: hexadecimal port number. default is 0x0378 """ parallel.setPortAddress(port) parallel.setData(0) return (parallel)
""" parallel ports demo This is for win32 only. """ from __future__ import division from psychopy import visual, core from psychopy import parallel nFramesOn = 5 nFramesOff = 30 nCycles = 2 parallel.setPortAddress(0x378) # address for parallel port on many machines pinNumber = 2 # choose a pin to write to (2-9). # setup the stimuli and other objects we need win = visual.Window([1280, 1024], allowGUI=False) # make a window win.flip() # present it myStim = visual.GratingStim(win, tex=None, mask=None, color='white', size=2) myClock = core.Clock() # just to keep track of time # present a stimulus for EXACTLY 20 frames and exactly 5 cycles for cycleN in range(nCycles): for frameN in range(nFramesOff): # don't draw, just refresh the window win.flip() parallel.setData(0) # sets all pins low
#!/usr/bin/env python # -*- coding: utf-8 -*- import random import time import tkinter from psychopy import visual, core, event, gui, parallel import pandas as pd import numpy as np from pylink import * import pylink # 打开端口 parallel.setPortAddress(49408) p = np.array([0.01, 0.05, 0.1, 0.25, 0.4, 0.5, 0.6, 0.75, 0.9, 0.95, 0.99]) money = np.array([(25, 0), (50, 0), (75, 0), (100, 0), (150, 0), (200, 0), (400, 0), (800, 0), (50, 25), (75, 50), (100, 50), (150, 50), (150, 100), (200, 100), (200, 150)]) # 读取初始数据 data = pd.read_csv('data.csv') data_np = data.values item = [0] * len(p) for i in range(len(p)): item[i] = data.loc[data['p'] == p[i]].values np.random.shuffle(item[i]) # 打乱每个p下的项目 # 打乱总体 np.random.shuffle(item) # 不要写[[0]*33]*5,这样赋值时会出错 block = [[0] * 33 for _ in range(5)] # 每个block 33个trial 11(p)* 3(x1 x2) for i in range(5):
testSound = sound.Sound( value=100, secs=0.1, stereo=True, volume=0.5, loops=0, sampleRate=44100, bits=16, hamming=False, start=0, stop=-1, name="", autoLog=False, ) parallel.setPortAddress(0xDFF8) # for stimpc-08, August 2016 try: parallel.setData(1) except RuntimeError: def setParallelData(code=0): pass print "Parallel port not working, check address?, Proceeding without..." else: parallel.setData(0) setParallelData = parallel.setData win = visual.Window(monitor="testMonitor", units="deg", fullscr=False) message1 = visual.TextStim(win, pos=[0, +3], text="Press any key to start...")
from __future__ import division from psychopy import visual, data, event, core, gui, parallel import time import numpy as np from numpy import random import os import math import pandas send_eegtriggers = False trigger_on_time = .01 if send_eegtriggers: # Address for the parallel port in the biosemi setup parallel.setPortAddress(0xC020) # this sends the trigger, usually initialize it at zero # then the trigger, then a wait-function for e.g. 30 ms, and zero again parallel.setData(0) time.sleep(trigger_on_time) #define amounts of everything Nstim = 2 Nresp = 2 Ntrials = 50 #Initialize data response = 0 print('initialization_ok') #make data file
# -*- coding: utf-8 -*- import time, socket import numpy import glob, os, random, sys, gc, time import psychopy from psychopy import gui from psychopy import prefs psychopy.prefs.general['audioLib'] = [u'pygame'] from psychopy import core, visual,sound,event,data,misc, logging,parallel from psychopy import visual import generateTrials from baseFoo import * from stimPresFoo import * parallel.setPortAddress(address=0xD010) #SetUp Experiment class #Set up experimental settings, subject variable, presnetation rate etc. #------------------------- class Exp: def __init__(self): self.expName = 'accPred' self.optionList = { '1': { 'name' : 'screenMode', 'prompt' : 'debug or fs', 'options': ('debug','fs'), 'default':'fs', 'type' : str}, '2' : { 'name' : 'seed',
def __init__(self,): if CONF['satori']['port_address']: parallel.setPortAddress(CONF['satori']['port_address']) # self.port = parallel.ParallelPort(address=CONF['satori']['port_address']) parallel.setData(0)
def __init__(self, port): parallel.setPortAddress(port) # set address for parallel port self.disabled = False
def send_triggers(port_address=0xC020, trigger_time=.03, init=False, sending=True, value=None): """ :param port_address: The address of the parallel port Hex :param trigger_time: How long a trigger has to be sent, keeping in mind the sampling rate Integer :param init: Initialize the EEG triggers if set to True Boolean :param sending: Send a trigger if set to True, will send the integer defined in the parameter value Boolean :param value: The trigger value sent if value is set to '255', then [255 0] will appear when looking at the ActiChamp window when triggers are sent Integer :return: Depends on the use: - Initialize triggers - Send a specific integer as trigger value :example use: send_triggers(init = True, # initialize triggers sending = False) send_triggers(value = 160) # sends trigger with value '160' Note that an error will occur if both sending and init are set to True """ try: if sending and init: raise ValueError( 'You cannot both initialize the triggers, and send at the same time' ) return 1 # fail elif not sending and not init: raise ValueError( 'You did not specify what you want to do with this function') return 1 # fail else: if init: parallel.setPortAddress( port_address ) # address of the parallel port in the Biosemi setup parallel.setData(0) # set all pins to low core.wait(trigger_time) # wait for x seconds else: if value is None: raise Exception('No value for trigger defined') return 1 # fail if not isinstance(value, int): raise Exception('Trigger value should be an integer') return 1 # fail parallel.setData(value) # sets all pins high core.wait(trigger_time) # wait for x seconds parallel.setData(0) # sets all pins low return 0 # success! except RuntimeError or NameError: print('\nLOG: sending of EEG trigger failed\nAn error occured') return 2 # exception
prefs.general['audioLib'] = ['pyo'] prefs.general['audioDriver'] = ['ASIO'] prefs.general['audioDevice'] = ['Speakers (Creative SB X-Fi)'] import numpy as np import pandas as pd import os, sys from psychopy import visual, core, event, gui, logging, sound import random import matplotlib.pyplot as plt import csv import pandas as pd from datetime import datetime from psychopy import parallel parallel.setPortAddress(0xB010) #system setup framerate = 100 #For debugging purposes only. Must be 100 for data collection if framerate != 100: print("Warning: framerate not set to 100 Hz") #get Subject ID subgui = gui.Dlg() subgui.addField("Subject ID:") subgui.show() subj = subgui.data[0] #determine counterbalance (0: left=sync, 1: right=sync) cb = int(subj) % 2
# -*- coding: utf-8 -*- import time, socket import numpy import glob, os, random, sys, gc, time import psychopy from psychopy import gui from psychopy import prefs psychopy.prefs.general['audioLib'] = [u'pygame'] from psychopy import core, visual, sound, event, data, misc, logging, parallel from psychopy import visual #import generateTrials from baseFoo import * from stimPresFoo import * parallel.setPortAddress(address=0xD010) #SetUp Experiment class #Set up experimental settings, subject variable, presnetation rate etc. #------------------------- class Exp: def __init__(self): self.expName = 'accPred' self.optionList = { '1': { 'name': 'screenMode', 'prompt': 'debug or fs', 'options': ('debug', 'fs'),
# prova ############################################################################ #########################--AFFECTIVE PRIMING--############################## ############################################################################ from psychopy import visual, data, core, event, gui, parallel import random import datetime #library to get the current date import pyglet import csv import itertools import os import demogrAno #set port parallel.setPortAddress(888) #address for parallel port on many machines = 888 #get demographics demogrAno.demographics() subj = int(demogrAno.subj) age = demogrAno.age gender = demogrAno.gender print subj, age, gender #--------------------------------------------------------------------------# #------------------------------Parameters----------------------------------# #--------------------------------------------------------------------------# win = visual.Window([1200, 800], fullscr=1, units='pix',
#!/usr/bin/env python2 #this is win32 only - I have no idea how to use parallel ports on a Mac! jwp from psychopy import visual, core, logging from psychopy import parallel nFramesOn = 5 nFramesOff = 30 nCycles = 2 parallel.setPortAddress(0x378) #address for parallel port on many machines pinNumber = 2 #choose a pin to write to (2-9). #setup the stimuli and other objects we need myWin = visual.Window([1280, 1024], allowGUI=False) #make a window myWin.flip() #present it myStim = visual.PatchStim(myWin, tex=None, mask=None, color='white', size=2) myClock = core.Clock() #just to keep track of time #present a stimulus for EXACTLY 20 frames and exactly 5 cycles for cycleN in range(nCycles): for frameN in range(nFramesOff): #don't draw, just refresh the window myWin.flip() parallel.setData(0) #sets all pins low for frameN in range(nFramesOn): myStim.draw() myWin.flip() #immediately *after* screen refresh set pins as desired parallel.setPin(2, 1) #sets just this pin to be high #report the mean time afterwards
#54121 -+sycu 6y from psychopy import parallel import serial ##### Set port address to match your local machine paddress = '/dev/parport0' # '0xDFF8' or 'COM1' in Windows ################################################## try: port = serial.Serial(paddress) port_type = 'serial' except NotImplementedError: port = parallel.setPortAddress(address=paddress) port_type = 'parallel' except: port_type = 'Not set' print('port type: {}'.format(port_type)) if port_type == 'parallel': def setParallelData(code=1): port.setData(code) print('trigger sent {}'.format(code)) elif port_type == 'serial': def setParallelData(code=1): port.write(bytes(str(code).encode())) print('trigger sent {}'.format(code)) else: def setParallelData(code=1):
units='pix') # store frame rate of monitor if we can measure it successfully expInfo['frameRate'] = win.getActualFrameRate() if expInfo['frameRate'] != None: frameDur = 1.0 / round(expInfo['frameRate']) else: frameDur = 1.0 / 60.0 # couldn't get a reliable measure so guess # Initialize components for Routine "setup" setupClock = core.Clock() import numpy import scipy import time from psychopy import parallel parallel.setPortAddress(888) wait_msg = "Waiting for Scanner..." msg = visual.TextStim(win, color='DarkGray', text=wait_msg) # Initialize components for Routine "instructions" instructionsClock = core.Clock() txt = "Escucha las siguientes definiciones y piensa sobre los conceptos a los que se refieren" text_instructions = visual.TextStim(win=win, ori=0, name='text_instructions', text='default text', font=u'Arial', pos=[0, 0], height=30, wrapWidth=None, color=u'white',
#54121 -+sycu 6y from psychopy import parallel import platform PLATFORM = platform.platform() if 'Linux' in PLATFORM: port = parallel.ParallelPort(address='/dev/parport0') # on MEG stim PC else: # on Win this will work, on Mac we catch error below try: port = parallel.setPortAddress(address='0xDFF8') #port = parallel.ParallelPort(address=0xDFF8) # on MEG stim PC except NotImplementedError: port = [] # NB problems getting parallel port working under conda env # from psychopy.parallel._inpout32 import PParallelInpOut32 # port = PParallelInpOut32(address=0xDFF8) # on MEG stim PC # parallel.setPortAddress(address='0xDFF8') # port = parallel # Figure out whether to flip pins or fake it if port: def setParallelData(code=1): port.setData(code) print('trigger sent {}'.format(code)) else: def setParallelData(code=1): print('trigger not sent {}'.format(code))