How does cat know the baud rate of the serial port?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
23
down vote

favorite
7












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?










share|improve this question























  • 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










  • @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














up vote
23
down vote

favorite
7












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?










share|improve this question























  • 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










  • @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












up vote
23
down vote

favorite
7









up vote
23
down vote

favorite
7






7





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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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. 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










  • @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











  • 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










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.






share|improve this answer






















  • 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

















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 #defines 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.






share|improve this answer
















  • 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










  • Of course that's a much better idea.
    – clacke
    Apr 19 '13 at 10:05










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer






















  • 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














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.






share|improve this answer






















  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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. 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
















  • 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















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












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 #defines 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.






share|improve this answer
















  • 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










  • Of course that's a much better idea.
    – clacke
    Apr 19 '13 at 10:05














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 #defines 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.






share|improve this answer
















  • 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










  • Of course that's a much better idea.
    – clacke
    Apr 19 '13 at 10:05












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 #defines 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.






share|improve this answer












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 #defines 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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 19 '13 at 9:32









clacke

33839




33839







  • 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










  • Of course that's a much better idea.
    – clacke
    Apr 19 '13 at 10:05












  • 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










  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?