TDTPy

Module for communicating with TDT's System 3 hardware
Download

TDTPy Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL v3
  • Price:
  • FREE
  • Publisher Name:
  • Brad Buran
  • Publisher web site:
  • http://bradburan.com/

TDTPy Tags


TDTPy Description

Tucker Davis Technologies (TDT) provides an ActiveX component for configuring their real-time hardware (e.g. the RP2.1, RX6, RZ6, etc.) and handling I/O. TDTPy is a wrapper around the ActiveX component that facilitates development of Python scripts and programs (e.g. Neurobehavior) that use TDT’s hardware. One goal of this module was to provide an abstraction layer that would allow us to migrate our code over to an alternate hardware platform in the future with relatively little effort.Developer commentsI encourage those of you who use TDT’s hardware to give this module a try. The code is stable, throughly tested and currently running in several laboratories.Supported features- Simple type conversion – When configuring variables in the microcode, certain units need to be converted based on the clock frequency of the real-time processor. The wrapper will automate this conversion process.- Non-blocking I/O – With a few lines of Python code, you can easily launch the I/O and hardware communication in a subprocess to free up your main program for other tasks (e.g. visualization of the incoming data or controlling the stimulus variables). This is particularly useful for users who are downloading large (e.g. 64 or more channels of neurophysiology data) amounts of data from the hardware.- Simple continuous reads and writes – Several classes facilitate acquiring data from hardware buffers that continuously spool data as well as writing data to hardware buffers that continuously consume the data. The current state of the hardware buffer is tracked to ensure that there are no buffer overflows or underflows.- Automated scaling and decompression of data – If you commonly compress or decimate a waveform before storing it in the hardware buffers, the wrapper will inspect the microcode and automatically decompress the data and record the appropriate sampling frequency when downloading from the hardware buffer. This automated functionality, however, requires certain coding conventions (see the documentation).- Error checking – Some methods on the manufacturer’s driver will silently fail (e.g. if you try to access a nonexistent variable in the microcode or attempt to write more data than the hardware buffer can hold). When the microcode is first loaded to the real-time processor, TDTPy will inspect the microcode and store some information about the variables and buffers available. This information will be used to validate all operations before passing them to the manufacturer’s ActiveX component for handling. If an invalid operation is attempted, the appropriate error is raised. When the ActiveX component does return an error (via a C-style return value), TDTPy converts it to a more Pythonic form by raising an exception.A brief example of how you would use the wrapper in your code:from tdt import DSPCircuitfrom numpy import random# Load the compiled microcode to the RZ5 processorcircuit = DSPCircuit('components/physiology.rcx', 'RZ5')# Initialize the buffers.raw_data_buffer = circuit.get_buffer('raw_data', 'r', channels=16)speaker_buffer = circuit.get_buffer('speaker', 'w')circuit.start()# Converts 0.5 sec to number of samples given the hardware sampling frequencycircuit.cset_tag('trial_duration', 0.5, 's', 'n')while True: # Acquire all new data spooled in the hardware buffer data = raw_data_buffer.read() process(data) # Find out how much space has been consumed and is now available noise = random.normal(size=speaker.available()) # Write some new data to these slots speaker.write(noise)Launching the data acquisition in a second process is as simple as substituting DSPProcess for DSPCircuit.from tdt import DSPProcesscircuit = DSPProcess('components/physiology.rcx', 'RZ5')raw_data_buffer = circuit.get_buffer('raw_data', 'r', channels=16)speaker_buffer = circuit.get_buffer('speaker', 'w')circuit.start()In the above example, when circuit.start() is called, the child process launches, configures the processor and starts continuously polling the hardware buffers at a regular interval. All new data is saved to a shared memory space. The raw_data_buffer monitors this shared memory space. Each time raw_data_buffer.read() is called, the buffer checks to see if new data has been written to the shared memory space by the child process and returns a copy of this data.Product's homepage


TDTPy Related Software