Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Matlab to determine if the OS is windows, or mac? So to find all serial-usb connections

Description of goal:

I'm trying to get matlab to determine if the computer is running windows, or mac. My main goal for this is to write a robust script to determine what serial ports are available, and USB ports (for the same reason) to identify which is an Arduino.

Current work:

I have a script that queries the registry on Windows and successfully identifies this information. However, I'm trying to make this script robust and identify for both mac and windows.

Request: If there is a better way to do this in matlab? And how do I do it robustly, hopefully independent of OS if possible, or if not, how do I do this on a Mac! Note, (instrfindall) only identifies objects to ports, which are therefore already open. So it is sadly not a solution.

EDIT: I can determine if it's MAC or WINDOWS via ismac, and ispc calls. However, the main guts of this question still remains!

like image 902
Leon92 Avatar asked Sep 14 '25 11:09

Leon92


1 Answers

Even easier. MATLAB has a method to flag each OS without going to the level of CPU architecture.

if ismac
    % Code to run on Mac platform
elseif isunix
    % Code to run on Linux platform
elseif ispc
    % Code to run on Windows platform
else
    disp('Platform not supported')
end

Note: I am a MathWorks employee.

like image 74
yuvalz Avatar answered Sep 17 '25 03:09

yuvalz