【Matlab】实现串口通信

整理时间:2020-05-19
目录:
1.matlab可以 进行串口通信?
2.怎么搞
3.总结

正文:

1.matlab可以 进行串口通信
matlab的toolbox很强大。其中Instrument Control Toolbox,The toolbox provides built-in support for TCP/IP, UDP, I2C, SPI, and Bluetooth® serial protocols for remote communication with other computers and printed circuit boards (PCBs) from MATLAB.
其中,我们就只关注本文话题 串口通信。
注:用好matlab自带的帮助文档。
【Matlab】实现串口通信

2.怎么搞
2.1 环境准备
准备好食材工具再做饭。包括:
(1)matlab软件(我使用的是R2019a)
(2)虚拟串口工具Configure Virtual Serial Port Driver
(3)串口工具hercules_3-2-8

【Matlab】实现串口通信
【Matlab】实现串口通信
2.1 开搞
step1:
使用虚拟串口工具生成一对虚拟串口,它们俩是“我发你收”的关系。
【Matlab】实现串口通信
比如我创建虚拟串口是COM1 和 COM2.
【Matlab】实现串口通信
step2:
打开串口工具,设置串口信息。
【Matlab】实现串口通信
step3:
上面串口工具软件hercules_3-2-8 使用的是COM2,那我们matlab中就使用COM1.
【Matlab】实现串口通信
查看详细信息
【Matlab】实现串口通信

step4:
matlab 发送消息,在hercules_3-2-8 中接收查看。
【Matlab】实现串口通信
step5:
hercules_3-2-8发送消息,在matlab中接收查看。
【Matlab】实现串口通信
step6:
打扫战场,保持好习惯,关闭句柄,清除占用。
fclose(sObject);
delete(instrfind);
【Matlab】实现串口通信

3.总结
实现了一个简单 的串口收发,重在理解。从易到难,循序渐进,加油吧,曾经那个少年!


THE END~