- Ensure that the port is not blocked, especially if you are using a public network.
- If you are using a serial port interface for your program, refer to the "Transition Your Code to serialport Interface" page for guidance on migrating your code.
- For more insights and information, you can consult the documentation page for "udpport".
UDP Connection does not work in Matlab App Designer
조회 수: 3 (최근 30일)
이전 댓글 표시
Dear Matlab-Enthusiasts,
I am currently sending commands and recieving data from a device using a Matlab UDP datagram connection, which works perfectly fine as a Matlab script. However, if I try to convert this to an app, the connection does not happen: the other device does not recieve any commands and Matlab does not recieve any data, vice-versa. Could somebody maybe help me here?
In fact, I have a dialog window where the IP and Port are obtained, giving the global variables app.IP_adress and app.Port. Also, in the startup function I call a function that should enable the UDP connection. I am using Matlab R2022b. Here's my simplified code:
properties (Access = private)
IP_address %IP address of my device
Port %Port address of my device
u %the udp variable
end
methods (Access = private)
function Connect(app)
app.u = udpport("datagram","IPV4");
write(app.u,'Start'),"char",app.IP_raspi,app.Port_raspi);
%this should start the measurement on my device.
%It works in a Matlab Script, however not in the app: the device
%remains in a standby-mode, still waiting for the start-command
fprintf(app.u.NumDatagramsWritten);
%this is just a test: Matlab is convinced it sent a datagram to the
%device, the output will be equal to 1
while app.u.NumDatagramsAvailable == 0
%now, the app should wait for an answer from the device, that
%indicates the start of the measurement.
%If the device starts properly, the Connect-function will be
%ended and the app should continue in the startup-function.
%UNFORTUNATELY, THIS DOES NOT HAPPEN. Matlab is waiting HERE
%for a Datagram, that is not recieved.
%(how should it, if the first datagram sent never arrived...)
end
...
function startupFcn(app)
app.StartDialogApp = StartDialog(app);
%this is the window in which IP and Port are declared
waitfor(app.StartDialogApp);
%Matlab waits for the Dialog to be ended
%connect
ConnectRaspi(app);
waitfor(app.ConnectRaspi);
msgbox('Yas! We are connected!')
% a simple test which should indicate, that the UDP connection is
% enabled.
% This message-box will not be reached...
end
I already tried to impliment the Connect-function into the startup-function. Also, I tried to declare u as public property. Even to have u as an output of the connect-function instead having a global variable did not do the job.
Any ideas?
댓글 수: 0
답변 (1개)
Tushar
2023년 8월 30일
Hi Arne,
I understand that you are experiencing issues with packets not being sent out or received while using the "UDP Interface". Based on the information provided, it seems that the port might not be opened in your code. To resolve this, you can open the port using the following commands:
port_variable = udpport("name of the port", portNumber);
fopen(port_variable);
Additionally, please consider the following:
I hope these resources and suggestions help you in debugging the issue you are facing.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!