UDP problems in a timer and GUI environment

1 view (last 30 days)
Markus
Markus on 11 Sep 2020
Edited: Markus on 11 Sep 2020
I have to GUIs that are communicating with each other via UDP. One of the GUIs is for debugging purposes and will be replaced by an external microcontroller.
I want to send a double matrix of size 70x6 that will be sent in the start function of the timer. That works most of the time.
Inside the timer function is another matrix with less columns but the same number of rows, e.g. 70x4.
When I receive the data, only 68/70 rows arrive in the first timer execution and the last two rows are following at the beginning of the next "round".
My receiving end looks somewhat like that:
sock_VAL=udp('127.0.0.1', 'LocalPort', 9008, 'RemotePort', 9007); %141.75.115.46 127.0.0.1
sock_VAL.DatagramReceivedFcn = {@udp_callback_Lok, handles};
sock_VAL.Timeout=120;
handles.UserData.sock=sock_VAL;
fopen(handles.UserData.sock);
with the udp callback function:
function udp_callback_Lok(sock, evt, handles)
D =(fread(sock, evt.Data.DatagramLength)); %, 'uint8'
D=char(D);
disp("Row " + str2double(D(1:8)) + "/" + str2double(D(9:16)))
%other code (tic toc says 0.001 ish seconds for one execution)
My sender looks like that:
function update_FrFA(~, ~, handles)
to_send=handles.VAL_System.UserData.VAL_Daten{1,4}(:,1:5);
FreigabeLok=to_send(:,3).*to_send(:,4).*to_send(:,5);
T=[to_send(:,1:2),FreigabeLok];
[z,s] = size(T);
T=[NaN(z,2),T]; % Fill the first columns for row numbering
T(:,1)=1:z; % number of the current row
T(:,2)=z; % number of rows
[z,~] = size(T);
% preallocation for TS_Freig
TS_Freig=repmat("",z,1);
%
for i=1:z
a_Freigabe = [num2str(T(i,1:2),'%08d'), num2str(T(i,3:4),'%04d'), num2str(T(i,5),'%01d')];
a_Freigabe=string(a_Freigabe);
b = "/";
TS_Freig(i,:) = join([a_Freigabe b],"");
end
sockel_Func=handles.VAL_System.UserData.sock_VAL_Lok;
for i=1:z
fwrite(sockel_Func, TS_Freig(i,1));
disp("sent: " + T(i,1))
end
The console output I get is a solid spam of "sent *row" up to the right amount and "Row x/y" until one to five rows before the actual last one. After that another round of "sent" and only then the receiver prints getting the last few rows.

Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!