Event Listening

These are functions that helps on programming simple and customized behaviour on a simple trigger event on a specified inputPin.

Listen for Default Simple to BNCO

Configures the BNC output to automatically respond to signals received on a custom inputPin

from trgenpy import TrgenClient

client = TrgenClient()
client.connect()

# Respond to positive edge (default)
# default input inputPin is BNCI
# send default Trigger to BNCO
client.callbackCustomTrigger(inputPin=TrgenPin.BNCI)

# Program a behaviour that send default trigger when BNCI (default) is on negative edge
client.callbackCustomTrigger(ne=True,inputPin=TrgenPin.BNCI)

# Program a behaviour that send default trigger when NS6 is on negative edge
client.callbackCustomTrigger(ne=True,inputPin=TrgenPin.NS6)

# Program a behaviour that send default trigger when GPIO2 is on positive edge (default True)
# it automatically set the global GPIO direction to "input" 
client.callbackCustomTrigger(ne=True,inputPin=TrgenPin.GPIO2)

# Remember to call .start(), because this is just Port programming
# Start listening
client.start()

Listen for Markers

Configures the GPIO connector (in “input direction” mode) to respond to signals received on a specific GPIO pin.

Marker arguments

Same parametrization of standard sendMarkers:

  • markerNS: for NeuroScan ports

  • markerSA: for Synamps ports

  • markerGPIO: for GPIO ports

# Program a behaviour that send default trigger when GPIO2 is on negative edge
# Also set the Global GPIO direction to "input"
client.callbackMarker(ne=True, markerNS=50,inputPin=TrgenPin.GPIO2)

# Start listening
client.start()

NOTE

It’s not allowed to send GPIO markers when the inputPin is GPIO

# THIS WILL GENERATE ERRORS
client.callbackMarker(ne=True, markerGPIO=13,inputPin=TrgenPin.GPIO2)

# Like:
# ❌ GPIO cannot be used as both input and output simultaneously

Listen for Custom Triggers

Configures a custom output pin to respond to a specific inputPin of type TrgenPin

# Program a default trigger to Neuroscan 7 and Synamps 8 pins on a negative front edge from the BNCI port
client.callbackCustomTrigger(ne=True, trgenPinList=[TrgenPin.NS7,TrgenPin.SA8], inputPin=TrgenPin.BNCI))

# Start listening
client.start()

# Advanced configuration: use custom instruction set
# Configuration with custom instructions
instruction_set = [
    istrWaitPE(TrgenPin.BNCI),      # Wait for positive edge on BNCI
    istrActiveFor(50),           # Active for 50µs
    istrUnactiveFor(10),         # Inactive for 10µs
    istrActiveFor(30),           # Active for 30µs
    istrUnactiveFor(20),         # Inactive for 20µs
    istrActiveFor(20),           # Active for 20µs
    istrUnactiveFor(30),         # Inactive for 30µs
    istrEnd()                        # End program
]

# Program a custom trigger on GPIO8 and BNCO on a positive edge front (default when not specified) with a custom instruction set
client.callbackCustomTrigger(trgenPinList=[TrgenPin.GPIO8,TrgenPin.BNCO], inputPin=TrgenPin.BNCI,customInstructions=instruction_set)

# Start listening
client.start()

NOTE

Programming custom trigger does not include the automatic start. It’s always recommended to invoke the start() function once your custom instruction set is written