Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...