How to catch the error thrown when unable to connect to an arduino?
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
August Mendelsohn
le 22 Août 2019
Réponse apportée : Walter Roberson
le 22 Août 2019
I am trying to write some code that will scan the COM ports for an arduino, and if none are found I would like to throw my own error. So I would like to catch this error somehow: "Unable to find Arduino hardware at COM3. First argument must be a valid serial port, IP address/hostname or Bluetooth address/name."
Is there a way to do this?
This function simply returns the COM port for use in creating an arduino object.
Here is my code:
function port = ports()
%% Description
% Searches for the COM Port that the arduino is connected to.
%
%% Try Block
ports = seriallist();
for i = 1:length(ports)
try
a = arduino(ports{i});
clear a
port = ports{i};
catch
clear a
end
end
end
0 commentaires
Réponse acceptée
Walter Roberson
le 22 Août 2019
>> try; arduino("/dev/cu.Bluetooth-Incoming-Port"); catch ME; disp('nan nan nah'); end
nan nan nah
The particular exception is 'MATLAB:hwsdk:general:invalidPort' and arduino() without any arguments can also generate 'MATLAB:hwsdk:general:boardNotDetected'
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!