How to select available COM-port from a table and input this in a serialport() function using MatLab App Designer?
Afficher commentaires plus anciens

Hello, i have designed a app in MatLab App Designer and need to be able to select a COM port.
The data is recieved from the serialportlist() function as shown below:
function RefreshButtonPushed(app, event)
freeport = serialportlist("available");
freeport = freeport';
app.UITable.Data = freeport;
end
The user can click the different rows to select the desired COM-port and the selection is saved in port.
function UITableCellSelection(app, event)
global port
port = event.Indices;
end
The selected port is then supposed to be put into the function serialport("COM#",115200). My problem is that i cannot figure out how to make the selected port appear in the "COM#". The selected port only outputs:
Error using serialport (line 116)
Unable to connect to the serialport device at port '2 1'. Verify that a device is connected to the port, the port is not in use, and all serialport input arguments and parameter values are supported by the device.
function Mode2ButtonPushed(app, event)
global s2;
global mode2;
global port;
formatSpec = "%s";
A1 = num2str(port);
str = sprintf(formatSpec,A1);
mode2 = 2;
s2 = serialport(str,115200);
write(s2,mode2,"uint8");
delete(s2);
clear s2;
end
1 commentaire
Jørgen Sørebø Myhre
le 18 Juin 2021
Réponses (1)
Jørgen Sørebø Myhre
le 21 Juin 2021
Catégories
En savoir plus sur Serial and USB Communication dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!