bpod = Bpod()

# Loop handler function is used to flush events for the online plotting
bpod.loop_handler = bpod_loop_handler
# Soft code handler function can run arbitrary code from within state machine
bpod.softcode_handler_function = softcode_handler
# Rotary Encoder State Machine handler
rotary_encoder = [x for x in bpod.modules if x.name == 'RotaryEncoder1'][0]
# ROTARY ENCODER SEVENTS
# Set RE position to zero 'Z' + eneable all RE thresholds 'E'
# re_reset = rotary_encoder.create_resetpositions_trigger()
re_reset = 1
bpod.load_serial_message(
    rotary_encoder,
    re_reset,
    [
        RotaryEncoder.COM_SETZEROPOS,  # ord('Z')
        RotaryEncoder.COM_ENABLE_ALLTHRESHOLDS
    ])  # ord('E')
# Stop the stim
re_stop_stim = re_reset + 1
bpod.load_serial_message(rotary_encoder, re_stop_stim, [ord('#'), 1])
# Show the stim
re_show_stim = re_reset + 2
bpod.load_serial_message(rotary_encoder, re_show_stim, [ord('#'), 2])
# Close loop
re_close_loop = re_reset + 3
bpod.load_serial_message(rotary_encoder, re_close_loop, [ord('#'), 3])

# =============================================================================
# TRIAL PARAMETERS AND STATE MACHINE
        sph.start_camera_recording()


# =============================================================================
# CONNECT TO BPOD
# =============================================================================
bpod = Bpod()
# Soft code handler function can run arbitrary code from within state machine
bpod.softcode_handler_function = softcode_handler
# Rotary Encoder State Machine handle
rotary_encoder = [x for x in bpod.modules if x.name == "RotaryEncoder1"][0]
# ROTARY ENCODER EVENTS
rotary_encoder_reset = 1
bpod.load_serial_message(
    rotary_encoder,
    rotary_encoder_reset,
    [RotaryEncoder.COM_SETZEROPOS, RotaryEncoder.COM_ENABLE_ALLTHRESHOLDS
     ],  # ord('Z')
)  # ord('E')
# Stop the stim
re_stop_stim = rotary_encoder_reset + 1
bpod.load_serial_message(rotary_encoder, re_stop_stim, [ord("#"), 1])
# Show the stim
re_show_stim = rotary_encoder_reset + 2
bpod.load_serial_message(rotary_encoder, re_show_stim, [ord("#"), 2])
# Shwo stim at center of screen
re_show_center = rotary_encoder_reset + 3
bpod.load_serial_message(rotary_encoder, re_show_center, [ord("#"), 3])
if sph.SOFT_SOUND is None:
    # SOUND CARD
    sound_card = [x for x in bpod.modules if x.name == "SoundCard1"][0]
    # Play tone
Esempio n. 3
0
# =============================================================================
# CONNECT TO BPOD
# =============================================================================
bpod = Bpod()

# Loop handler function is used to flush events for the online plotting
bpod.loop_handler = bpod_loop_handler
# Rotary Encoder State Machine handler
rotary_encoder = [x for x in bpod.modules if x.name == 'RotaryEncoder1'][0]
sound_card = [x for x in bpod.modules if x.name == 'SoundCard1'][0]
# ROTARY ENCODER SEVENTS
# Set RE position to zero 'Z' + eneable all RE thresholds 'E'
# re_reset = rotary_encoder.create_resetpositions_trigger()
re_reset = 1
bpod.load_serial_message(rotary_encoder, re_reset,
                         [RotaryEncoder.COM_SETZEROPOS,  # ord('Z')
                          RotaryEncoder.COM_ENABLE_ALLTHRESHOLDS])  # ord('E')
# Stop the stim
re_stop_stim = re_reset + 1
bpod.load_serial_message(rotary_encoder, re_stop_stim, [ord('#'), 1])
# Show the stim
re_show_stim = re_reset + 2
bpod.load_serial_message(rotary_encoder, re_show_stim, [ord('#'), 2])
# Close loop
re_close_loop = re_reset + 3
bpod.load_serial_message(rotary_encoder, re_close_loop, [ord('#'), 3])
# Play tone
sc_play_tone = re_reset + 4
bpod.load_serial_message(sound_card, sc_play_tone, [ord('P'), sph.GO_TONE_IDX])
# Play noise
sc_play_noise = re_reset + 5
Esempio n. 4
0
Example adapted from Josh Sanders' original version on Sanworks Bpod repository
"""

import time

from pybpodapi.protocol import Bpod

my_bpod = Bpod()

print("Send byte 65 on UART port 1 - by default, this is ASCII 'A'")
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT, Bpod.ChannelNames.SERIAL, 1,
                        65)
time.sleep(1)  # Wait 1s

print("Set byte 65 ('A') on UART port 1 to trigger a 3-byte message: 'BCD'")
my_bpod.load_serial_message(1, 65, [66, 67, 68])
# Now, the same command has a different result
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT,
                        Bpod.ChannelNames.SERIAL,
                        channel_number=1,
                        value=65)
time.sleep(1)  # Wait 1s

print("Reset the serial message library. Bytes will now pass through again.")
my_bpod.reset_serial_messages()
# Back to 'A'
my_bpod.manual_override(Bpod.ChannelTypes.OUTPUT,
                        Bpod.ChannelNames.SERIAL,
                        channel_number=1,
                        value=65)