def cleanup(): if app.config['use_biopac']: lj = U3() lj.setFIOState(0,0) lj.setFIOState(1,0) lj.close() return "Cleaned up."
def biopac(): if app.config['use_biopac']: lj = U3() lj.setFIOState(0,1) lj.setFIOState(1,0) lj.close() return "Biopac"
def bioback_triger(sleep_time): lj = U3() # Get calibration info and turn FIO 0 to off (usually starts as ON) cal_data = lj.getCalibrationData() if lj.getFIOState(0) == 1: lj.setFIOState(0, 0) #Make sure we start with the trigger off # At onset of event toggle FIO 0 to ON lj.setFIOState(0, 1) time.sleep(sleep_time) # At offset of event toggle FIO 0 to OFF lj.setFIOState(0, 0)
def linkSession(): if app.config['use_biopac']: lj = U3() lj.setFIOState(0,0) lj.setFIOState(1,0) lj.setFIOState(2,0) lj.close() # Turn trigger on if not checkValidOrigin(request): return badOriginResponse labUserId = request.form.get("labUserId") psiturkUid = request.form.get("psiturkUid") psiturkWorkerId = request.form.get("psiturkWorkerId") wave = request.form.get("wave") if not (labUserId or (psiturkUid and psiturkWorkerId)): return badRequestResponse resuming = True session = retrieveOpenSession(labUserId = labUserId, psiturkWorkerId = psiturkWorkerId) # Start a new session if no open one was found if not session: resuming = False session = startNewSession(labUserId = labUserId, psiturkUid = psiturkUid, psiturkWorkerId = psiturkWorkerId, wave = wave) if not session: return failureResponse validStim = validStimuliForUser(labUserId = labUserId, psiturkWorkerId = psiturkWorkerId) # Make stimuli JSON-serializable stimPrims = [] for thisStim in validStim: primObj = { "id": thisStim.id, "filename": thisStim.filename, "duration": thisStim.duration, "modality": thisStim.modality, "tags": thisStim.tags, "tagOrder": thisStim.tagOrder } stimPrims.append(primObj) respDict = { "sessionId": session.id, "resuming": resuming, "validStim": stimPrims, "emotions": json.loads(session.emotions) if session.emotions else None, # Avoid trying to JSON-parse nothing "sequence": remainingSequenceForSession(session) } response = jsonify(respDict) return response
def __init__(self, sub_n): self.subjectID = sub_n # get subject number # create a time stamp at the bigining of the run date=datetime.datetime.now() self.time_stamp = str(date.day) + str(date.month) + str(date.year) + str(date.hour) + str(date.minute) + str(date.second) # create file and folder for the run cwd = os.getcwd() fileName = cwd + '/data/cb1Reversal_' + str(self.subjectID) + '_' + str(self.time_stamp) if not os.path.isdir('data/'): os.makedirs('data/') self.dataFile = open(fileName+'.csv', 'w') #writes headers for the output file self.dataFile.write('Sub,Group,time,Trial_n,Condition,color,US,FixationOnset,StimulusOnset,USOnset,reversal\n') # create a window object self.win = visual.Window(color=[0,0,0], screen = 1, fullscr=True, mouseVisible = False) #initiate a trial counter self.trial_n = 0 self.lj = U3() self.lj.setFIOState(6,1) self.lj.setFIOState(0,0) self.reversed=False # creates the visual objects for the experiment self.fixation=visual.Circle(self.win, radius=10, fillColor='black',lineColor='black',units = 'pix') self.rect = visual.Rect(self.win,units="norm",width=0.5,height=0.5,fillColor='black',lineColor='Grey',pos=(0,0)) self.Text = visual.TextStim(self.win,text="US", pos=(0,0), font='Courier New', alignHoriz = 'center', alignVert = 'center', color = 'black',units = 'norm') # base on subject number subjects are divided to group A and B (%2) and color order (%4<=1) if self.subjectID % 2 == 0: self.group = "A" else: self.group = "B" if self.subjectID % 4 <= 1: self.stim = {"CSplus":"blue","CSminus":"yellow"} else: self.stim={"CSplus":"yellow","CSminus":"blue"}
# Check to see if u3 is calibrated correctly with: cal_data = biopac.getCalibrationData() # Check to see the data at the FIO, EIO, and CIO ports: biopac.getFeedback(u3.PortStateWrite(State = [0, 0, 0])) try: from psychopy.hardware.labjacks import U3 # from labjack import u3 except ImportError: import u3 # Function defining setData to use the FIOports (address 6000) def biopacSetData(self, byte, endian='big', address=6000): if endian=='big': byteStr = '{0:08b}'.format(byte)[-1::-1] else: byteStr = '{0:08b}'.format(byte) [self.writeRegister(address+pin, int(entry)) for (pin, entry) in enumerate(byteStr)] biopac = U3() biopac.setData = biopacSetData # Set all FIO bits to digital output and set to low (i.e. “0") # The list in square brackets represent what’s desired for the FIO, EIO, CIO ports. We will only change the FIO port's state. biopac.configIO(FIOAnalog=0, EIOAnalog=0) biopac.setData(biopac, byte=0) """ 1. Experimental Parameters Paths, etc. """ # Paths # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__)) os.chdir(_thisDir) main_dir = _thisDir
import time from ctypes import windll from psychopy import parallel import psychopy labjack library from psychopy.hardware.labjacks import U3 # Initialize labjack lj = U3() # Get calibration info and turn FIO 0 to off (usually starts as ON) cal_data = lj.getCalibrationData() if lj.getFIOState(0) == 1: lj.setFIOState(0,0) #Make sure we start with the trigger off # At onset of event toggle FIO 0 to ON lj.setFIOState(0,1) # At offset of event toggle FIO 0 to OFF lj.setFIOState(0,0) ''' port = parallel.ParallelPort() print port port.setData(0) print port.readData() port.readPin(2) port.setPin(2, 10) port.setData(45) # sets all pins low
def biopac_run_off(): if app.config['use_biopac']: lj = U3() lj.setFIOState(1,0) lj.close() return "Run off"