- Properly close the COM server at the end of your MATLAB
Why do I see "The RPC server is unavailable" when calling Hysys solver from MATLAB?
    5 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Hi! I am trying to automate my hysys model on MATLAB, and successfully linked via actxserver. Added my code below. Currently, I keep getting the error that
Warning: Error during simulation run: Invalid input for argument 2 (rhs2):
Value must be numeric or logical
I tried to see what the problem was and used the code: 
>> properties(MySimCase.Solver)
but I received back the error below: 
Error: The RPC server is unavailable.
When I code properties(MySimCase), it is able to list for me all the properties, only for solver it isnt.
Please help!
Below is the full code:
>> % Connect to HYSYS Application
try
    MyObject = actxserver('Hysys.Application');
catch ME
    error('Error connecting to HYSYS: %s', ME.message);
end
FileNamePath = 'Test'; % Adjust the filename as needed
try
    MySimCase = MyObject.SimulationCases.Open([cd, strcat('\', FileNamePath, '.hsc')]);
catch ME
    error('Error opening simulation case: %s', ME.message);
end
MySimCase.Visible = true;
% Verify the list of unit operations
try
    unitOperations = MySimCase.Flowsheet.Operations;
    numUnitOperations = unitOperations.Count;
    unitOperationNames = cell(numUnitOperations, 1);
    for idx = 1:numUnitOperations
        unitOperationNames{idx} = unitOperations.Item(idx - 1).Name; % Adjusting index for MATLAB (1-based)
    end
    disp('Available unit operations in the flowsheet:');
    disp(unitOperationNames);
catch ME
    error('Error accessing unit operations: %s', ME.message);
end
% Access the LIC control under unit operations
try
    LICSP = unitOperations.Item('LIC');
catch ME
    error('Error accessing LIC control: %s', ME.message);
end
if isempty(LICSP)
    error('The ''LIC'' control was not found in the flowsheet.');
end
% Display the properties of LICSP for debugging
disp('Properties of LICSP:');
disp(get(LICSP));
% Set the range for the filling level in LIC (SP)
startLevel = 0.5;
endLevel = 0.9;
stepSize = 0.1;
% Initialize variables for storing the results
seagoingBOG = [];
cjkBOG = [];
portBOG = [];
boilerBOG = [];
% Loop through the filling levels
fillingLevel = startLevel:stepSize:endLevel;
for i = 1:numel(fillingLevel)
    % Set the filling level value
    try
        LICSP.SPValue = fillingLevel(i); % Set the setpoint value
    catch ME
        warning('Error setting LIC control set point: %s', ME.message);
        continue;
    end
    % Run the simulation case
    try
        MySimCase.Solver.Integrator.RunUntil(MySimCase.Solver.Integrator.CurrentTime)
    catch ME
        warning('Error during simulation run: %s', ME.message);
        continue;
    end
    % Obtain Seagoing BOG
    try
        bog2Stream = MySimCase.Flowsheet.MaterialStreams.Item('BOG2');
        seagoingBOG(i) = bog2Stream.MolarFlow.GetValue('kgmole/h') * 8760; % Assuming 8760 hours in a year
    catch ME
        warning('Error accessing BOG2 stream for Seagoing BOG: %s', ME.message);
        seagoingBOG(i) = NaN;
    end
    % Obtain CJK BOG
    try
        bog2Stream = MySimCase.Flowsheet.MaterialStreams.Item('BOG2');
        cjkBOG(i) = bog2Stream.MolarFlow.GetValue('kgmole/h') * 8760 * 0.5; % Example: Assuming CJK BOG is 50% of BOG2
    catch ME
        warning('Error accessing BOG2 stream for CJK BOG: %s', ME.message);
        cjkBOG(i) = NaN;
    end
    % Obtain Port BOG
    try
        bog3Stream = MySimCase.Flowsheet.MaterialStreams.Item('BOG3');
        portBOG(i) = bog3Stream.MolarFlow.GetValue('kgmole/h') * 8760; % Assuming 8760 hours in a year
    catch ME
        warning('Error accessing BOG3 stream for Port BOG: %s', ME.message);
        portBOG(i) = NaN;
    end
    % Obtain Boiler BOG
    try
        bog2Stream = MySimCase.Flowsheet.MaterialStreams.Item('BOG2');
        bog3Stream = MySimCase.Flowsheet.MaterialStreams.Item('BOG3');
        boilerBOG(i) = (bog2Stream.MolarFlow.GetValue('kgmole/h') + bog3Stream.MolarFlow.GetValue('kgmole/h')) * 8760 - cjkBOG(i);
    catch ME
        warning('Error accessing BOG streams for Boiler BOG: %s', ME.message);
        boilerBOG(i) = NaN;
    end
end
% Close the HYSYS application
MyObject.Quit();
0 Kommentare
Antworten (1)
  Shubham
 am 6 Sep. 2024
        
      Bearbeitet: Shubham
 am 6 Sep. 2024
  
      Hi Jun,
The "RPC server is unavailable" error in MATLAB when calling HYSYS via "actxserver" arises from improper COM server closure, timing issues, or system service/firewall problems. This error can occur if a previous COM instance is still running or in the process of shutting down while a new one is being initiated.
To resolve this issue, you can follow these steps:
MyObject.Quit();  % Close the HYSYS application
delete(MyObject);  % Delete the COM object
          2. Add a small delay after closing the server to ensure it has enough time to terminate:
pause(5);  % Pause for 5 seconds
Refer to the following documentation link for more information on "pause" function:
Hope this helps
2 Kommentare
  Shubham
 am 6 Sep. 2024
				
      Bearbeitet: Shubham
 am 6 Sep. 2024
  
			Thanks for catching that @Walter Roberson. I was indeed referring to the "pause" function. Appreciate your attention to detail.
Siehe auch
Kategorien
				Mehr zu MATLAB Compiler SDK 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!


