UDP problems in a timer and GUI environment

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 70×6 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. 70×4.

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);

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));

D=char(D);

disp(“Row ” + str2double(D(1:8)) + “/” + str2double(D(9:16)))

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];

T(:,1)=1:z;

T(:,2)=z;

[z,~] = size(T);

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.

Latest posts