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
-
Install PyUSB and libusb:
pip install pyusb sudo apt-get install libusb-1.0-0-dev
-
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
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ni_usb_6501-0.0.3.tar.gz.
File metadata
- Download URL: ni_usb_6501-0.0.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bec9bb8b3e7b1c7f5a9dcea9456ecb9992a42d63be2f83de2132bc7a8b455e3
|
|
| MD5 |
5f3123d9321fc7aab5cc2224ae49aacd
|
|
| BLAKE2b-256 |
3e0ccc92dcd2943d590aaac4af983c84ddb57fd845815b496d5b7168f05dff13
|
File details
Details for the file ni_usb_6501-0.0.3-py3-none-any.whl.
File metadata
- Download URL: ni_usb_6501-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43e52b70f8d4ee701f1e3951bad1dcb717221a57277e887e08651b3306da3459
|
|
| MD5 |
011f9d8320d6e1d68e065082a077727a
|
|
| BLAKE2b-256 |
5df1cfd850552ba353362bcc00153469be00680d3e3c208eaeeb9dafdda8c00c
|