(1)matlab simulink模块在 Instrument Control Toolbox里
SerialPort 相关模块的详细说明:
https://cn.mathworks.com/help/instrument/direct-interface-communication-in-simulink.html
https://cn.mathworks.com/help/instrument/serialreceive.html
(2)最简单的simulink 串口发数据的例子:这个例子往串口3上发数据,[1 2 3 4]四个字节,串口3设置波特率为9600。
需要注意的是Serial Send模块默认的输入类型为uint8型的一维数组,所以要设置 Constant模块的类型:
还要注意设置Constant 的Sample time:
(3)最简单的接收串口数据的例子:接收来自串口2的数据。值得注意的是Serial Receive模块可以设置为block(堵塞)模式和非block模式,block模式下程序会一直卡住等待接收来自串口的数据,非block模式则不然。下面是例子是block模式下的例子。