How does cat know the baud rate of the serial port?
Clash Royale CLAN TAG#URR8PPP
up vote
23
down vote
favorite
I regularly use cat
to view debugging information in the console from my FPGA development board over the serial connection, but I never have had to tell linux what the baud rate is. How does cat know what the baud rate of the serial connection is?
linux devices serial-port
add a comment |Â
up vote
23
down vote
favorite
I regularly use cat
to view debugging information in the console from my FPGA development board over the serial connection, but I never have had to tell linux what the baud rate is. How does cat know what the baud rate of the serial connection is?
linux devices serial-port
You did not set up the port e.g. withminicom
before? It doesn't work here. Only after I set up the serial port parameters I can usecat
.
â Marco
Apr 19 '13 at 9:11
It doesn't set or knows the baudrate, it just reads from the device.
â Ulrich Dangel
Apr 19 '13 at 9:12
@Marco, I don't know if Debian has some default baud rate setting, but I haven't set it anywhere.
â stanri
Apr 19 '13 at 9:18
add a comment |Â
up vote
23
down vote
favorite
up vote
23
down vote
favorite
I regularly use cat
to view debugging information in the console from my FPGA development board over the serial connection, but I never have had to tell linux what the baud rate is. How does cat know what the baud rate of the serial connection is?
linux devices serial-port
I regularly use cat
to view debugging information in the console from my FPGA development board over the serial connection, but I never have had to tell linux what the baud rate is. How does cat know what the baud rate of the serial connection is?
linux devices serial-port
linux devices serial-port
edited Apr 19 '13 at 22:03
Gilles
515k12110231551
515k12110231551
asked Apr 19 '13 at 9:07
stanri
6261719
6261719
You did not set up the port e.g. withminicom
before? It doesn't work here. Only after I set up the serial port parameters I can usecat
.
â Marco
Apr 19 '13 at 9:11
It doesn't set or knows the baudrate, it just reads from the device.
â Ulrich Dangel
Apr 19 '13 at 9:12
@Marco, I don't know if Debian has some default baud rate setting, but I haven't set it anywhere.
â stanri
Apr 19 '13 at 9:18
add a comment |Â
You did not set up the port e.g. withminicom
before? It doesn't work here. Only after I set up the serial port parameters I can usecat
.
â Marco
Apr 19 '13 at 9:11
It doesn't set or knows the baudrate, it just reads from the device.
â Ulrich Dangel
Apr 19 '13 at 9:12
@Marco, I don't know if Debian has some default baud rate setting, but I haven't set it anywhere.
â stanri
Apr 19 '13 at 9:18
You did not set up the port e.g. with
minicom
before? It doesn't work here. Only after I set up the serial port parameters I can use cat
.â Marco
Apr 19 '13 at 9:11
You did not set up the port e.g. with
minicom
before? It doesn't work here. Only after I set up the serial port parameters I can use cat
.â Marco
Apr 19 '13 at 9:11
It doesn't set or knows the baudrate, it just reads from the device.
â Ulrich Dangel
Apr 19 '13 at 9:12
It doesn't set or knows the baudrate, it just reads from the device.
â Ulrich Dangel
Apr 19 '13 at 9:12
@Marco, I don't know if Debian has some default baud rate setting, but I haven't set it anywhere.
â stanri
Apr 19 '13 at 9:18
@Marco, I don't know if Debian has some default baud rate setting, but I haven't set it anywhere.
â stanri
Apr 19 '13 at 9:18
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
31
down vote
accepted
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
gives the current baud rate for the ttyACM0 device.
but how did stty know about the baud rate then? This answer only defers somehow the question, if the baud rate can be autodetected or was set at some point (i.e. viastty
)
â humanityANDpeace
Apr 3 at 19:51
@humanityANDpeace I assume the default baud rate was the one I happened to be using. I later on did need to change it via stty when I changed the baud rate on the device.
â stanri
Apr 6 at 8:16
add a comment |Â
up vote
9
down vote
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(&tios);
speed_t ospeed = cfgetospeed(&tios);
printf("baud rate in: 0%on", ispeed);
printf("baud rate out: 0%on", ospeed);
return 0;
Run it:
./get-baud-rate < /dev/ttyS0 # or whatever your serial port is
The numbers you get can be looked up in /usr/include/asm-generic/termios.h
, where there are #define
s such as B9600
etc. Note that the numbers in the header file and in the get-baud-rate
output are in octal.
Maybe you can experiment and see what these numbers are like on a fresh boot and whether they change later.
2
I just found thestty
command which does just this. For example,stty -F /dev/ttyACM0
gives me the current baud rate, which is correct for my device.
â stanri
Apr 19 '13 at 9:33
Of course that's a much better idea.
â clacke
Apr 19 '13 at 10:05
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
31
down vote
accepted
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
gives the current baud rate for the ttyACM0 device.
but how did stty know about the baud rate then? This answer only defers somehow the question, if the baud rate can be autodetected or was set at some point (i.e. viastty
)
â humanityANDpeace
Apr 3 at 19:51
@humanityANDpeace I assume the default baud rate was the one I happened to be using. I later on did need to change it via stty when I changed the baud rate on the device.
â stanri
Apr 6 at 8:16
add a comment |Â
up vote
31
down vote
accepted
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
gives the current baud rate for the ttyACM0 device.
but how did stty know about the baud rate then? This answer only defers somehow the question, if the baud rate can be autodetected or was set at some point (i.e. viastty
)
â humanityANDpeace
Apr 3 at 19:51
@humanityANDpeace I assume the default baud rate was the one I happened to be using. I later on did need to change it via stty when I changed the baud rate on the device.
â stanri
Apr 6 at 8:16
add a comment |Â
up vote
31
down vote
accepted
up vote
31
down vote
accepted
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
gives the current baud rate for the ttyACM0 device.
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
gives the current baud rate for the ttyACM0 device.
edited 58 secs ago
Cristian Ciupitu
2,01111519
2,01111519
answered Apr 19 '13 at 9:35
stanri
6261719
6261719
but how did stty know about the baud rate then? This answer only defers somehow the question, if the baud rate can be autodetected or was set at some point (i.e. viastty
)
â humanityANDpeace
Apr 3 at 19:51
@humanityANDpeace I assume the default baud rate was the one I happened to be using. I later on did need to change it via stty when I changed the baud rate on the device.
â stanri
Apr 6 at 8:16
add a comment |Â
but how did stty know about the baud rate then? This answer only defers somehow the question, if the baud rate can be autodetected or was set at some point (i.e. viastty
)
â humanityANDpeace
Apr 3 at 19:51
@humanityANDpeace I assume the default baud rate was the one I happened to be using. I later on did need to change it via stty when I changed the baud rate on the device.
â stanri
Apr 6 at 8:16
but how did stty know about the baud rate then? This answer only defers somehow the question, if the baud rate can be autodetected or was set at some point (i.e. via
stty
)â humanityANDpeace
Apr 3 at 19:51
but how did stty know about the baud rate then? This answer only defers somehow the question, if the baud rate can be autodetected or was set at some point (i.e. via
stty
)â humanityANDpeace
Apr 3 at 19:51
@humanityANDpeace I assume the default baud rate was the one I happened to be using. I later on did need to change it via stty when I changed the baud rate on the device.
â stanri
Apr 6 at 8:16
@humanityANDpeace I assume the default baud rate was the one I happened to be using. I later on did need to change it via stty when I changed the baud rate on the device.
â stanri
Apr 6 at 8:16
add a comment |Â
up vote
9
down vote
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(&tios);
speed_t ospeed = cfgetospeed(&tios);
printf("baud rate in: 0%on", ispeed);
printf("baud rate out: 0%on", ospeed);
return 0;
Run it:
./get-baud-rate < /dev/ttyS0 # or whatever your serial port is
The numbers you get can be looked up in /usr/include/asm-generic/termios.h
, where there are #define
s such as B9600
etc. Note that the numbers in the header file and in the get-baud-rate
output are in octal.
Maybe you can experiment and see what these numbers are like on a fresh boot and whether they change later.
2
I just found thestty
command which does just this. For example,stty -F /dev/ttyACM0
gives me the current baud rate, which is correct for my device.
â stanri
Apr 19 '13 at 9:33
Of course that's a much better idea.
â clacke
Apr 19 '13 at 10:05
add a comment |Â
up vote
9
down vote
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(&tios);
speed_t ospeed = cfgetospeed(&tios);
printf("baud rate in: 0%on", ispeed);
printf("baud rate out: 0%on", ospeed);
return 0;
Run it:
./get-baud-rate < /dev/ttyS0 # or whatever your serial port is
The numbers you get can be looked up in /usr/include/asm-generic/termios.h
, where there are #define
s such as B9600
etc. Note that the numbers in the header file and in the get-baud-rate
output are in octal.
Maybe you can experiment and see what these numbers are like on a fresh boot and whether they change later.
2
I just found thestty
command which does just this. For example,stty -F /dev/ttyACM0
gives me the current baud rate, which is correct for my device.
â stanri
Apr 19 '13 at 9:33
Of course that's a much better idea.
â clacke
Apr 19 '13 at 10:05
add a comment |Â
up vote
9
down vote
up vote
9
down vote
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(&tios);
speed_t ospeed = cfgetospeed(&tios);
printf("baud rate in: 0%on", ispeed);
printf("baud rate out: 0%on", ospeed);
return 0;
Run it:
./get-baud-rate < /dev/ttyS0 # or whatever your serial port is
The numbers you get can be looked up in /usr/include/asm-generic/termios.h
, where there are #define
s such as B9600
etc. Note that the numbers in the header file and in the get-baud-rate
output are in octal.
Maybe you can experiment and see what these numbers are like on a fresh boot and whether they change later.
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(&tios);
speed_t ospeed = cfgetospeed(&tios);
printf("baud rate in: 0%on", ispeed);
printf("baud rate out: 0%on", ospeed);
return 0;
Run it:
./get-baud-rate < /dev/ttyS0 # or whatever your serial port is
The numbers you get can be looked up in /usr/include/asm-generic/termios.h
, where there are #define
s such as B9600
etc. Note that the numbers in the header file and in the get-baud-rate
output are in octal.
Maybe you can experiment and see what these numbers are like on a fresh boot and whether they change later.
answered Apr 19 '13 at 9:32
clacke
33839
33839
2
I just found thestty
command which does just this. For example,stty -F /dev/ttyACM0
gives me the current baud rate, which is correct for my device.
â stanri
Apr 19 '13 at 9:33
Of course that's a much better idea.
â clacke
Apr 19 '13 at 10:05
add a comment |Â
2
I just found thestty
command which does just this. For example,stty -F /dev/ttyACM0
gives me the current baud rate, which is correct for my device.
â stanri
Apr 19 '13 at 9:33
Of course that's a much better idea.
â clacke
Apr 19 '13 at 10:05
2
2
I just found the
stty
command which does just this. For example, stty -F /dev/ttyACM0
gives me the current baud rate, which is correct for my device.â stanri
Apr 19 '13 at 9:33
I just found the
stty
command which does just this. For example, stty -F /dev/ttyACM0
gives me the current baud rate, which is correct for my device.â stanri
Apr 19 '13 at 9:33
Of course that's a much better idea.
â clacke
Apr 19 '13 at 10:05
Of course that's a much better idea.
â clacke
Apr 19 '13 at 10:05
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f72979%2fhow-does-cat-know-the-baud-rate-of-the-serial-port%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You did not set up the port e.g. with
minicom
before? It doesn't work here. Only after I set up the serial port parameters I can usecat
.â Marco
Apr 19 '13 at 9:11
It doesn't set or knows the baudrate, it just reads from the device.
â Ulrich Dangel
Apr 19 '13 at 9:12
@Marco, I don't know if Debian has some default baud rate setting, but I haven't set it anywhere.
â stanri
Apr 19 '13 at 9:18