I have a RedBee RFID Reader. Its user documentation is only for windows, and I am on ArchLinux. The only time I have ever done serial communication over a USB port was for an Arduino and that was through their GUI environment so I never was exposed to the metal. So I have this RFID reader that you interface with via serial communication across a USB port. The baud rate is 9600, the device is connected to /dev/bus/usb/004/004. The output of ls -l /dev/bus/usb/004/004 is:
crwxrwxrwx 1 root root 189, 387 Mar 8 19:14 /dev/bus/usb/004/004
The output of lsusb is
Bus 004 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-
Serial (UART) IC
Bus 004 Device 003: ID 0cf3:3005 Atheros Communications, Inc. AR3011 Bluetooth
...
The output of lsusb -s 004:004 -v is:
Bus 004 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0403 Future Technology Devices International, Ltd
idProduct 0x6001 FT232 USB-Serial (UART) IC
bcdDevice 6.00
iManufacturer 1 FTDI
iProduct 2 FT232R USB UART
iSerial 3 A900DGX9
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 90mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 2 FT232R USB UART
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Device Status: 0x0000
(Bus Powered)
Here is the output of dmsg | grep -i tty
[ 0.000000] console [tty0] enabled
[ 7.226118] systemd[1]: Starting system-getty.slice.
[ 7.226397] systemd[1]: Created slice system-getty.slice.
[ 10.535204] usb 4-1.7: FTDI USB Serial Device converter now attached to ttyUSB0
[ 6372.435916] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[ 7961.660760] usb 4-1.7: FTDI USB Serial Device converter now attached to ttyUSB0
[ 7964.716225] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[ 8282.582961] usb 4-1.7: FTDI USB Serial Device converter now attached to ttyUSB0
Things I have tried:
I have tried using putty's (compiled for linux) serial option to connect to /dev/bus/usb/004/004 but it responds with:
Unable to open connection to:
Unable to configure serial port
The solution is to use dmesg | grep -i tty to get the TTY the device has connected to. In my case I needed to connect to /dev/ttyUSB0 not /dev/bus/usb/004/004.
More Info
dmesg
This way you can automatically detect which device you should use (replace FT232R_USB_UART with model) :
#!/bin/sh
PORT=""
for i in /dev/ttyUSB* ; do
if [ "x`udevadm info $i | grep 'ID_MODEL=FT232R_USB_UART'`" != "x" ] ; then
PORT=$i
fi
done
if [ "x$PORT" = "x" ] ; then
echo "No FT232R_USB_UART port found!" 1>&2
exit 1
fi
echo "PORT = $PORT"
Related
I'm running the Python script below on Ubuntu 20.04. My user is a member of dialout.
$ ./test_serial.py
Traceback (most recent call last):
File "./test_serial.py", line 20, in <module>
data = os.read(fd, 1024)
BlockingIOError: [Errno 11] Resource temporarily unavailable
$ ls -al /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 Feb 10 16:12 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 Feb 10 17:56 /dev/ttyUSB1
The script:
#! /usr/bin/env python3
import os
import termios
DEVICE = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AB0NTUNC-if00-port0"
DEVICE = "/dev/ttyUSB0"
fd = os.open(DEVICE, os.O_RDWR | os.O_NONBLOCK)
if fd >= 0:
if os.isatty(fd):
# Configure the serial port.
tios = termios.tcgetattr(fd)
tios[2] &= ~termios.CBAUD
tios[2] |= termios.B115200
termios.tcsetattr(fd, termios.TCSANOW, tios)
data = os.read(fd, 1024)
print(data)
dmesg:
[ 1254.255499] usb 1-3: USB disconnect, device number 3
[ 1254.256536] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[ 1254.256604] ftdi_sio 1-3:1.0: device disconnected
[ 1257.829592] usb 1-3: new full-speed USB device number 4 using xhci_hcd
[ 1257.985421] usb 1-3: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[ 1257.985441] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1257.985448] usb 1-3: Product: FT232R USB UART
[ 1257.985454] usb 1-3: Manufacturer: FTDI
[ 1257.985460] usb 1-3: SerialNumber: A500INN8
[ 1257.989360] ftdi_sio 1-3:1.0: FTDI USB Serial Device converter detected
[ 1257.989490] usb 1-3: Detected FT232RL
[ 1257.990398] usb 1-3: FTDI USB Serial Device converter now attached to ttyUSB0
[ 4076.157451] usb 1-1: new full-speed USB device number 5 using xhci_hcd
[ 4076.311520] usb 1-1: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
[ 4076.311537] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4076.311544] usb 1-1: Product: FT232R USB UART
[ 4076.311550] usb 1-1: Manufacturer: FTDI
[ 4076.311554] usb 1-1: SerialNumber: AB0NTUNC
[ 4076.315282] ftdi_sio 1-1:1.0: FTDI USB Serial Device converter detected
[ 4076.315368] usb 1-1: Detected FT232RL
[ 4076.316294] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB1
So, I'm trying to read a USB device in a brand new installation of Linux Mint.
The way I've done it before is to read the raw stream found in /dev/input/by-id
The device is being detected, and it is producing the expected device:
$ ls /dev/input/by-id/
usb-Generic_WebCam_SC-13HDL11939N_200901010001-event-if00
usb-Logitech_Logitech_Buzz_tm__Controller_V1-event-if00
But when I look at the file using
tail -f /dev/input/by-id/usb-Generic_WebCam_SC-13HDL11939N_200901010001-event-if00
No data is output to the terminal when I press some keys. I've tried it with sudo, I've tried changing the rights for the file. It basically waits where it is, unchanged.
There's a lot of questions about devices not appearing, or about IO errors when reading a file, but I can't find anyone else who's had the same problem.
Why might Linux Mint be detecting the device, but not reading the data from it?
Additional requested information:
# ls -lRa /dev/input/by-id
/dev/input/by-id:
total 0
drwxr-xr-x 2 root root 80 Jul 2 21:38 .
drwxr-xr-x 4 root root 360 Jul 2 21:38 ..
lrwxrwxrwx 1 root root 9 Jul 2 21:24 usb-Generic_WebCam_SC-13HDL11939N_200901010001-event-if00 -> ../event9
lrwxrwxrwx 1 root root 10 Jul 2 21:38 usb-Logitech_Logitech_Buzz_tm__Controller_V1-event-if00 -> ../event10
I tried tail -f on /dev/input/event10, too. Same result.
Also, the last few lines of dmesg
[ 263.440421] usb 2-1.1: new low-speed USB device number 5 using ehci-pci
[ 263.538270] usb 2-1.1: New USB device found, idVendor=054c, idProduct=0002
[ 263.538280] usb 2-1.1: New USB device strings: Mfr=3, Product=1, SerialNumber=0
[ 263.538285] usb 2-1.1: Product: Logitech Buzz(tm) Controller V1
[ 263.538290] usb 2-1.1: Manufacturer: Logitech
[ 263.585640] hidraw: raw HID events driver (C) Jiri Kosina
[ 263.597332] usbcore: registered new interface driver usbhid
[ 263.597338] usbhid: USB HID core driver
[ 263.615420] input: Logitech Logitech Buzz(tm) Controller V1 as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:054C:0002.0001/input/input11
[ 263.668811] sony 0003:054C:0002.0001: input,hidraw0: USB HID v1.11 Joystick [Logitech Logitech Buzz(tm) Controller V1] on usb-0000:00:1d.0-1.1/input0
[ 811.582183] usb 2-1.1: USB disconnect, device number 5
[ 813.318275] usb 2-1.1: new low-speed USB device number 6 using ehci-pci
[ 813.416196] usb 2-1.1: New USB device found, idVendor=054c, idProduct=0002
[ 813.416207] usb 2-1.1: New USB device strings: Mfr=3, Product=1, SerialNumber=0
[ 813.416213] usb 2-1.1: Product: Logitech Buzz(tm) Controller V1
[ 813.416218] usb 2-1.1: Manufacturer: Logitech
[ 813.422041] input: Logitech Logitech Buzz(tm) Controller V1 as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/0003:054C:0002.0002/input/input12
[ 813.422335] sony 0003:054C:0002.0002: input,hidraw0: USB HID v1.11 Joystick [Logitech Logitech Buzz(tm) Controller V1] on usb-0000:00:1d.0-1.1/input0
I have found that it can be read using the evtest utility (https://wiki.ubuntu.com/DebuggingTouchpadDetection/evtest), but only as root, or using sudo.
Also as root or sudo, I am unable to see any data in the path mentioned above.
P.S. I am able to push control data to the lamps in these controllers via /sys/class/leds/
The problem here is with the tail program, not with the input devices themselves. tail is trying to read data until "the end of the file" before it starts printing anything -- but an input device has no "end of the file", so it will never print anything. cat, on the other hand, writes out data immediately as it comes in, so that works correctly. I don't know why tail worked for you with other input devices in the past.
I want to monitor (sniff) the traffic of my /dev/ttyUSB0 which is created by FTDI USB Serial Converter. I've written my own application in Windows and now I try to port it to linux and use /dev/tty/USB0. I want to debug the communication that actually happens.
The software strace is not an option for me because it only shows the syscalls to ioctl.
Using Windows the software "Free Serial Port Monitor" did it by sniffing COM1.
Output of dmesg:
[16975.000221] usb 7-1: new full-speed USB device number 5 using uhci_hcd
[16975.193543] usb 7-1: New USB device found, idVendor=0403, idProduct=6001
[16975.193548] usb 7-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[16975.193552] usb 7-1: Product: FT232R USB UART
[16975.193555] usb 7-1: Manufacturer: FTDI
[16975.193558] usb 7-1: SerialNumber: A400BJII
[16975.200550] ftdi_sio 7-1:1.0: FTDI USB Serial Device converter detected
[16975.200599] usb 7-1: Detected FT232RL
[16975.202604] usb 7-1: FTDI USB Serial Device converter now attached to ttyUSB0
However I tried moserial to do this and the command "echo foobar > /dev/ttyUSB0" to verify, if it works. Also my software doesn't create an output to moserial.
UPDATE:
Found out how to monitor usb directly, now I need to convert USB packets to RS-232 (what FTDI basically does).
Setup usbmon
modprobe usbmon
1.1 With Linux kernels prior to 2.6.23, you will also need to run this command
modprobe -t debugfs none /sys/kernel/debug
usbmon0 will monitor any traffic from all usbmon0 to usbmonX
2.1. Find the correct usb device
cat /sys/kernel/debug/usb/devices|grep FTDI -A 7 -B 4
T: Bus=07 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 12 Spd=12 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0403 ProdID=6001 Rev= 6.00
S: Manufacturer=FTDI
S: Product=FT232R USB UART
S: SerialNumber=A400BJII
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr= 90mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=ftdi_sio
E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
2.2. Note Bus number of the port (Bus=07), so usbmon to monitor will be usbmon7
2.3. Use wireshark to capture the usbmon7 interface or use following command to get output to the console (stdout) ... replace the number with bus-id
cat /sys/kernel/debug/usb/usbmon/7u
What means 'u'?
https://www.kernel.org/doc/Documentation/usb/usbmon.txt
Two formats are supported currently: the original, or '1t' format, and the '1u' format. The '1t' format is deprecated in kernel 2.6.21. The '1u' format adds a few fields, such as ISO frame descriptors, interval, etc. It produces slightly longer lines, but otherwise is a perfect superset of '1t' format.
How do I convert the USB capture to RS-232 capture?
I don't know it ... TODO
With your hint I managed to solve my problem, so there it is my hint for the last point:
Using Wireshark, open usbmon0 and use this filter
usb.capdata or at
Issuing two times the command echo asd > /dev/ttyUSB0 produces the result below in Wireshark
You can extract the whole Leftover Capture Data from a capture file using tshark:
tshark -r capture.pcapng -T fields -e usb.capdata
from dmesg we can know that particular device has been mounted or unmounted.
But I want to know on which time the device has been mounted or unmounted.
Solution 1:
dmesg output isn't having human readable date-time information
Instead using dmesg you can use kernel log available, and filter it according to your need.
for e.g. Ubuntu, Debian stores kernel log at /var/log/kern.log
cat /var/log/kern.log | grep "usb"
It will give output like,
Apr 30 11:42:23 debian kernel: [ 1537.984584] usb 1-1.1: USB disconnect, device number 3
Apr 30 11:42:23 debian kernel: [ 1538.207012] usb 1-1.1: new low-speed USB device number 5 using ehci_hcd
Apr 30 11:42:29 debian kernel: [ 1543.409629] usb 1-1.1: new low-speed USB device number 6 using ehci_hcd
Apr 30 11:42:29 debian kernel: [ 1543.504880] usb 1-1.1: New USB device found, idVendor=04f3, idProduct=0235
Apr 30 11:42:29 debian kernel: [ 1543.504885] usb 1-1.1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
Apr 30 11:42:29 debian kernel: [ 1543.504888] usb 1-1.1: Product: OM
Solution 2:
I've found one perl script to convert dmesg date-time to human readable.
Try it,
#!/usr/bin/perl
use strict;
use warnings;
my #dmesg_new = ();
my $dmesg = "/bin/dmesg";
my #dmesg_old = `$dmesg`;
my $now = time();
my $uptime = `cat /proc/uptime | cut -d"." -f1`;
my $t_now = $now - $uptime;
sub format_time {
my #time = localtime $_[0];
$time[4]+=1; # Adjust Month
$time[5]+=1900; # Adjust Year
return sprintf '%4i-%02i-%02i %02i:%02i:%02i', #time[reverse 0..5];
}
foreach my $line ( #dmesg_old )
{
chomp( $line );
if( $line =~ m/\[\s*(\d+)\.(\d+)\](.*)/i )
{
# now - uptime + sekunden
my $t_time = format_time( $t_now + $1 );
push( #dmesg_new , "[$t_time] $3" );
}
}
print join( "\n", #dmesg_new );
print "\n";
Save and apply execute permission.
$chmod a+x script.pl
$./script.pl
[Sample output:]
[2014-04-30 11:17:27] eth0: no IPv6 routers present
[2014-04-30 11:42:18] hub 1-1:1.0: port 1 disabled by hub (EMI?), re-enabling...
[2014-04-30 11:42:18] usb 1-1.1: USB disconnect, device number 3
[2014-04-30 11:42:19] usb 1-1.1: new low-speed USB device number 5 using ehci_hcd
[2014-04-30 11:42:24] hub 1-1:1.0: unable to enumerate USB device on port 1
[2014-04-30 11:42:24] usb 1-1.1: new low-speed USB device number 6 using ehci_hcd
[2014-04-30 11:42:24] usb 1-1.1: New USB device found, idVendor=04f3, idProduct=0235
[2014-04-30 11:42:24] usb 1-1.1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[2014-04-30 11:42:24] usb 1-1.1: Product: OM
[2014-04-30 11:42:24] input: OM as /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1/1-1.1:1.0/input/input11
[2014-04-30 11:42:24] generic-usb 0003:04F3:0235.0004: input,hidraw0: USB HID v1.11 Mouse [OM] on usb-0000:00:1a.0-1.1/input0
Solution 3:
If your distro supports -T option for dmesg
Try dmesg -T. For me it worked on Debian, It should work for you too on Ubuntu. It enables time-stamp for output.
[From man page]
-T, --ctime
Print human readable timestamps. The timestamp could be inaccurate!
The time source used for the logs is not updated after system SUSPEND/RESUME.
In linux /var/log directory contains various log details. We can also get history of previous logs from this directory. Kernel zips the previous log details. In case of yours you have to open kern.log. But If you are looking for details which is not in kern.log, you can see kern.log.1 or in case you are interested in very old details, you have to unzip kern.log.2.gz
I have 3.2.27 Linux kernel with Busybox. I am using Raspberry PI. When I pluging my Huawei E303c dmesg showing
[ 4.569781] usb 1-1.2: new high-speed USB device number 5 using dwc_otg
[ 4.681078] usb 1-1.2: New USB device found, idVendor=12d1, idProduct=14fe
[ 4.690885] usb 1-1.2: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[ 4.701143] usb 1-1.2: Product: HUAWEI Mobile
[ 4.708326] usb 1-1.2: Manufacturer: HUAWEI
[ 4.718185] scsi0 : usb-storage 1-1.2:1.0
[ 4.726518] scsi1 : usb-storage 1-1.2:1.1
[ 5.720951] scsi 0:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2
[ 5.738561] scsi 1:0:0:0: Direct-Access HUAWEI SD Storage 2.31 PQ: 0 ANSI: 2
[ 5.755514] sd 1:0:0:0: [sda] Attached SCSI removable disk
The option kernel module is already running but usb-storage module not running. But when I enter usb_modeswitch -v 0x12d1 -p 0x14fe -H it's hangs like
Looking for default devices ...
Found default devices (1)
Accessing device 002 on bus 002 ...
Using endpoints 0x04 (out) and 0x83 (in)
Inquiring device details; driver will be detached ...
Looking for active driver ...
OK, driver found ("usb-storage")
OK, driver "usb-storage" detached
Can anyone give me a solution,
This has solve my issue
usb_modeswitch -c /etc/usb_modeswitch.conf -W -I
modprobe option
modprobe ppp_generic
My /etc/usb_modeswitch.conf looks like
# Huawei E303c
DefaultVendor= 0x12d1
DefaultProduct=0x14fe
TargetVendor= 0x12d1
TargetProductList="1001,1406,140b,140c,1412,141b,14ac,1506"
CheckSuccess=20
MessageEndpoint= 0x01
MessageContent="55534243123456780000000000000011062000000100000000000000000000"