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.4.tar.gz (5.2 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.4-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ni_usb_6501-0.0.4.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for ni_usb_6501-0.0.4.tar.gz
Algorithm Hash digest
SHA256 2b361b87f94241359cace7644f78c824a0e5a01b761d54bedacbab670659c7f6
MD5 1d7f71f7a1019020701237122173bdde
BLAKE2b-256 c527fb6ceb7b3d61af865ba59900b6bdb305dcd7db575a082d82415fca317356

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ni_usb_6501-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for ni_usb_6501-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 751335502e6cc7038549f412df594a8ae94bcdaa38544cabd1c03977879c0f51
MD5 2e524831c2a9c7616e4213772795d43e
BLAKE2b-256 9a978f9445433bc1b311b74650280a8dfdccc07c0e9e0e7ff9b1b7e3f3ef0fbf

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