Skip to main content

A Python library used to communicate with TrGen devices.

Project description

trgenpy

A Python library for IIT's TriggerBox device 🐍.

Getting started

To install this package use is required Python >= 3.9

pip install trgenpy

Client

The TriggerClient is the object that stores all the information about the socket connection between you and the TriggerBox.
You can instantiate the TriggerClient object like this:

client = TriggerClient() 

Once the client object is created you can connect to Trgen Device...

client.connect()

...or check device availability

isAavailable = client.is_available() # true / false

Single Trigger Send

To send a defaul trigger signal (positive square with a logic state of 20µs) you can use the sendTrigger() function:

client.sendTrigger()

Custom Trigger Send

If you want to send trigger to a custom list inside the pinout you can use the sendCustomTrigger() function:

client.sendCustomTrigger([TriggerPin.NS0,TriggerPin.GPIO0])

Sending Markers

In order to send a marker value to all (Neuroscan,Synamps and GPIO) ports you can use the sendMarker() function:

client.sendMarker(13)

if you want invert the bit order, just flag the LSB argument (Trueby default)

client.sendMarker(13,LSB=False)

if you want to send different markers simultaiously on different ports you can use the arguments:

  • markerNS
  • markerSA
  • markerGPIO

like this:

client.sendMarker(markerNS=8,markerSA=2,markerGPIO=15)

Trigger

The Trigger object defines a single trigger behaviours through its id. This is the list of supported trigger_id values for the TriggerBox:

Trigger ID List

  • Neuroscan IDs The Neuroscan pinout (only for used pins) goes from 0 to 7
    • [NS0,NS1,NS2,NS3,NS4,NS5,NS6,NS7]
  • Synamps IDs The Neuroscan pinout (only for used pins) goes from 0 to 7
    • [SA0,SA1,SA2,SA3,SA4,SA5,SA6,SA7]
  • TMSI/O IDs
    • TMSO
    • TMSI
  • GPIO IDs The GPIO pinout goes from 0 to 7
    • [GPIO0,GPIO01,GPIO02,GPIO03,GPIO04,GPIO05,GPIO06,GPIO07]

You can instantiate the Trigger object with:

neuroScan = TriggerClient.create_trigger(TriggerPin.NS3)

passing ad only argument the constant from TriggerPin

Now you're ready to define the instruction set for Trigger with the set_instruction() function. Each trigger has a memory property, a list that can contain 32 instructions, so this function is defined:

def set_instruction(self, index, instruction):
# index: 0-32 value
# instruction: instruction_code

Each instruction code can be encoded using the Instruction Helpers

# call the function directly on the same Trigger object
neuroScan.set_instruction(0, active_for_us(5))
neuroScan.set_instruction(1, unactive_for_us(3))
# ...

Instruction Helpers

The supported instruction set for Trgen is:

Instruction 1° Param 2° Param Description
unactive_for_us(us) µ seconds duration Set the unactivation time for µ seconds
active_for_us(us) µ seconds duration Set the activation time for µ seconds
wait_pe(tr) Trigger ID Wait the positive edge for a specific Trigger ID
wait_ne(tr) Trigger ID Wait the negative edge for a specific Trigger ID
repeat(addr,time) Instruction address Time of repeat Set the activation time for µ seconds
end() End the behaviour
not_admissible() Empty instruction, it has to be placed after the end()

NOTE

Each Trigger can support a list of N instructions, where N = 2^MTML (Max Trigger Memory Length)

You can access to the mtml value by

# Add this in try block to manage errors
try:
    impl = client.get_implementation()
    mtml = impml.mtml
except InvalidAckError as e:
    print(f"⚠️ ACK sbagliato: {e}")
except AckFormatError as e:
    print(f"⚠️ ACK malformato: {e}")
except TimeoutError as e:
    print(f"⏱️ Timeout: {e}")

Native Commands

IIT's TriggerBox can receive some commands, the full instruction set includes:

  • Program Trigger
  • Start Trigger
  • Set GPIO I/O Direction
  • Request Implementation parameters
  • Request Trgen Status
  • Set the Trigger level
  • Get GPIO I/O Direction
  • Get the Trigger Level
  • Stop the Triggers

Program Trigger

Start Trigger

Set GPIO I/O Direction

Request Implementation

Request Trgen Status

Set the Trigger level

Get the GPIO I/O Direction

Get the Trigger Level

E-Prime integration via Python COM-visible

Install pywin32

pip install pywin32

TODO continue...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trgenpy-0.0.5.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trgenpy-0.0.5-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file trgenpy-0.0.5.tar.gz.

File metadata

  • Download URL: trgenpy-0.0.5.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for trgenpy-0.0.5.tar.gz
Algorithm Hash digest
SHA256 451ed64cae2f8f5b812866104e361675299f84cb8e2c3a75db993e2105c2b019
MD5 2a46558823842a836199f2d1648bccd0
BLAKE2b-256 0d172a9f624eb8f2ce1f429df680cd9ebea63b7108c68a3e2bc141f4b9c9929d

See more details on using hashes here.

File details

Details for the file trgenpy-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: trgenpy-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for trgenpy-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 349d6bdf025d00fed5fee28133e474e998294f48ab7c36c5457d373f1b62d196
MD5 e95e06761874a0b46169321f39cba6d8
BLAKE2b-256 f069f6605f54748dbfd7334c391660ac402aba39d23c19434a1feb0a70b9c371

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page