How to write custom attributes (ATTRS{attribute_name} to a USB-Device?

218 Views Asked by At

I have 2 identical devices which I want to differentiate using udev rules.

However, after executing the following for the devices, I have found out that the Serial Number is missing from the given hardware for 1 device.

For every device this number should be unique and visible.

When the good one only is connected it shows the Serial Number,

$ udevadm info -a -p  $(udevadm info -q path -n /dev/ttyUSB0) | grep -i Serial
ATTRS{serial}=="XXXXXXXX"

When the faulty one only is connected it does not show serial number.

$ udevadm info -a -p  $(udevadm info -q path -n /dev/ttyUSB1) | grep -i Serial

$

When the good one only is connected:

$ ls /dev/serial/by-id/*
/dev/serial/by-id/usb-FTDI_DEVICE-NAME_XXXXXXXX-if00-port0

When the faulty one only is connected:

$ ls /dev/serial/by-id/*
/dev/serial/by-id/usb-FTDI_DEVICE-NAME_-if00-port0

So is there a way to add a custom attribute to these devices, so I can differentiate them using udev rules?

Something like a command or a program to do

$ attribute_writing_binary /dev/tty_device_path "ATTRS{custom_attribute}=value" 
0

There are 0 best solutions below