What's the maximum baud rate in MATLAB?

99封情书 提交于 2019-12-13 08:59:35

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/47962291/whats-the-maximum-baud-rate-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!