Define a patch to each serial port - linux

I'm using CentOS 6 and I have two serial ports (two USB interfaces on two different ports), USB1 and USB2. When I connect the USB1, the OS sets her patch to "/dev/ttyACM0", and when I connect the USB2, "/dev/ttyACM1".
But when I connect first the USB2, the OS sets her patch to "/dev/ttyACM0" and no to "/dev/ttyACM1". I need that the USB1 patch be "/dev/ttyACM0" and USB2 "/dev/ttyACM1", regardless of the order that I connect the interfaces. How I do to do it?
Thank you

Create a udev rule that defines the symlink based on the attributes of the USB device (such as the serial number).
Find out information about your device-
udevadm info -n /dev/ttyACM0 -a
udevadm info -n /dev/ttyACM1 -a
Then go into /etc/udev/rules.d/ and create a udev rule. Something similar to the blurb below. Here is a good reference. For lots of examples and more discussion, do searches for udev persistent usb serial.
SUBSYSTEM=="tty", ATTRS{idVendor}=="0000", ATTRS{idProduct}=="0000", ATTRS{serial}=="000001", SYMLINK+="ACM0"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0000", ATTRS{idProduct}=="0000", ATTRS{serial}=="000002", SYMLINK+="ACM1"

Related

Blocking USB HID in Linux

I'm programming a kioks device and i want to block all usb devices expect 2 kind of usb.One is my touch screen hid usb and the other one is usb storage devices.Actually i tried write rules under udev.I tried this code :
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTR{authorized}="0"
But this one is blocking all usb devices.So i tried to add another rule to unblock specific device with product and vendor id.
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTR{idVendor}=="0eef", ATTR{idProduct}=="0005", ATTR{authorized}="1"
but this one is not working.
is there any another way to do this operation.
The problem with your approach is that it disables USB hub devices as well, and normally hub is part of the USB host controller internally. Therefore, after disabling all USB devices, you need to explicitly enable any hub devices and then the desired USB devices. This can be done as:
#By default, disable all usb devices (including hubs)
ACTION=="add", SUBSYSTEMS=="usb", RUN+="/bin/sh -c 'for host in /sys/bus/usb/devices/usb*; do echo 0 > $host/authorized_default; done'"
#Enable hub devices
ACTION=="add", ATTR{bDeviceClass}=="09", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"
#Enable desired USB devices by setting PID/VID
ACTION=="add", ATTR{idVendor}=="045e", ATTR{idProduct}=="07f8", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"
ACTION=="add", ATTR{idVendor}=="045e", ATTR{idProduct}=="0797", RUN+="/bin/sh -c 'echo 1 >/sys$DEVPATH/authorized'"
For more info, follow these links :
Setting authorized by running script,
Setting authorized using ATTR

Generic usb-serial device continuously gives 1`

I'm trying to communicate with a Di245 through its Virtual COM driver (VCD) in Linux (pdf) and I'm having a strange issue. Internally, an FTDI chipset is used by this device (FT232BL).
Attaching the device by itself isn't registered as a VCD, so I do the following:
sudo modprobe usbserial vendor=0x0683 product=0x2450
which results in the following dmesg message:
usbserial: USB Serial support registered for generic
usbserial_generic 3-3:1.0: The "generic" usb-serial driver is only for testing and one-off prototypes.
usbserial_generic 3-3:1.0: Tell linux-usb#vger.kernel.org to add your device to a proper driver.
usbserial_generic 3-3:1.0: generic converter detected
usb 3-3: generic converter now attached to ttyUSB0
and I get the /dev/ttyUSB0 device as promised. So far, everything seems ok.
However, if I open the port in my code, I get a bunch of 1` from it (alternating 1 and `). Trying with screen:
screen /dev/ttyUSB0 115200
I continuously receive 1`. This is definitely not something the device is sending and oddly enough, if I put a random baudrate, I keep getting the same thing.
Is this a way some error is being reported? What could be triggering this behavior and how can I address it?
The solution was the following:
# modprobe usbserial vendor=0x0683 product=0x2450
# modprobe ftdi_sio
# echo "0683 2450" >> /sys/bus/usb-serial/drivers/ftdi_sio/new_id
This way, the ftdi_sio driver knows which vendor/product to provide VCD for. The following udev rule (say, 99-di245.rules) can automate this:
ACTION=="add", ATTRS{idVendor}=="0683", ATTRS{idProduct}=="2450", RUN+="/sbin/modprobe ftdi_sio" RUN+="/sbin/modprobe usbserial vendor=0x0683 product=0x2450" RUN+="/bin/sh -c 'echo 0683 2450 > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'"
It is installed with:
$ sudo cp 99-di245.rules /etc/udev/rules.d
$ sudo udevadm control --reload

Disconnect and reconnect ttyUSB0 programmatically in Linux

Trying to solve this problem (ttyUSB0 that works properly than stop working after about 1hr)I'm thinking on if disconnecting and reconnecting the usb device could be a good fix.
So, it is possibile to cut down power to the USB device and repower it programmatically (bash)?
# lsusb -t
1-1:1.0: No such file or directory
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=musb-hdrc/1p, 480M
|__ Port 1: Dev 2, If 0, Class=vend., Driver=, 12M
|__ Port 1: Dev 2, If 1, Class=vend., Driver=cp210x, 12M
On am335x, kernel 3.2.0, ubuntu core armhf.
[ 1.784332] usb 1-1: cp210x converter now attached to ttyUSB0
At the moment I need a complete power cycle to have ttyUSB0 back.
This is the solution:
Find the identity of your usb device.
# tree /sys/bus/usb/drivers/cp210x/
/sys/bus/usb/drivers/cp210x/
|-- 1-1:1.1 -> ../../../../devices/platform/omap/musb-ti81xx/musb-hdrc.1/usb1/1-1/1-1:1.1
|-- bind
|-- module -> ../../../../module/cp210x
|-- remove_id
|-- uevent
-- unbind
So 1-1:1.1 is the identifier of my ttyUSB0(it can be discovered also via dmesg).
Then, disconnect the device (as root):
# echo -n "1-1:1.1" > /sys/bus/usb/drivers/cp210x/unbind
reconnect it
# echo -n "1-1:1.1" > /sys/bus/usb/drivers/cp210x/bind
At this point I had the same device but with a different name, it was now ttyUSB1 instead of ttyUSB0.
- To avoid this I added a new rule in /etc/udev/rules.d/ by creating a new file named 99-usb-serial.rules with this line:
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea70", ATTRS{serial}=="002DCFAF", SYMLINK+="sameName", MODE:="0666"
where idVendor, idProduct and serial must be the values of your device. This rule will create a new device called sameName linked to the ttyUSB* device normally generated from the OS.
As #Robert Harvey Said,
You first need to find our driver that will help you 'unplug and plug' the usb. Type: ls /sys/bus/usb/drivers which should print something like this: btusb ftdi_sio hub usb usbfs usbhid usbserial_generic uvcvideo. These, are all the drivers for each usb device. Now, lets say mine is ftdi_sio, which is a device i use to program my arduino (atmega328p chip). I am not sure how Your/other usb devices name themselves there. Like, i dont know which of these is my mouse.
Now, you can see the driver's commands using:
ls /sys/bus/usb/drivers/ftdi_sio/, which will print something like: 1-4:1.0 bind module uevent unbind, Where 1-4:1.0 is the device's characteristic code, and the bind and unbind command, which are the 'plug' and 'unplug' command respectively.
Now, if i want to unplug programatically the ftdi usb port, i will type:
echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/unbind
and, to plug it again:
echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/bind
Now, we can combine all the commands together, with a ';':
echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/unbind ; echo -n "1-4:1.0" > /sys/bus/usb/drivers/ftdi_sio/bind

How can I install Hjelmslund USB485 in debian

As the title says!
I can read info from the device with "dmesg" and see it when "lsusb" but how do I attach/install it as for example dev/ttyUSB2
One way is to change the VID and PID with FTDI software FT Prog (utility for programming the EEPROM of FTxxx devices). Change to 0403 and 6001, Linux will then recognise it as a generic FTDI.
If you don't want to modify the ftdi chips settings, you could just add the VID / PID to the list of ids recognized by the ftdi driver. To do this at run time (non permanent) do:
modprobe ftdi_sio
echo "1c40 0477" > /sys/bus/usb-serial/drivers/ftdi_sio/new_id

How do I log data from my serial ports consistently?

I need to deal with two pieces of custom hardware which both send debugging data over two serial connections. Those serial connections go through two serial-to-USB converters. The serial-to-USB devices have the same vendor numbers, device numbers, and, apparently, the same serial numbers.
Here's the issue: I want to log the two serial ports separately. The custom hardware needs to be rebooted constantly, and whether they attach to the same /dev/ttyUSB* is completely random. How can I make them pick the same device path every time? I could make it dependent on what port it is plugged into, but that seems kind of hacky.
So, I ran a diff against the output of udevadm, like so:
$ udevadm info -a -p `udevadm info -q path -n /dev/ttyUSB1` > usb1
$ udevadm info -a -p `udevadm info -q path -n /dev/ttyUSB2` > usb2
$ diff usb1 usb2
The output of the diff is long; you can see it here
Grepping for serial (same for both):
$ udevadm info -a -p `udevadm info -q path -n /dev/ttyUSB2` | grep serial
SUBSYSTEMS=="usb-serial"
ATTRS{serial}=="0001"
ATTRS{serial}=="0000:00:1d.7"
Other info:
I'm using PuTTY to read from the serial ports.
OS:
$ uname -a
Linux xxxxxxxx.localdomain 2.6.32-279.14.1.el6.x86_64 #1 SMP Tue Nov 6 23:43:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Please check if the usb-serial converter is based on a ftdi chip?
(You can check driver filenames)
If so; you have a chance to change serial number,or even the manufacturer info.
http://www.ftdichip.com/Support/Utilities.htm
Check the tools; MProg and FT_PROG utility tools.

Resources