get_psim_version
Usage
% Import the module
psim_module = py.importlib.import_module('psimapipy');
% Create the PSIM object (empty string = auto-detect from registry)
psim = psim_module.PSIM('');
% Verify it loaded correctly
if ~psim.IsValid()
error('PSIM failed to load');
end
ver = psim.get_psim_version();
ver_cell = cell(ver);
fprintf('PSIM version: %d.%d.%d.%d\n', ...
int32(ver_cell{1}), int32(ver_cell{2}), int32(ver_cell{3}), int32(ver_cell{4}));
disp(char(psim.get_psim_version()));
Verify PSIM version:
% Call the function (returns a py.tuple)
ver_tuple = psim.get_psim_version();
% Convert Python tuple to a MATLAB double array for easier comparison
% result will be something like [2023, 1, 0, 0]
ver_array = double(ver_tuple);
% Extract the major and minor versions
major_ver = ver_array(1);
minor_ver = ver_array(2);
fprintf('Detected PSIM Version: %d.%d.%d.%d\n', ...
ver_array(1), ver_array(2), ver_array(3), ver_array(4));
% Logic for 2023.1 or above
if major_ver > 2023
is_valid = true;
elseif major_ver == 2023 && minor_ver >= 1
is_valid = true;
else
is_valid = false;
end
if is_valid
disp('Status: Version compatibility confirmed.');
else
error('Status: PSIM 2023.1 or higher is required.');
end
The MATLAB Function: verify_psim_ver.m
function [is_ok, ver_info] = verify_psim_ver(method)
% VERIFY_PSIM_VER Checks if the installed PSIM version supports a specific method.
%
% Usage:
% ok = verify_psim_ver('Psim_GetProbes')
% [ok, ver] = verify_psim_ver('Psim_DS_UpdateParameters')
% 1. Import and Initialize
try
psim_module = py.importlib.import_module('psimapipy');
psim = psim_module.PSIM('');
catch
error('Could not load psimapipy. Ensure Python is configured in MATLAB.');
end
if ~psim.IsValid()
error('PSIM object invalid. Check your PSIM license and registry.');
end
% 2. Get Version Tuple from Python: (Major, Minor, Sub, SubSub)
py_tuple = psim.get_psim_version();
ver_info = double(py_tuple);
major = ver_info(1);
minor = ver_info(2);
% 3. Define Version Requirements for Methods
is_ok = false;
switch method
% --- 2026.0 Methods ---
case {'Psim_GetProbes', 'Psim_RunScriptFile', 'Psim_RunScript', 'get_psim_version_name'}
if major >= 2026
is_ok = true;
end
% --- 2025.0 Methods ---
case {'Psim_DS_UpdateParameters', 'Psim_DS_GetParameters', 'Psim_DS_RunScript', 'Psim_GetUndefinedParameters'}
if major >= 2025
is_ok = true;
end
% --- 2024.0 Methods ---
case {'PsimConvertToPython', 'PsimEnableElm3', 'PsimSetElmValue3'}
if major >= 2024
is_ok = true;
end
% --- 2023.1 Methods ---
case {'PsimSimulate_HyperSpice', 'PsimSimulate_LTSpice', 'PsimReadGraphFile'}
if major > 2023 || (major == 2023 && minor >= 1)
is_ok = true;
end
% --- Legacy / Baseline Methods ---
case {'PsimSimulate', 'PsimGetElementList', 'PsimSetElmValue'}
is_ok = true; % Assuming these exist in all modern versions
otherwise
warning('Method "%s" is not in the known compatibility list. Defaulting to major version check.', method);
if major >= 2023
is_ok = true;
end
end
% Output status to console
if is_ok
fprintf('Success: Method "%s" is supported by PSIM %d.%d\n', method, major, minor);
else
fprintf('Warning: Method "%s" requires a newer version (Current: %d.%d)\n', method, major, minor);
end
end
How to use it in your scripts:
You can use this as a "gatekeeper" before running simulation loops to prevent the script from crashing halfway through.
% Example: Checking for 2026 features
[status, ver] = verify_psim_ver('Psim_GetProbes');
if status
% Logic for high-end automation
disp('Using advanced 2026 probe retrieval...');
else
% Fallback logic for older versions
disp('Falling back to standard file parsing.');
end
Python def
def get_psim_version(self):
if not self.IsValid():
print("PSIM object was not loaded.")
return None;
GetPSIMVersion = getattr(self.psimHandle, "GetPSIMVersion")
if not GetPSIMVersion:
raise AttributeError(self.VersionErrorMessage)
# Create variables for the version info
nVersion = ctypes.c_int()
nSubVersion = ctypes.c_int()
nSubSubVersion = ctypes.c_int()
nSubSubSubVersion = ctypes.c_int()
nVertical = ctypes.c_int()
# Call the DLL function
ver = GetPSIMVersion(ctypes.byref(nVersion),
ctypes.byref(nSubVersion),
ctypes.byref(nSubSubVersion),
ctypes.byref(nSubSubSubVersion),
ctypes.byref(nVertical))
# print(f"PSIM version {nVersion.value}.{nSubVersion.value}.{nSubSubVersion.value}.{nSubSubSubVersion.value}")
# Check result if necessary, here assumed success
return (nVersion.value, nSubVersion.value, nSubSubVersion.value, nSubSubSubVersion.value)