我正在尝试编写一个Matlab代码,该代码将从外部c程序接收数据并对其进行绘图。数据采用文本格式。在我每次进行连接时的过去尝试,但是matlab程序没有收到任何消息,即使我可以验证是否已发送。基本上我正在寻找Matlab中正确方法的答案,以便从c程序发送的TCP连接中检索数据。
function tcp_testing()
t = tcpip('localhost',7220,'NetworkRole','server')
% Set size of receiving buffer, if needed.
set(t, 'InputBufferSize', 30000);
% Open connection to the server.
fopen(t);
% Transmit data to the server (or a request for data from the server).
fprintf(t, 'GET /');
% Pause for the communication delay, if needed.
pause(1)
% Receive lines of data from server
while (get(t, 'BytesAvailable') > 0)
t.BytesAvailable
DataReceived = fscanf(t)
end
end