Retrieve BER values from Optisystem

13 views (last 30 days)
Salem
Salem on 22 Oct 2025 at 9:26
Answered: Umar on 26 Oct 2025 at 12:04
Hi
i'm trying to retrieve BER values from optisystem and save them into CSV file. At line 13, I receive this error: Unrecognized method, property, or field 'System' for class 'COM.OptiSystem_Application'.
% Retrieves BER Analyzer results and saves them to a CSV file.
% Define the path to your OptiSystem project
optisystemProjectPath = 'C:\Users\Me\Documents\FSO\Simulations\Turbulence.osd';
% Define output CSV file path
outputCSV = 'C:\Users\Me\Documents\FSO\Simulations\ber_results.csv';
% Start OptiSystem COM server
optisystem = actxserver('OptiSystem.Application');
% === project loading ===
systemDoc = optisystem.System;
systemDoc.Load(optisystemProjectPath);
% Run simulation
systemDoc.Calculate;
% === Retrieve BER values ===
berData = {};
componentCount = systemDoc.ComponentsCount;
for i = 1:componentCount
component = systemDoc.GetComponent(i);
compName = component.Name;
if contains(compName, 'BER Analyzer', 'IgnoreCase', true)
try
result = component.GetResult('BER');
berValue = result.GetValue;
berData{end+1,1} = compName; %#ok<SAGROW>
berData{end,2} = berValue;
fprintf('BER from %s: %e\n', compName, berValue);
catch ME
fprintf('No valid BER in %s (%s)\n', compName, ME.message);
end
end
end
% === Save results to CSV ===
if ~isempty(berData)
berTable = cell2table(berData, 'VariableNames', {'Component', 'BER'});
writetable(berTable, outputCSV);
fprintf('BER results saved to %s\n', outputCSV);
else
warning('No BER Analyzer components found.');
end
% Close project and release COM
systemDoc.Close;
delete(optisystem);

Answers (1)

Umar
Umar on 26 Oct 2025 at 12:04

Hi @Salem,

I’ve made the necessary updates to the MATLAB script based on your feedback and some further research. The error you encountered, "Unrecognized method, property, or field 'System' for class 'COM.OptiSystem_Application'", was caused by trying to access a non-existent `System` property in the OptiSystem COM interface. After looking into this, I found that the correct method for opening a project is `OpenProject`, not accessing `System`. So, I replaced the attempt to access the `System` property with the `OpenProject` method to load the OptiSystem project correctly. I also wrapped key sections of the script (project loading, simulation, and BER retrieval) in `try-catch` blocks to handle any errors gracefully and provide better feedback if anything goes wrong and made sure the script checks for components that contain "BER Analyzer" in their names and retrieves the BER values using the `GetResult('BER')` method. Finally, the retrieved BER values are saved into a CSV file for easy review.

Updated Script

% Define the path to your OptiSystem project
optisystemProjectPath = 'C:
\Users\Me\Documents\FSO\Simulations\Turbulence.osd';
% Define output CSV file path
outputCSV = 'C:\Users\Me\Documents\FSO\Simulations\ber_results.csv';
% Start OptiSystem COM server
optisystem = actxserver('OptiSystem.Application');
% === Open the OptiSystem project ===
try
  % Use OpenProject method instead of System to load the project
  optisystem.OpenProject(optisystemProjectPath);
  fprintf('Project loaded successfully: %s\n', optisystemProjectPath);
catch ME
  fprintf('Error loading project: %s\n', ME.message);
  return; % Exit the script if project loading fails
end
% === Run simulation ===
try
  % Run the simulation (assuming optisystem object has Calculate method)
  optisystem.Calculate;
  fprintf('Simulation completed successfully.\n');
catch ME
  fprintf('Error running simulation: %s\n', ME.message);
  return; % Exit the script if simulation fails
end
% === Retrieve BER values from components ===
berData = {}; % Initialize cell array to store BER data
componentCount = optisystem.ComponentsCount;
for i = 1:componentCount
  try
      % Get the component (assuming optisystem has GetComponent method)
      component = optisystem.GetComponent(i);
      compName = component.Name;
        % Check if component is a BER Analyzer
        if contains(compName, 'BER Analyzer', 'IgnoreCase', true)
            result = component.GetResult('BER'); % Get the BER result
            berValue = result.GetValue;          % Retrieve the BER value
            berData{end+1, 1} = compName;       % Store component name
            berData{end, 2} = berValue;         % Store BER value
            fprintf('BER from %s: %e\n', compName, berValue);
        end
    catch ME
        fprintf('Error retrieving BER from component %d: %s\n', i, ME.message);
    end
  end
% === Save results to CSV ===
if ~isempty(berData)
  berTable = cell2table(berData, 'VariableNames', {'Component', 'BER'});
  writetable(berTable, outputCSV);
  fprintf('BER results saved to %s\n', outputCSV);
else
  warning('No BER Analyzer components found or no valid results retrieved.');
end
% Close project and release COM
optisystem.Close;
delete(optisystem);

So, please test this updated script on your end and check whether it loads the project, runs the simulation, and retrieves the BER values as expected. The results will be saved in a CSV file, which you can open to verify the BER values. Please make sure that the paths for your OptiSystem project (`optisystemProjectPath`) and the output CSV file (`outputCSV`) are correct.

If any errors occur, the `try-catch` blocks will provide helpful error messages to identify where the issue happened (e.g., project loading, simulation, or BER retrieval).

Please let me know how the script works on your end, and feel free to reach out if any issues arise during testing.

Hope this helps!

Categories

Find more on Wireless Communications in Help Center and File Exchange

Products


Release

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!