How to catch the error thrown when unable to connect to an arduino?
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
August Mendelsohn
am 22 Aug. 2019
Beantwortet: Walter Roberson
am 22 Aug. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 22 Aug. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!