This repository contains tools for identifying and managing USB devices on your main system.
Clone this repository to your system where you need to connect and identify specific USB devices:
git clone https://github.com/your-username/tools.git
cd tools
Description
This script creates a persistent udev rule for a specified USB device, allowing the system to recognize and assign a fixed name to it.
Usage
sudo ./create_usb_rule.sh /dev/ttyUSB0 usb_custom_name
Replace /dev/ttyUSB0 with your device path and usb_custom_name with the desired symlink name.
Quickly extracts and lists key attributes of specific USB devices.
./extract_usb_info.sh /dev/ttyUSB0
Replace /dev/ttyUSB0
with the device you want to query.
idVendor
: Device's vendor IDidProduct
: Device's product IDmanufacturer
: Device manufacturer nameserial
: Device's serial number
Generates specific udev rules based on USB device characteristics, allowing the main system to recognize and assign fixed names to these USB devices.
- Modify the
device_rule_generate.sh
script:- Add USB device characteristics (obtained from
extract_usb_info.sh
) to the designated area.
- Add USB device characteristics (obtained from
- Execute the script with sudo:
This will assign fixed names to the USB devices and take effect immediately.
sudo ./device_rule_generate.sh
# LiDAR device rule
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{manufacturer}=="Silicon Labs", SYMLINK+="usb_ydlidar", MODE="0666"
# Arduino device rule
SUBSYSTEM=="tty", ATTRS{idVendor}=="1d6b", ATTRS{idProduct}=="0002", SYMLINK+="usb_rear_wheel", MODE="0666"
This Python script automates the process of generating udev rules for USB devices. It communicates with connected devices, retrieves their custom IDs, and creates appropriate udev rules.
- Python 3.x
pyserial
library (install withpip install pyserial
)- Arduino or ESP32 devices with proper firmware (see Arduino/ESP32 Code Requirements below)
For this script to work correctly, the Arduino or ESP32 devices must include their own CUSTOM_ID and be able to respond to JSON commands. Add the following to your Arduino/ESP32 code:
// Replace with your device's unique identifier
#define CUSTOM_ID "usb_rear_wheel"
// In your main loop or command processing function:
if (doc.containsKey("command") && doc["command"] == "I") {
Serial.println(CUSTOM_ID);
}
This code allows the device to respond with its CUSTOM_ID when queried by the rule_generator.py script. The CUSTOM_ID will be used as the device's rule name in the generated udev rules.
- Ensure you have the necessary permissions to write to
/etc/udev/rules.d/
and execute udev commands. - Make sure your Arduino/ESP32 devices are programmed with the required code (as described above).
- Connect your devices to the system.
- Run the script with sudo:
sudo python3 rule_generator.py
- Automatically detects all
/dev/ttyUSB*
and/dev/ttyACM*
devices. - Communicates with each device to retrieve its custom ID.
- Generates udev rules based on the device's kernel information and custom ID.
- Reloads udev rules to apply changes immediately.
- Displays the custom ID received from each device.
- Shows the matching KERNELS information.
- Confirms the creation of udev rules for each device.
- Reports any errors encountered during the process.