Why does "cat ttyUSB0" not produce output?
Solution 1
I had the same issue
On the other side, my device was only sending a stream of data without end-of-line
You need to set /dev/ttyUSB0 as raw to have it process stream one byte at a time:
stty -F dev/ttyUSB0 raw
(of course, make sure to set the speed properly, just add the baud value at the end of that line)
Solution 2
This may not help, but here's a similar problem I've had in the past. When I cat the device file for my mouse directly (i.e., using cat /dev/input/by-id/usb-<mymouse>
) I get output similar to what you get with your keyboard (i.e., gibberish). However, some mouse motions, like left click, don't generate any printable characters, so the terminal shows nothing.
Of course, the mouse is still doing something, we just can't see it by cat
'ing the device file. Fortunately the kernel has a neat feature called usbmon that is helpful for eavesdropping on the raw binary output of usb devices. Using that, we can see exactly what's happening when we perform (say) a left-click, whereas doing the same thing via /dev
often shows nothing.
Again, this may not help, but here's how to use usbmon:
Make sure your kernel has usbmon enabled. The output of:
zcat /proc/config.gz | grep USB_MON
should have either=m
or=y
in it.If it was
=m
, then load the module withsudo modprobe usbmon
To make sure all the usb sockets are showing up in the right place, run:
ls /sys/kernel/debug/usb/usbmon
You should see something like:
0s 0u 1s 1t 1u 2s 2t 2u 3s 3t 3u 4s 4t 4u
The different numbers refer to different USB ports, and the ones with a 0 in front give the aggregated output of all USB ports. So for example, running cat /sys/kernel/debug/usb/usbmon/0u
shows exactly what the device is doing, even in cases where cat
'ing the file in /dev
showed nothing.
Whether this solves your problem or not, it may be helpful in the future, since it's often a more helpful way to eavesdrop on USB devices than /dev
.
Good luck :)
Solution 3
Disregard the answer about need to initiate USB connection - it's already been initiated when you plugged in the device.
If you just want to check if it's working, use dd if=/dev/ttyUSB0
.
If you want to actually read those characters, you need serial terminal. Use minicom
(CLI, need manual), picocom
(might figure it out on your own), cutecom
(nice graphical interface, easy) or screen
(CLI, but really easy). You'll need to know the baudrate.. 90% it's either 115200 or 9600, might as well be 57600, 38400 or 19200.
By the way, what kind of receiver are you using? Could you give us a link to a product page or description?
Solution 4
For me it was the baudrate too low. Output did appear once I reconfigured the system (device and port) to use 300 instead of 150.
Related videos on Youtube
nlognfan
Updated on September 18, 2022Comments
-
nlognfan over 1 year
I connected an infrared receiver to a USB port ... (the last line of dmesg tells device file)
$ dmesg [10496.596063] usb 7-2: new full-speed USB device number 2 using uhci_hcd [10496.751112] usb 7-2: New USB device found, idVendor=0df7, idProduct=0620 [10496.751117] usb 7-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [10496.751120] usb 7-2: Product: USB-Serial Controller [10496.751124] usb 7-2: Manufacturer: Prolific Technology Inc. [10496.787441] usbcore: registered new interface driver usbserial [10496.787467] usbcore: registered new interface driver usbserial_generic [10496.787483] usbserial: USB Serial support registered for generic [10496.795104] usbcore: registered new interface driver pl2303 [10496.795129] usbserial: USB Serial support registered for pl2303 [10496.795160] pl2303 7-2:1.0: pl2303 converter detected [10496.807238] usb 7-2: pl2303 converter now attached to ttyUSB0
Then I went on to try it ...
$ sudo cat /dev/ttyUSB0
but no output, simply hangs. Even though, as I press any button on my remote control, the infrared receiver device's LED flashes, so that does seem to work.
Why could that be?
notes:
the above command quits when I remove device from USB port and prints "cat: ttyUSB0: No such device", and dmesg prints 3 lines:
[13707.264086] usb 7-2: USB disconnect, device number 2 [13707.264894] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0 [13707.264915] pl2303 7-2:1.0: device disconnected)
with the device files for keyboard this works, eg:
$ sudo cat /dev/input/by-id/usb-USB_USB_Keykoard-event-kbd
produces many weird characters on the console as I press any key the keyboard
- same happens on other USB ports too
-
Celada almost 10 yearsBut this is a question about a serial port. The fact that the serial port is connected with USB is neither here nor there.