Skip to main content

API for EVT-2 USB devices

Project description

pyevt - A Python API for the Event-Exchanger EVT-2 USB hardware

1. About

This repository contains the API to communicate with EVT-2 USB-devices (+derivatives) developed by the Research Support group of the faculty of Behavioral and Social Science from the University of Groningen. The EVT-2 is a TTL event marking/TTL triggering device intended for computer-based psychology experiments.

2. Dependencies

The pyevt API uses HIDAPI, a cython module to communicate with HID-class USB devices.

3. Install

Install pyevt (and hidapi) with:

pip install pyevt or

pip install --user pyevt on managed computers.

4. Device Permission for Linux

Permission for using EVT (HID) devices should be given by adding the next lines to a file, for example named:

99-evt-devices.rules in /etc/udev/rules.d:

# /etc/udev/rules.d/99-evt-devices.rules

# All EVT devices
SUBSYSTEM=="usb", ATTR{idVendor}=="0004", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0008", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0009", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0114", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0208", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0308", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0408", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0508", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0604", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0808", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0909", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="1803", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="1807", MODE="0660", GROUP="plugdev"

The user should be a member of the plugdev -group.

Check with:

$ groups username

If this is not the case, add the user to the plugdev group by typing:

$ sudo usermod -a -G plugdev username

5. EventExchanger Class — API Summary

Device Management

Method Description
scan(matching_key="EventExchanger") Lists connected HID devices whose product name contains matching_key. Returns a list of device info dicts.
attach_name(matching_key="EventExchanger") Attaches the first device whose product name contains matching_key.
attach_id(path) Attaches a device using its unique HID path.
close() Closes the currently attached device.
reset() Sends a reset command to the device and disconnects it from USB.

Event & Data Retrieval

Method Description
wait_for_event(allowed_event_lines, timeout_ms) Waits for digital input events matching the given bit mask. Returns (event_code, elapsed_ms), or (-1, elapsed_ms) on timeout.
get_axis() Reads the current axis position value from the device.

Digital Output Control

Method Description
write_lines(value) Sets digital output lines to the specified bit pattern (0–255).
pulse_lines(value, duration_ms) Pulses output lines for the given duration in milliseconds (0-65535).
clear_lines() Clears (sets low) all output lines.

Analog & Encoder Control

Method Description
set_analog_event_step_size(samples_per_step) Configures analog event step size.
renc_init(encoder_range, min_value, position, input_change, pulse_divider) Initializes rotary encoder parameters.
renc_set_pos(position) Sets the current rotary encoder position.

LED Control

Method Description
set_led_rgb(red, green, blue, led_number, mode) Sets RGB color for a specific LED.
send_led_rgb(num_leds, mode) Sends LED color data to the device.

6. Python coding examples

from pyevt import EventExchanger

myevt = EventExchanger()
# Get list of devices containing the partial string 'partial_device_name'
myevt.scan('partial_device_name') # The default is 'EventExchanger'.

# Create a device handle:
myevt.attach_name('partial_device_name') # Example: 'EVT02', 'SHOCKER' or 'RSP-12', etc. The default is 'EventExchanger'.

myevt.write_lines(0) # clear outputs
myevt.pulse_lines(170, 1000) # value=170, duration=1000ms

# remove device handle
myevt.close()

# connect RSP-12 button response box
myevt.attach_name('RSP-12')
myevt.wait_for_event(3, None) # wait for button 1 OR 2, timeout is infinite.
myevt.close() # remove device handle

7. License

The pyevt API is distributed under the terms of the GNU General Public License 3. The full license should be included in the file COPYING, or can be obtained from

http://www.gnu.org/licenses/gpl.txt

The pyevt API contains the work of others.

8. Other documentation

Information about EVT-devices and OpenSesame plugins:

https://markspan.github.io/evtplugins/

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

pyevt-0.2.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

pyevt-0.2.1-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file pyevt-0.2.1.tar.gz.

File metadata

  • Download URL: pyevt-0.2.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/6.8.0-71-generic

File hashes

Hashes for pyevt-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fcad8fbdce4677b8400740de21597392fffda82b0cbbf11748ea3c5586d896c2
MD5 d529c5cd3e4a5f423cbaa4a0c0d1c484
BLAKE2b-256 052bbe01210bbc0744fa468ce73a0261d24599533bf4b4104f2d8e8b23a9b1f1

See more details on using hashes here.

File details

Details for the file pyevt-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyevt-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/6.8.0-71-generic

File hashes

Hashes for pyevt-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb73905df4cb7f44cf1407a7b220add49f987882905d759a2bb287454bf24071
MD5 2736654890ceb1092540345b23748809
BLAKE2b-256 71614d16a232b15dacd8737f50cdd5aa0ffa8c882c7ca2ea98b057aaf8e2a6a2

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