Skip to main content
Skip table of contents

The two flavours of pypixxlib

There are two general ways to interact with pypixxlib, which reflect two different programming styles. Which approach you decide to take depends on your personal preference, previous programming experience and general comfort level with coding. 

Object oriented programming (OOP)

OOP groups code elements into classes, with their own unique attributes (properties) and functions (behaviours). Broadly defined parent classes may also have child classes that contain more specific attributes and functions. For example, in PsychoPy the parent class visual contains useful attributes and functions shared by all visual elements, but it also has a child class line with attributes and functions specifically related to creating lines.

In OOP, specific instances of classes, called objects, are created and strategically called in the code. Pypixxlib has classes for all of our devices. We also have specific I/O subclasses for each of our different kinds of data acquisition and control (including audio inputs, audio outputs, digital inputs, etc.) that can be called by a device object.

Here’s a simple example where we create an instance of a DATAPixx3 object, and then call the setVolume() function of its audio subclass.

from pypixxlib.datapixx import DATAPixx3
myDevice = DATAPixx3()

OOP code tends to be elegant and efficient, but it takes time to conceptualize. If you’re interested to learn more about this style of programming, there are lots of resources available on the web.

Wondering about the final line of code in the example “writeRegisterCache?” We will cover this in more detail in the next section of the guide. 

Procedural programming

Procedural programming is a style of programming in which individual functions are called step-by-step to build a program. Procedural code is a linear set of instructions, like a recipe. The downside to this approach is that there is no way to easily modify or invoke previously-implemented code, so occasionally procedural code is less efficient.

Our tools for MATLAB are procedural, following the example of Psychtoolbox. Originally, pypixxlib kept the procedural format and the OOP tools were added later. The procedural functions can be found in a subsection of pypixxlib called libdpx. Procedural libdpx commands have a prefix, usually DPx.

Here’s the same example as before of setting audio volume, using libdpx procedural code this time: 

from pypixxlib import _libdpx as dp

Libdpx commands can be used across all VPixx devices supported by our software tools. Some device-specific functions are prefaced with variations of the DPx prefix. For example, libdpx commands for our eye tracking systems are prefaced with TPx

If you have more than one VPixx device connected by USB, such as a PROPixx projector and a PROPixx controller, libdpx commands will target the appropriate device based on the nature of the command. In the example above, DPxSetAudVolume would be sent to the PROPixx controller, as this is the device which manages audio. If you want to force libdpx to target a specific device, you can use the command DPxSelectDevice and pass the device type or name as an argument.

Procedural programming is much more intuitive for beginner programmers. The libdpx commands also closely follow the format of our MATLAB/Psychtoolbox functions, so if you are familiar with our MATLAB tools already, libdpx will feel very similar.

Ultimately, the decision of which strategy to take, OOP or procedural, is up to the user’s preferences. Both provide a solid foundation for working with our tools in Python.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.