栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

2021a之后版本matlab与python TCP通信详解

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021a之后版本matlab与python TCP通信详解

2021a之后版本matlab与python TCP通信详解 问题初始:

我想要使用python调用 matlab来进行一些科学计算,但是调用过程中 matlab.eng 转换数据以及调用启动需要大量的时间,所以萌生出一个想法:使用本机的TCP
参考优化调用的链接:http://www.daimazhu.com/etagid33143b0/

matlab 服务端

matlab 中有的新的tcpserver对象来进行服务的构建,这里用得到是一个请求访问来的时候回调函数 @requestDATACommand,以及server收到一个代码终止符后自动处理二进制数据的 readArduinoData函数。 运行后就已经将服务启动了。函数之间和上级之间的传参可以使用global 变量的方式。

ip = '127.0.0.1';
port = 5005;
% 构造服务器端tcpip对象
server = tcpserver(ip, port,"Timeout",40);
server.ConnectionChangedFcn = @requestDataCommand;
configureCallback(server,"terminator", @readArduinoData);
configureTerminator(server,"LF");

function requestDataCommand(src,~)
    if src.Connected
        % Display the server object to see that Arduino client has connected to it.
        disp("The Connected and ClientAddress properties of the tcpserver object show that the Arduino is connected.")
        %       disp(src.BytesAvailableFcnMode)
        % Request the Arduino to send data.
        disp("Send the command: ")
    end
end

function readArduinoData(src,~)
	% Read the sine wave data sent to the tcpserver object.
	recive_tmie = tic;
	src.UserData = readline(src);
	input = jsondecode(src.UserData);
	toc(recive_tmie)
end
python clinet 代码

xxxx 后续补充吧,python在服务器上(或者也能够在其他博客里面找到,就是访问连接服务器,然后sent数据,receive 数据。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/938656.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号