mcu_matlab/McuLib/m/asynchManage.m
2025-06-19 13:29:33 +03:00

104 lines
3.5 KiB
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

classdef asynchManage < handle
properties (Access = private)
modelName % Имя модели
maskBlockPath % Полный путь к блоку с маской
timerSave
timerUpdate
timerConfigUpdate
end
methods
function obj = asynchManage(modelName, maskBlockPath)
% Конструктор принимает имя модели и путь к блоку с маской
obj.modelName = modelName;
if nargin < 2
obj.maskBlockPath = ''; % если не передали, оставляем пустым
else
obj.maskBlockPath = maskBlockPath;
end
end
function saveAndUpdateModel(obj)
obj.timerSave = timer(...
'StartDelay', 0.01, ...
'ExecutionMode', 'singleShot', ...
'TimerFcn', @(~,~) obj.saveCallback());
start(obj.timerSave);
end
function updateGUIfromConfig(obj)
obj.timerConfigUpdate = timer(...
'StartDelay', 0.01, ...
'ExecutionMode', 'singleShot', ...
'TimerFcn', @(~,~) obj.GUIconfigCallback());
start(obj.timerConfigUpdate);
end
end
methods (Access = private)
function saveCallback(obj)
try
mcuMask.close(obj.maskBlockPath);
save_system(obj.modelName);
catch ME
warning('progr:Nneg', 'Ошибка при сохранении модели: %s', ME.message);
end
stop(obj.timerSave);
delete(obj.timerSave);
obj.timerSave = [];
obj.timerUpdate = timer(...
'StartDelay', 0.05, ...
'ExecutionMode', 'singleShot', ...
'TimerFcn', @(~,~) obj.updateCallback());
start(obj.timerUpdate);
end
function updateCallback(obj)
try
set_param(obj.modelName, 'SimulationCommand', 'update');
save_system(obj.modelName);
catch ME
warning('progr:Nneg', 'Ошибка при обновлении модели: %s', ME.message);
end
% Открываем маску, если задан путь к блоку
if ~isempty(obj.maskBlockPath)
try
mcuMask.open(obj.maskBlockPath, 1);
catch ME
warning('progr:Nneg', 'Не удалось открыть маску: %s', ME.message);
end
end
stop(obj.timerUpdate);
delete(obj.timerUpdate);
obj.timerUpdate = [];
end
function GUIconfigCallback(obj)
try
mcuMask.close(obj.maskBlockPath);
mexing(0);
catch ME
warning('progr:Nneg', 'Ошибка при обновлении модели: %s', ME.message);
end
% Открываем маску, если задан путь к блоку
if ~isempty(obj.maskBlockPath)
try
mcuMask.open(obj.maskBlockPath, 1);
catch ME
warning('progr:Nneg', 'Не удалось открыть маску: %s', ME.message);
end
end
stop(obj.timerConfigUpdate);
delete(obj.timerConfigUpdate);
obj.timerConfigUpdate = [];
end
end
end