How do I close the udpport with 2021b? Error Unable to bind to LOCALHOST and LOCALPORT. Verify that the LOCALPORT is not in use...

I am switching my app to use the new udpport. It works the first time I use it. However, when I close the app, then run it again and attempt to connect, it seems that the resource is still in use:
Error: "Unable to bind to LOCALHOST and LOCALPORT. Verify that the LOCALPORT is not in use, and that LOCALHOST and LOCALPORT are valid for IPADDRESSVERSION "IPV4"."
I used to just use delete(isntrfind) or instrreset, but those don't seem to work. Now, if I start a udpport, then close the app, I get the error above. I have to close matlab to get it to forget the udp port.
Thanks!

1 Comment

Hi Brandon.
Add close button in first app where you can add clear udpport in the "ButtonPushedFcn" of close button.
In the second app in the startup function you can reconfigure the udpport .

Sign in to comment.

Answers (2)

Hey,
The only thing that actually close the conneciton for me is using the udpport function delete.
udpPort.delete();
flushing and clearing the object doesn't work.
in theory it needs to have the variable holding the port cleared. I suggest that you put in an onCleanup to ensure that it is done.

3 Comments

What command? fclose errors out. clear does not work. It still binds the next time it is called
app.ZMotor.portName=udpport("byte","LocalPort",7777) % This one works
% do some stuff with the port (writeline, etc.)
clear app.ZMotor.portName %Try to clear the port, deleted the variable but doesn't work
app.ZMotor.portName=udpport("byte","LocalPort",7777) %Try again and get an error:
Unable to bind to LOCALHOST and LOCALPORT. Verify that the LOCALPORT is not in use, and that LOCALHOST
and LOCALPORT are valid for IPADDRESSVERSION "IPV4"..
I also cannot connect to the device with the manufacturer provided software after making the udpport in matlab. Thanks.
I don't think you can clear a struct member; I think you would need to assign something else such as [] over top of app.ZMotor.portName

Sign in to comment.

Categories

Products

Release

R2021b

Asked:

on 30 Nov 2021

Commented:

on 31 Mar 2023

Community Treasure Hunt

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

Start Hunting!