Personal tools

Difference between revisions of "Fixed name for USB device"

From PhotoVoltaic Logger new generation

Jump to: navigation, search
m (Solution)
m (Solution)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:HowTo]]
 +
[[Category:Hardware]]
 
== Problem ==
 
== Problem ==
  
Line 14: Line 16:
 
<cite>[[Wikipedia:Udev]]</cite></blockquote>
 
<cite>[[Wikipedia:Udev]]</cite></blockquote>
  
At 1st find out information about your device:
+
Find out information about your device
  
  $ sudo udevadm info --query=all --name=/dev/ttyUSB0
+
  # sudo udevadm info --query=all --name=/dev/ttyUSB0
  
Look for these lines:
+
Look for these lines
  
 
  P: /devices/pci0000:00/0000:00:13.1/usb3/3-2/3-2:1.0/ttyUSB0/tty/ttyUSB0
 
  P: /devices/pci0000:00/0000:00:13.1/usb3/3-2/3-2:1.0/ttyUSB0/tty/ttyUSB0
Line 24: Line 26:
 
  N: ttyUSB0
 
  N: ttyUSB0
 
  ...
 
  ...
  E: SUBSYSTEM='''tty'''
+
  E: SUBSYSTEM=<span style="color:red">tty</span>
 
  ...
 
  ...
  E: ID_SERIAL_SHORT='''FTGCYLSS'''
+
  E: ID_SERIAL_SHORT=<span style="color:blue">FTGCYLSS</span>
 
  ...
 
  ...
 +
 +
To enable udev to select the correct adapter, the <tt>ID_SERIAL</tt> or the <tt>ID_SERIAL_SHORT</tt> entry is used.
  
 
Choose a (for you :-) meaningful device name.
 
Choose a (for you :-) meaningful device name.
  
I use <tt>usb-ftdi-1</tt> because its my only serial adapter, all others are for 1-Wire.
+
I use <tt>usb-ftdi-1</tt> because its my only serial adapter, all others are for 1-Wire. I also played with the idea of <tt>consumption-watt-meter-s0</tt> ...
 +
 
 +
Put this definition
  
I also played with the idea of <tt>consumption-watt-meter-s0</tt>...
+
SUBSYSTEM=="<span style="color:red">tty</span>", ENV{ID_SERIAL_SHORT}=="<span style="color:blue">FTGCYLSS</span>", SYMLINK+="usb-ftdi-1"
  
Create a rules file
+
into a rules file
  
  $ sudo echo 'SUBSYSTEM=="'''tty'''", ENV{ID_SERIAL_SHORT}=="'''FTGCYLSS'''", SYMLINK+="usb-ftdi-1"' >/etc/udev/rules.d/99-usb-S0.rules
+
  # sudo echo 'SUBSYSTEM=="'''tty'''", ENV{ID_SERIAL_SHORT}=="'''FTGCYLSS'''", SYMLINK+="usb-ftdi-1"' >>/etc/udev/rules.d/99-usb.rules
  
 
Restart udev
 
Restart udev
  
  $ sudo udevadm trigger
+
  # sudo udevadm trigger
  
 
Check
 
Check
  
  $ sudo ls -al /dev/u*
+
  # sudo ls -al /dev/u*
 
   lrwxrwxrwx 1 root root    7  9. Feb 21:47 /dev/usb-ftdi-1 -> ttyUSB0
 
   lrwxrwxrwx 1 root root    7  9. Feb 21:47 /dev/usb-ftdi-1 -> ttyUSB0
  
Line 51: Line 57:
  
 
Put this device name into the [[Channel attributes#Channel|channel]] attribute of your Power sensor.
 
Put this device name into the [[Channel attributes#Channel|channel]] attribute of your Power sensor.
 +
  
 
[[File:S0PowerSensorChannel.png]]
 
[[File:S0PowerSensorChannel.png]]
 
[[Category:HowTo]]
 
[[Category:Hardware]]
 

Latest revision as of 20:51, 31 August 2014

Problem

If you have no more a real serial port on your system, you will have to use in most cases a USB-serial adapter.

If you have more than adapter, the device (/dev/ttyUSB?) assigned to the adapter during boot time is not in every cases the same.

But it is required to have for the PVLng scripts to have always the same device...

Solution

udev

udev is a device manager for the Linux kernel. Primarily, it manages device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load. Wikipedia:Udev

Find out information about your device

# sudo udevadm info --query=all --name=/dev/ttyUSB0

Look for these lines

P: /devices/pci0000:00/0000:00:13.1/usb3/3-2/3-2:1.0/ttyUSB0/tty/ttyUSB0
...
N: ttyUSB0
...
E: SUBSYSTEM=tty
...
E: ID_SERIAL_SHORT=FTGCYLSS
...

To enable udev to select the correct adapter, the ID_SERIAL or the ID_SERIAL_SHORT entry is used.

Choose a (for you :-) meaningful device name.

I use usb-ftdi-1 because its my only serial adapter, all others are for 1-Wire. I also played with the idea of consumption-watt-meter-s0 ...

Put this definition

SUBSYSTEM=="tty", ENV{ID_SERIAL_SHORT}=="FTGCYLSS", SYMLINK+="usb-ftdi-1"

into a rules file

# sudo echo 'SUBSYSTEM=="tty", ENV{ID_SERIAL_SHORT}=="FTGCYLSS", SYMLINK+="usb-ftdi-1"' >>/etc/udev/rules.d/99-usb.rules

Restart udev

# sudo udevadm trigger

Check

# sudo ls -al /dev/u*
  lrwxrwxrwx 1 root root    7  9. Feb 21:47 /dev/usb-ftdi-1 -> ttyUSB0

Here you can see, that the adapter is at he moment also /dev/ttyUSB0

Put this device name into the channel attribute of your Power sensor.


S0PowerSensorChannel.png