Skip to main content

Psim_GetProbes

Usage

% Usage:
cols = psim_get_colnames("buck.sch")

MATLAB function

function colNames = psim_get_colnames(schFilePath)
%PSIM_GET_COLNAMES Get probe names from a PSIM schematic
%
% Usage:
% cols = psim_get_colnames("buck.sch")

psim = psim_get_instance();

out = psim.Psim_GetProbes(schFilePath);

% Extract tuple safely
result = double(out{1});
namesStr = string(out{2});
err = string(out{4});

if result == 0
error("PSIM:GetProbesFailed", "%s", err);
end

% Handle both newline and null-separated formats
if contains(namesStr, newline)
colNames = strsplit(namesStr, newline);
else
colNames = strsplit(namesStr, char(0));
end

% Remove empty entries
colNames = colNames(colNames ~= "");
end
%PSIM_GET_COLNAMES Get probe names from a PSIM schematic
%
% Usage:
% cols = psim_get_probes("buck.sch")

psim = psim_get_instance();

out = psim.Psim_GetProbes(schFilePath);

% Extract tuple safely
result = double(out{1});
namesStr = string(out{2});
err = string(out{4});

if result == 0
error("PSIM:GetProbesFailed", "%s", err);
end

% Handle both newline and null-separated formats
if contains(namesStr, newline)
colNames = strsplit(namesStr, newline);
else
colNames = strsplit(namesStr, char(0));
end

% Remove empty entries
colNames = colNames(colNames ~= "");
end

Python def

PSIM 2025 and above:

def Psim_GetProbes(self, schFilePath_or_Obj):
result = 0
ErrorMessage = ""
szProbeNames = ""
szProbeCount = 0

try:
if not self.IsValid():
ErrorMessage = "PSIM object was not loaded."
Result = 0;
return result , szProbeNames, szProbeCount, ErrorMessage;


sch_closeFile = False
schHandle = 0
#is schFilePath a filePath or schematicID?
if isinstance(schFilePath_or_Obj, PSIM_schematic):
schHandle = schFilePath_or_Obj.value
elif isinstance(schFilePath_or_Obj, str):
schFilePath = schFilePath_or_Obj
SimOpenSchematicFileW = getattr(self.psimHandle, "SimOpenSchematicFileW")
if not SimOpenSchematicFileW:
raise AttributeError(self.VersionErrorMessage)

SimOpenSchematicFileW.restype = ctypes.c_int
# int SimOpenSchematicFileW(const wchar_t * szFileName, UINT nFlag)
schHandle = SimOpenSchematicFileW(ctypes.c_wchar_p(schFilePath), ctypes.c_int (1)); #returns 0 on error
if schHandle == 0 :
ErrorMessage = "Unable to open schematic file " + schFilePath
Result = 0;
return result , szProbeNames, szProbeCount, ErrorMessage;

sch_closeFile =True
elif schFilePath_or_Obj is None:
ErrorMessage = "in Psim_GetProbes function, schFilePath_or_Obj is None"
Result = 0;
return result , szProbeNames, szProbeCount, ErrorMessage;
else:
ErrorMessage = "in Psim_GetProbes function, schFilePath_or_Obj is of an unknown type"
Result = 0;
return result , szProbeNames, szProbeCount, ErrorMessage;

# BOOL SimGetProbes(int nID, int* pnProbeCount, char* szProbeNames, int* pnMaxBufferSize)
# get the function pointer
funcGetProbes = getattr(self.psimHandle, "SimGetProbes")
if not funcGetProbes:
raise AttributeError(self.VersionErrorMessage)


funcGetProbes.argtypes = [
ctypes.c_int, # nID
ctypes.POINTER(ctypes.c_int), # int* pnVariableCount
ctypes.c_char_p, # char* szVarNames
ctypes.POINTER(ctypes.c_int) # int* pnMaxBufferSize
]
funcGetProbes.restype = ctypes.c_int # Return type

# call funcGetProbes
pParameterCount = ctypes.c_int(0) # Initial value for pnVariableCount
initial_buffer_size = 1000
buffer_size = initial_buffer_size
pBufferSize = ctypes.c_int(buffer_size) # Set initial pBufferSize to buffer size

# Allocate buffer
szProbeNames_szValues = ctypes.create_string_buffer(buffer_size)

# Call the function
result = funcGetProbes(
schHandle,
ctypes.byref(pParameterCount),
szProbeNames_szValues,
ctypes.byref(pBufferSize)
)

if result == 0:
if pBufferSize.value > initial_buffer_size:
initial_buffer_size = pBufferSize.value
szProbeNames_szValues2 = ctypes.create_string_buffer(initial_buffer_size) # Allocate memory

result = funcGetProbes(
schHandle,
ctypes.byref(pParameterCount),
szProbeNames_szValues2,
ctypes.byref(pBufferSize)
)

if result == 0:
ErrorMessage = "in Psim_GetProbes function: Failed to retrieve probes."
result = 0
else:
# Retrieve the output values
szProbeCount = pParameterCount.value
updated_pBufferSize = pBufferSize.value
szProbeNames = szProbeNames_szValues2.value.decode('utf-8')
result = 1
else:
ErrorMessage = "in Psim_GetProbes function: Failed to retrieve probes. "
result = 0
else:
# Retrieve the output values
szProbeNames = szProbeNames_szValues.value.decode('utf-8')
updated_pBufferSize = pBufferSize.value
szProbeCount = pParameterCount.value
result = 1


if sch_closeFile:
CloseSchematicFile = getattr(self.psimHandle, "SimCloseSchematicFile")
if not CloseSchematicFile:
raise AttributeError(self.VersionErrorMessage)

CloseSchematicFile.restype = ctypes.c_int
# int SimCloseSchematicFile(int nSchematicID)
res = CloseSchematicFile(schHandle); #returns 0 on error

except Exception as e:
Result = 0
ErrorMessage += f"Error: {e}"

return result , szProbeNames, szProbeCount, ErrorMessage;