Persistant name in usb device which open several connections || connect USB to specific port [duplicate] - linux

This question already has an answer here:
Change default names for USB virtual serial ports in Linux
(1 answer)
Closed 5 years ago.
I am trying to add a persistent name to a USB device connection to be able to connect to it by writing /dev/multitech instead of /devttyACMx. I have been able to do so with other devices by adding an udev rule, for example:
SUBSYSTEM=="tty", ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="0021",ATTRS{serial}=="356136967675473", SYMLINK+="multitech"
The problem is that this device open 6 connections, from ttyACM0 to ttyACM5 (if nothing else connected) but to use it you have to use the ttyACM0 (meaning the first connection) but if you write:
$ ls -l /dev/multitech
you may get whatever connection it has open, maybe ttyACM0 or maybe ttyACM3... the thing is that this is useless for me, since it sometimes works and sometimes it does not. Is there anything I can do about this?
Thanks a lot!!

normally each connection the device establishes has its own interface or alternate setting in USB tree structure. in udev rules you can use several other attributes (all you can display using udevadm info --attribute-walk http://www.beyondlogic.org/usbnutshell/usb5.shtml#InterfaceDescriptors )
run an attribute walk with udevadm info --attribute-walk + /sys/class/... or /dev/... path for your device to see the identifiers of the several usb interfaces it has in its usb structure and try to include them in the udev rule, i.e. using the following attributes:
ATTRS{bAlternateSetting}=="..."
ATTRS{bInterfaceClass}=="..."
ATTRS{bInterfaceNumber}=="..."
ATTRS{bInterfaceProtocol}=="..."
ATTRS{bInterfaceSubClass}=="..."
try to assign a specific /dev/ttyACMx for any interface the device has in its usb structure and try to assign the top-level interface in the usb structure to /dev/ttyACM0 ...
http://weininger.net/how-to-write-udev-rules-for-usb-devices.html

Change default names for USB virtual serial ports in Linux
This post was the solution to my troubles, instead of using the /devttyACMx
y changed to used the names in /dev/serial/by-id/
up until now it has worked fine, if it stops doing it I will post it

Related

udev rule generating symlink for USB-device using ATTRS{serial} in link name

I have a udev rule that generates symlinks for my USB devices in /dev according to their serial number (I have multiple otherwise identical devices but need reproducible device endpoints).
Currently I need to add a rule for every new serial number, like this:
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{serial}=="S101", SYMLINK+="ttyS101"
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{serial}=="S102", SYMLINK+="ttyS102"
...
I'm looking for a way to do this with a single rule, all that is dynamically accessible is %k, %n, and %c, but I found no way to access any other values. Using PROGRAM="" might be the way, but how would I access ATTRS from there?
I tried this:
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{serial}=="S101", PROGRAM="/bin/sh -c 'udevadm info /dev/%k | grep ID_SERIAL_SHORT= | cut -d= -f 2'" SYMLINK+="tty%c"
but it looks like /dev/%k is not available when the program runs, so that doesn't work either.
Is there any way to use ATTRS{serial} for my SYMLINK+=""?
It looks like you are using USB serial ports. It should be easier for you to just access these devices via the symbolic links in /dev/serial/by-id. There is no need to make udev rules.

How to select a particular USB port on raspberry pi 3B+ to program two arduino boards with arduino-mk?

I have a python program on my Raspberry pi 3B+ witch updates an Arduino mega2560 and an Arduino Uno by using Arduino-mk through bash commands. Each Arduino has its own code folder with its code (.ino) and a Makefile which looks like:
ARDUINO_DIR = /usr/share/arduino
ARDUINO_PORT = /dev/ttyUSB0 (here is the problem)
USER_LIB_PATH = /home/pi/sketchbook/libraries
BOARD_TAG = mega2560 (Uno for the uno one)
include /usr/share/arduino/Arduino.mk
When I call the following command:
os.system("(cd ~/sketchbook/mega; make upload clean)")
with only the mega connected on the USB port everything works and the mega gets programed (same with Uno only). but when I try to get both done:
os.system("(cd ~/sketchbook/mega; make upload clean)")
os.system("(cd ~/sketchbook/uno; make upload clean)")
arduino-mk can't program the Uno (multiple timeouts).
At first the second line in Makefile was:
ARDUINO_PORT = /dev/ttyAMC0
but it was not working so I checked on the web and found that some Arduino copies worked better with:
ARDUINO_PORT = /dev/ttyUSB0
Then it worked but I couldn't get any result with ttyUSB1 up to ttyUSB3 (I hoped it would work like COM ports on windows).
I also noticed that if I keep testing with ttyUSB0 and try with each physical USB port and worked so ttyUSB0 refers to the four physical ports right?
Please how can I get one particular port name?
Or is there an other way to make Arduino-mk work?
Plug in one device at a time and look at the output of ls -l /dev/serial/by-id/, you should see a symlink to the actual device node, but uniquely named for your specific device.
You can then set ARDUINO_PORT=/dev/serial/by-id/unique_name in the respective makefiles.

PyUSB Barcode Scanner without Button by Honeywell

I have a Honeywell N5600 that I'm trying to use, but I don't get it to scan anything.
The device is recognized as /dev/hidraw1, but as it does not have any button to press, I cannot trigger the scan and thus, when I try to read from it, it just waits forever.
I started creating a python program, that seems to be able to communicate with it (different return values):
VENDOR_LEGO = 0x0c2e
PRODUCT_EV3 = 0x0967
device = usb.core.find(idVendor=VENDOR_LEGO, idProduct=PRODUCT_EV3)
device.detach_kernel_driver(0)
#"TRGMOD8." would - when scanned (which I cannot do, at this point) - activate a permanent scanning mode
device.ctrl_transfer(0x21, 0x9, wValue=0x200, wIndex=0x00, data_or_wLength='TRGMOD8.')
#8 is returned
device.ctrl_transfer(0x21, 0x9, wValue=0x200, wIndex=0x00, data_or_wLength='PAPSPC.')
#7 is returned
Unluckily the link given in this post is not reachable anymore. It seems like it would have solved my problem.
How can I activate the scanning?
The document on Honeywell N5600 is as follows.
N5600 OEM 2D Imager Data Sheet
N56XX Decoded Engine User's Guide
You need a Windows PC that can connect to the Internet, but there is a tool called EZConfig-Scanning that configures and maintains the scanner.
EZConfig Device Management Data Sheet
Perhaps the recognition device /dev/hidraw1 is probably because the scanner is set to USB HID Bar Code Scanner mode.
If you change the setting to USB Keyboard(PC/Mac), it is always readable and the barcode you read will be notified as keyboard input.
By changing the setting to USB Serial, reading start/stop can be controlled by SerialPort command transmission. The barcode read is notified by receiving data from SerialPort.

Weird URI string displayed on mounting iPod

I have written a small program to detect whenever a device is mounted on a desktop running Linux. I have used GIO for this. I am extracting the URI of the mounted resource and displaying it to the user. When I put in a CD I get a URI string which looks like file:///media/cdrom0/ which I can understand. But when I mount an iPod the URI I see is something like gphoto2://[usb:002,028]. What does this mean? I have observed that the second number (028) keeps increasing every time I take the device out and plug it back in. Can some one interpret this URI for me?
Update: As shodanex answered, the two numbers are the bus number and device number respectively. gphoto2:// indicates the protocol (PTP/MTP).
gphoto2://[usb:002,028]
I guess 002 is the bus number, and 28 is the adress of the device on that bus.
It maps to the second and fourth field of the lsusb util output. Here is an example
on my system :
Bus 001 Device 015: ID 05e3:0715 Genesys Logic, Inc. USB 2.0 microSD Reader
I guess it would translate to :
usb:001,015
I have these kinds of URL's in Nautilus too, but the other response doesn't explain how that relates to a mount location on disk. I can navigate through the files on an SD card via the Nautilus file browser, but I don't see any of these files in /mnt/ or /media/ or anywhere else I would typically look for automatically mounted file systems.
Eventually I tried right-clicking the folder, selecting "Open with other application," choosing a text editor, and then I could see that the folder was actually mounted at:
'~/.gvfs/gphoto2 mount on usb%3A001,010'
I wish Nautilus and other tools in ubuntu would provide some more obvious way to find these files... this seems pretty un-intuitive.

How do I make my default (or any static) route permanent on Linux (Fedora 9 specifically)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I've just performed a new installation of the very latest (Fall, 2008) version of Fedora 9 Linux and am perplexed that it never set the default route properly and that even traveling the labyrinthine ways of this OS, there's no obvious way.
Of course, it's clear that one can do it on a one-off basis like this:
route add default gw gw1 metric 0 eth0
or like this:
ip route add to default via 192.168.2.1 protocol static
However, neither of these survives reboot. In reading through /etc/rc.d/init.d/network, it attempts to find data from a file in /etc/sysconfig/static-routes, but that file never existed. So, I tried to create it and populate it with data. The trouble with that is that the script places a dash (minus sign) in an odd spot that I'm not sure how to deal with.
Of course, one can just edit /etc/rc.d/init.d/network, but that would be non-standard. As it is, my only other recourse seems to be editing rc.local, but that doesn't come early enough in the boot sequence to be there for things like, for example, the network time daemon.
I've done my homework - I've read all the man pages, info entries, tried apropos, and I've even done a fair bit of web searching, all to no avail - my next step, sans answer here, will be to sign up to the Fedora mailing lists and ask there! Or, give up and edit the scripts.
So, how is one supposed to do this?
The gateway is normally set in /etc/sysconfig/network-scripts/ifcfg-eth0, not in /etc/sysconfig/network. For example, on my current machine:
/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=flyboys
NISDOMAIN=ekcineon
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
HWADDR=00:1d:09:31:3a:cc
NETMASK=255.255.255.0
IPADDR=150.102.65.30
GATEWAY=150.102.65.252
TYPE=Ethernet
Note that I set HWADDR because I have two ethernet cards and I want to make sure the right one is assigned to eth0. The configuration for the second card is in /etc/sysconfig/network-scripts/ifcfg-eth1
just edit the /etc/sysconfig/network-scripts/route-ethXX
and write inside: default via ip_address dev device , replace ip_address with your gateway ip and device with the name of the right eth device. but for the Device option its ... optional, set it in the case of multiple eth devices.
Works even in case of network restart, the route directive in rc.local works at boot only.
I have not used recent versions of Fedora, but it was often set as a GATEWAY variable in /etc/sysconfig/network.
Of course, if you just wanted it to work, you could just put the commands in /etc/rc.local to be executed when the boot sequence completes.
You can use nmcli if available, e.i.
# nmcli con show
NAME UUID TYPE DEVICE
System eth0 xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ethernet eth0
ens33 xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ethernet --
# nmcli con edit "System eth0"
nmcli> goto ipv4
You may edit the following properties: method, dns, dns-search, dns-options, dns-priority, addresses, gateway, routes, route-metric, route-table, routing-rules, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-timeout, dhcp-send-hostname, dhcp-hostname, dhcp-fqdn, never-default, may-fail, dad-timeout
nmcli ipv4>
nmcli ipv4> print
['ipv4' setting values]
ipv4.method: manual
ipv4.dns: --
ipv4.dns-search: --
ipv4.dns-options: --
ipv4.dns-priority: 0
ipv4.addresses: 10.10.10.1/26
ipv4.gateway: 10.10.10.129
ipv4.routes: --
ipv4.route-metric: -1
ipv4.route-table: 0 (unspec)
ipv4.routing-rules: --
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0 (default)
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
nmcli ipv4>
nmcli ipv4> set routes 192.168.122.0/24 10.10.10.1
nmcli ipv4> verify
Verify setting 'ipv4': OK
nmcli ipv4> save
nmcli ipv4> quit
#nmcli con up "System eth0"
And it should create file /etc/sysconfig/network-scripts/routes- with proper parameters, e.g.
ADDRESS0=192.0.2.0
NETMASK0=255.255.255.0
GATEWAY0=198.51.100.1
Haven't seen Fedora. But shouldn't there be some GUI for this kind of thing? If you have Gnome try running gnome-network-preferences
Here it is for RHEL, as it is slightly different:
Identify the interface by using ifconfig
sudo vi /etc/sysconfig/network-scripts/route-ethXX
add the routes as per syntax below, where /xx represents subnet mask
host: 172.30.xxx.xxx via 172.30.xxx.xxx
network: 172.30.xxx.xxx/xx via 172.30.xxx.xxx
Default gateway: 0.0.0.0 via xxx.xxx.xxx.xxx</li>
Save the file.
sudo /etc/init.d/network restart (Warning: if you forget to set
correct routes for the management interface (if applicable) you may lose
connectivity to the server)

Resources