Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
75

I'm not quite certain what you're asking. You mention 'port' several times, but then in your example, you say the answer is /dev/ttyUSB0, which is a device dev path, not a port. So this answer is about finding the dev path for each device. Below is a quick and dirty script which walks through devices in /sys looking for USB devices with a ID_SERIAL ...


65

I find screen the most useful program for serial communication since I use it for other things anyway. It's usually just screen /dev/ttyS0 <speed>, although the default settings may be different for your device. It also allows you to pipe anything into the session by entering command mode and doing exec !! <run some program that generates output>....


53

Same as with output. Example: cat /dev/ttyS0 Or: cat < /dev/ttyS0 The first example is an app that opens the serial port and relays what it reads from it to its stdout (your console). The second is the shell directing the serial port traffic to any app that you like; this particular app then just relays its stdin to its stdout. To get better ...


50

All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0 /dev/ttyS1 ... . First have a look at the permissions on that file, lets assume you are using /dev/ttyS1. ls -l /dev/ttyS1 You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone. ...


47

Background The main reason why you need any program like minicom to communicate over a serial port is that the port needs to be set up prior to initiating a connection. If it weren't set up appropriately, the cat and echo commands would not do for you what you might have expected. Notice that once you run a program like minicom, the port is left with the ...


41

These /dev nodes appear because the standard PC serial port driver is compiled into the kernel you're using, and it is finding UARTs. That causes /sys/devices/platform/serial8250 (or something compatible) to appear, so udev creates the corresponding /dev nodes. These UARTs are most likely one of the many features of your motherboard's chipset. Serial UARTs ...


40

The right to access a serial port is determined by the permissions of the device file (e.g. /dev/ttyS0). So all you need to do is either arrange for the device to be owned by you, or (better) put yourself in the group that owns the device, or (if Fedora supports it, which I think it does) arrange for the device to belong to the user who's logged in on the ...


38

As suggested, you can add some udev rules. I edited the /etc/udev/rules.d/10-local.rules to contain: ACTION=="add", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="my_uart" You can check for the variables of your device by running udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0) There is a more in depth guide you can read on http:/...


34

I know it is an old question, but a one-liner may help those who come here searching: cat /dev/ttyPSC9 | awk '{ print $0; system("")}' system("") does the trick, and is POSIX compliant. Non-posix systems: beware. There exists a more specific function fflush() that does the same, but is not available in older versions of awk. An important piece of ...


32

The stty utility sets or reports on terminal I/O characteristics for the device that is its standard input. These characteristics are used when establishing a connection over that particular medium. cat doesn't know the baud rate as such, it rather prints on the screen information received from the particular connection. As an example stty -F /dev/ttyACM0 ...


32

Unfortunately serial ports are non-PlugNPlay, so kernel doesn't know which device was plugged in. After reading a HowTo tutorial I've got the working idea. The /dev/ directory of unix like OSes contains files named as ttySn (with n being a number). Most of them doesn't correspond to existing devices. To find which ones do, issue a command: $ dmesg | grep ...


29

The rule syntax above may work on some distributions, but did not work on mine (Raspbian). Since I never found a single document that explains all the ins and outs, I wrote my own, to be found here. This is what it boils down to. 1. find out what's on ttyUSB: dmesg | grep ttyUSB 2. list all attributes of the device: udevadm info --name=/dev/ttyUSBx --...


28

socat is a tool to connect (nearly) everything to (nearly) everything, and tee can duplicate streams. In your usecase you could connect your serial port /dev/ttyS0 to a PTY /tmp/ttyV0, then point your application to the PTY, and have socat tee out Input and Output somewhere for you to observe. Googling "socat serial port pty tee debug" will point you to ...


24

I found a way using a shell script here that put cat as a background process and a while loop that read the user input and echo it out to the port. I modified it to be more general and it fitted my purpose perfectly. #!/bin/sh # connect.sh # Usage: # $ connect.sh <device> <port speed> # Example: connect.sh /dev/ttyS0 9600 # Set up device ...


22

If UUCP is installed on the system, you may use the command cu, e.g. $ cu -l /dev/ttyS0 -s 9600


22

the best way to pass a file through xmodem is to use sx. In debian this application is part of 'lrzsz' package. In debian: apt-get install screen lrzsz screen /dev/ttyUSB0 115200 Then press Ctrl-A followed by : and type: exec !! sx yourbinary.bin This will send the file to ttyUSB0 over xmodem protocol


20

I found projects called Linux Serial Sniffer, jpnevulator, and Moni. The first two look like they do exactly what you want. The last one calls itself a monitor, but it actually looks like a standard serial communication program.


20

Use the screen quit command (normally ctrl-A \).


17

I use the command stty -F /dev/ttyUSB0 9600.


17

You can use the stty command to set such parameters. This will show all settings on the first serial port (replace ttyS0 with ttyUSB0 if using an USB serial port): stty -F /dev/ttyS0 -a This will set the baud rate to 9600, 8 bits, 1 stop bit, no parity: stty -F /dev/ttyS0 9600 cs8 -cstopb -parenb One thing that generally confuses people is that most ...


16

Thanks to the second comment by Bruce, I was able to figure out the problem on my own. After running stty -a -F /dev/ttyS1, there were 3 options I found to contribute to the problem: "echo", "onlcr", and "icrnl". Since this serial port is looped back to itself, here is what happened after running echo "hi" > /dev/ttyS1: The echo command appends a ...


16

You don't need to modify the kernel to just it just once; you can override it. Unplug the device modprobe ftdi_sio echo 0403 6001 >/sys/bus/usb-serial/drivers/ftdi_sio/new_id Plug in the device And your device should work. Your other alternative is to use the bind sysfs interface; I suggest using lsusb -t to figure out the correct path+interface in ...


15

I don't think the serial driver has any tracing functionality that would allow you to watch packets. You can use strace to observe all the reads and writes from your application: strace -s9999 -o myapp.strace -eread,write,ioctl ./myapp


14

Try http://tio.github.io "tio" is a simple TTY terminal application which features a straightforward commandline interface to easily connect to TTY devices for basic input/output. Typical use is without options. For example: tio /dev/ttyS0 Which corresponds to the commonly used options: tio --baudrate 115200 --databits 8 --flow none --stopbits 1 --...


12

This script is based on another answer, but sends everything over the serial port (except Ctrl+Q), not just single commands followed by Enter. This enables you to use Ctrl+C or Ctrl+Z on the remote host, and to use interactive "GUI" programs like aptitude or alsamixer. It can be quit by pressing Ctrl+Q. #!/bin/bash if [[ $# -lt 1 ]]; then echo "Usage:" ...


12

You don't need to modify the kernel, you can automate the process like this: Add the following single line to /etc/udev/rules.d/99-ftdi.rules ACTION=="add", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", RUN+="/sbin/modprobe ftdi_sio" RUN+="/bin/sh -c 'echo 0403 6001 > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'" Either reboot or run sudo udevadm ...


10

It is likely to be buffering in awk, not cat. In the first case, awk believes it is interactive because its input and output are TTYs (even though they're different TTYs - I'm guessing that awk is not checking that). In the second, the input is a pipe so it runs non-interactively. You will need to explicitly flush in your awk program. This is not portable, ...


10

You can use this command to explore your device if connected to usb0: udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)


9

Are you sure the data isn't corrupted by your terminal (or wherever cat is displaying)? cat is unlikely to corrupt your data. Try using od (octal dump) to dump the data coming from the serial port, so you can see exactly what is coming across (without relying on it being printable). Use od -c if you're expecting ASCII data. If you're still seeing ...


9

cat just uses whatever settings the port is already configured for. With this little C snippet you can see the baud rate currently set for a particular serial port: get-baud-rate.c #include <termios.h> #include <unistd.h> #include <stdio.h> int main() { struct termios tios; tcgetattr(0, &tios); speed_t ispeed = cfgetispeed(&...


Only top voted, non community-wiki answers of a minimum length are eligible