Skip to main content

A Python driver for the NI USB 6501 I/O Module

Project description

NI USB 6501 Python Driver

This package provides a Python driver for configuring and controlling the NI USB 6501 I/O module.

Prerequisites

Linux

  1. Install PyUSB and libusb:

    pip install pyusb
    sudo apt-get install libusb-1.0-0-dev
    
  2. Set up udev rules to allow non-root access to the device:

    sudo sh -c 'echo "SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"3923\", ATTRS{idProduct}==\"718a\", MODE=\"0666\"" > /etc/udev/rules.d/99-ni_usb_6501.rules'
    sudo udevadm control --reload-rules
    sudo udevadm trigger
    

    This will grant all users read and write permissions to the device.

Windows

  1. Install the WinUSB driver for the NI USB-6501 device using Zadig.

Installation

Download the .whl file from the Releases page and install it using: pip install <filename>.whl

Usage

from ni_usb_6501 import NIUSB6501

# Instantiate the NIUSB6501 driver
device = NIUSB6501()

# Pin-to-bit mapping:
# Each port has 8 pins, and the most significant bit (MSB) corresponds to the highest pin number:
# Port 0: Pin 7 (MSB) -> Bit 7, Pin 6 -> Bit 6, ..., Pin 0 (LSB) -> Bit 0
# Port 1: Pin 15 -> Bit 7, ..., Pin 8 -> Bit 0
# Port 2: Pin 23 -> Bit 7, ..., Pin 16 -> Bit 0

# Set IO modes: Ports 0 and 1 as output, port 2 as input
# 0xFF -> 11111111: All pins set to output
# 0x00 -> 00000000: All pins set to input
device.set_io_mode(0xFF, 0xFF, 0x00)

# Write to ports 0 and 1:
# Port 0: Set pins 7, 6, 5, 4 to HIGH (1) and pins 3, 2, 1, 0 to LOW (0)
device.write_port(0, 0b11110000)  # 0xF0
print("Port 0: Set pins 7, 6, 5, 4 to HIGH, pins 3, 2, 1, 0 to LOW.")

# Port 1: Set pins 15, 13, 11, 9 to HIGH (1) and pins 14, 12, 10, 8 to LOW (0)
device.write_port(1, 0b10101010)  # 0xAA
print("Port 1: Set alternating HIGH and LOW starting from pin 15 (MSB).")

# Read from port 2:
# The returned value will represent the HIGH/LOW state of pins 23 to 16 (bits 7 to 0 of port 2).
input_value = device.read_port(2)
print(f"Port 2 input (pins 23 to 16): {bin(input_value)}")

# Perform additional operations:
# Toggle port 0 pins between 0b00001111 and 0b11110000
device.write_port(0, 0b00001111)  # Set pins 3, 2, 1, 0 to HIGH
print("Port 0: Set pins 3, 2, 1, 0 to HIGH, pins 7, 6, 5, 4 to LOW.")

# Read and display input from port 2 again
input_value = device.read_port(2)
print(f"Port 2 input after toggle: {bin(input_value)}")

# Release the device resources
device.release_interface()
print("Device released.")

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

ni_usb_6501-0.0.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

ni_usb_6501-0.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file ni_usb_6501-0.0.2.tar.gz.

File metadata

  • Download URL: ni_usb_6501-0.0.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for ni_usb_6501-0.0.2.tar.gz
Algorithm Hash digest
SHA256 29036e4475d6b157e239b1a5e8e81453735836f049469ef649207e4ecec447bd
MD5 df3524485f959bbd2f62196a9f75f417
BLAKE2b-256 3394aaf8b81b12d2f2eff0915254551ba69398011a759a72d704e9afbcc7e036

See more details on using hashes here.

File details

Details for the file ni_usb_6501-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ni_usb_6501-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for ni_usb_6501-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 90586a9324022dbb33f429735416878f1979dbedc3a887f5585fe2a011b18861
MD5 6ef755fe42c7d5a2b2d10257ab9436df
BLAKE2b-256 d4013aa19fe37eb127b262b1751c057d6035d920f868c4b036f6a997ae15fcf9

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