Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

linux - What's the maximum baud rate in MATLAB?

Ubuntu 16.04 & MATLAB R2017a.

I'm trying to set serial port like that:

s=serial_port('/dev/ttyUSB0','BaudRate',115200,'DataBits',8,'InputBufferSize',80000)

It's working fine, but when I try to change baud rate, say 1000000. I got this message:

Open failed: BaudRate could not be set to the specified value.

So, I have 2 question:

1) Is it possible to set not common baud rates, say 2000000?

2) I found, that 1500000 and 3000000 is working for me. Is there maximum speed?

** UPDATE**

I know how to change the baud rate in OS, in my case (Ubuntu 16.04) setserial is not working, so I'm using sudo stty -F /dev/ttyUSB3 3500000 (not all speed is allowed) or via asm/termios.h> -- all speed is allowed. So, I'm using second way.

After that, I can easily listen the port like that cu -l /dev/ttyUSB0 And at the same time I cant set the speed in matlab.. (Error above)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Although this link should provide you enough information about how to manage baud rates on Matlab side, as @Cris Luengo already stated in his command, I would like to elaborate a little bit on the hardware side of the problem.

Using the following command:

stty -F /dev/ttyUSB0

you should be able to retrieve the current baud rate of the targeted device. Alternatively, the following command also retrieves that value:

 setserial -ag /dev/ttyUSB0

together with other important information:

/dev/ttyUSB0, Line ..., UART: ..., Port: ..., IRQ: ...

Baud_base: ..., close_delay: ..., divisor: ...

closing_wait: ..., closing_wait2: ...

Flags: ...

OS side, you can play with the baud rate of some devices but if you want to avoid problems, you always have to set a coherent value when establishing a connection. Generally speaking, devices have a tolerance level (of, I think, no more than ±5%) on overspeed and underspeed concerning baud rate deviance... so you can try to force an arbitrary baud rate different from the current one, but you don't want to go too far from it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...