📄 mc9s12_callback_handler.m
字号:
function mc9S12_callback_handler (varargin)
% mc9S12_CALLBACK_HANDLER - RTW GUI callback handler
% fw-02-05
if (nargin == 0)
dialogFig = get (gcbo, 'Parent');
else
dialogFig = varargin{1};
end
% get handles to all objects
extMD = findobj (dialogFig, 'Tag', 'External mode_CheckboxTag');
comBD = findobj (dialogFig, 'Tag', 'Communication speed_PopupFieldTag');
comSP = findobj (dialogFig, 'Tag', 'Host sided communication port_PopupFieldTag');
matCP = findobj (dialogFig, 'Tag', 'Target sided communication port_PopupFieldTag');
timSG = findobj (dialogFig, 'Tag', 'Timing signals_CheckboxTag');
cycTI = findobj (dialogFig, 'Tag', 'Cycle time signal pin_EditFieldTag');
serTI = findobj (dialogFig, 'Tag', 'Serial reception signal pin_EditFieldTag');
timPT = findobj (dialogFig, 'Tag', 'Timing signaling port_PopupFieldTag');
lcdEM = findobj (dialogFig, 'Tag', 'Use LCD display for error messages_CheckboxTag');
serDB = findobj (dialogFig, 'Tag', 'RT logging information (debug) on SCI0_PopupFieldTag');
tarPF = findobj (dialogFig, 'Tag', 'Target platform_PopupFieldTag');
% freCP = findobj (dialogFig, 'Tag', 'Free communications port_PopupFieldTag');
switch(gcbo)
case extMD
if (isequal(get(extMD,'Value'),0))
% If extMD has just been switched off -> also switch off comBD and comSP
set(comBD, 'Enable', 'off');
set(comSP, 'Enable', 'off');
set(matCP, 'Enable', 'off');
% ... and switch to 'normal' mode
set_param(gcs,'SimulationMode', 'normal');
else
% Else, extMD has just been activated... -> activate comBD and comSP
set(comBD, 'Enable', 'on');
set(comSP, 'Enable', 'on');
set(matCP, 'Enable', 'on');
% ... and switch to 'external' mode
set_param(gcs,'SimulationMode', 'external');
% determine current baudrate settings
baudrate = get(comBD, 'String');
baudrate = baudrate(get(comBD, 'Value'), :);
% determine current port settings
port = get(comSP, 'String');
port = port(get(comSP, 'Value'), 4);
% ensure that communication parameters are set in 'ext_comm'
hModel = get_param(gcs, 'handle');
kk = get_param(hModel, 'ExtModeMexArgs');
ll = findstr(kk, ',');
if(~isempty(ll))
ll = deblank(kk(ll(1)+1:ll(2)-1));
else
ll = '0'; % default 'verbosity' : 'off'
end
ext_comm_str = [port ',' ll ',' baudrate];
if(~strcmp(kk, ext_comm_str))
set_param(hModel, 'ExtModeMexArgs', ext_comm_str);
end
% ensure that communication module is set to 'ext_comm_ms9S12'
kk = get_param(gcs, 'ExtModeMexFile');
if(~strcmp(kk, 'ext_comm_mc9S12'))
set_param(gcs, 'ExtModeMexFile', 'ext_comm_mc9S12');
end
% ensure that the FreePort is set to the other port...
% set(freCP, 'Value', 3 - str2num(port));
% save model...
save_system;
end
case {comBD, comSP}
% user changed communication port (COMx), baudrate settings or verbosity level
% determine current baudrate settings
baudrate = get(comBD, 'String');
baudrate = baudrate(get(comBD, 'Value'), :);
% determine current port settings
port = get(comSP, 'String');
port = port(get(comSP, 'Value'), 4);
% ensure that communication parameters are set in 'ext_comm'
hModel = get_param(gcs, 'handle');
kk = get_param(hModel, 'ExtModeMexArgs');
ll = findstr(kk, ',');
if(~isempty(ll))
ll = deblank(kk(ll(1)+1:ll(2)-1));
else
ll = '0'; % default 'verbosity' : 'off'
end
ext_comm_str = [port ',' ll ',' baudrate];
if(~strcmp(kk, ext_comm_str))
set_param(hModel, 'ExtModeMexArgs', ext_comm_str);
% save model...
save_system;
end
case timSG
if (isequal(get(timSG,'Value'),0))
% If timSG has just been switched off -> also switch off cycTI, serTI and timPT
set(cycTI, 'Enable', 'off');
set(serTI, 'Enable', 'off');
set(timPT, 'Enable', 'off');
else
% Else, extMD has just been activated... -> activate cycTI, serTI and timPT
set(cycTI, 'Enable', 'on');
set(serTI, 'Enable', 'on');
set(timPT, 'Enable', 'on');
end
case {cycTI, serTI}
% ensure that we're using the correct pin format and that there is no conflict...
cycTIstr = upper(deblank(get(cycTI,'String')));
serTIstr = upper(deblank(get(serTI,'String')));
% if(cycTIstr(1) ~= 'P' | isempty(findstr(cycTIstr, '^')) | length(findstr(cycTIstr, '^')) ~= 1)
% set(cycTI, 'String', '');
% error('Pin format: P<port>^<pin>')
%
% elseif(serTIstr(1) ~= 'P' | isempty(findstr(serTIstr, '^')) | length(findstr(serTIstr, '^')) ~= 1)
% set(serTI, 'String', '');
% error('Pin format: P<port>^<pin>')
%
% elseif(isequal(cycTIstr, serTIstr))
if(isequal(cycTIstr, serTIstr))
% pin conflict
if(gcbo == cycTI)
cycTIstr = [];
set(cycTI, 'String', cycTIstr);
else
serTIstr = [];
set(serTI, 'String', serTIstr);
end
error('Pin conflict: Use separate pins to monitor the cycle time and serial communication interrupts.')
end
% case serDB
%
% % user changed level of debugging messages to be displayed via SCI0
%
% % determine current baudrate settings
% serMSlvl = get(serMS, 'String');
% serMSlvl = serMSlvl(get(serMS, 'Value'), :);
%
case tarPF
% get target board specifier
target = get(tarPF, 'Value');
if(target == 1)
% -- Dragon12 --
% select SCI1 as MATLAB_SCI_PORT
set(matCP, 'Value', 2); % 2 -> second entry, which is 'SCI1'
disp(['Setting target sided communication port to SCI1 (default on Dragon-12)'])
% select default serial port on the host : COM2
set(comSP, 'Value', 2); % 2 -> second entry, which is 'COM2'
disp(['Setting host sided communication port to COM2 (default for Dragon-12)'])
% enable LCD error messages (default for Dragon-12)
set(lcdEM, 'Value', 1); % checkbox -> 0 = off, 1 = on
end
if(target == 2)
% -- MiniDragon+ --
% switch off debugging through SCI0 (if required)
dbgmsgSCI0 = get(serDB, 'Value');
if(dbgmsgSCI0 > 1)
set(serDB, 'Value', 1); % 1 -> first entry, which is '0'
disp(['Warning: Disabling debug messages through SCI0 (not used on the MiniDragon+)'])
end
% switch off error messages on the LCD
errmsgLCD = get(lcdEM, 'Value');
if(errmsgLCD == 1)
set(lcdEM, 'Value', 0); % checkbox -> 0 = off, 1 = on
disp(['Warning: Disabling LCD display based error messages (not supported on the MiniDragon+)'])
end
% select SCI0 as MATLAB_SCI_PORT
set(matCP, 'Value', 1); % 1 -> first entry, which is 'SCI0'
disp(['Setting target sided communication port to SCI0 (default on MiniDragon+)'])
% select default serial port on the host : COM1
set(comSP, 'Value', 1); % 1 -> first entry, which is 'COM1'
disp(['Setting host sided communication port to COM1 (default for MiniDragon+)'])
% save model...
save_system;
end
if(target == 3)
% -- University of Adelaide, mobile robot (MiniDragon+ based, download via SCI0, communication w/h MATLAB through SCI1) --
% switch off error messages on the LCD
errmsgLCD = get(lcdEM, 'Value');
if(errmsgLCD == 1)
set(lcdEM, 'Value', 0); % checkbox -> 0 = off, 1 = on
disp(['Warning: Disabling LCD display based error messages (not supported on the MiniDragon+)'])
end
% select SCI1 as MATLAB_SCI_PORT
set(matCP, 'Value', 2); % 2 -> second entry, which is 'SCI1'
disp(['Setting target sided communication port to SCI1 (default for UofA mobile robot)'])
% select default serial port on the host : COM2
set(comSP, 'Value', 2); % 2 -> second entry, which is 'COM2'
disp(['Setting host sided communication port to COM2 (default for UofA mobile robot)'])
% disable LCD error messages (no LCD on the MiniDragon+)
set(lcdEM, 'Value', 0); % checkbox -> 0 = off, 1 = on
% save model...
save_system;
end
case matCP
% set MATLAB comms port (SCI0/SCI1)
target = get(tarPF, 'Value');
if(target == 1)
% -- Dragon12 --
% do nothing...
end
if(target == 2)
% -- MiniDragon+ --
% select SCI0 as MATLAB_SCI_PORT
set(matCP, 'Value', 1); % 1 -> first entry, which is 'SCI0'
disp(['Warning: Resetting target sided communication port to SCI0 (default on MiniDragon+)'])
end
% set FreePort to the other port
% matPort = get(matCP, 'Value');
% set(freCP, 'Value', 3-matPort);
case lcdEM
% ensure this is not switched on when working on the MiniDragon+
target = get(tarPF, 'Value');
if(target == 1)
% -- Dragon12 --
% do nothing...
end
if(target == 2)
% -- MiniDragon+ --
% no LCD display...
set(lcdEM, 'Value', 0); % 0 = off
disp(['Warning: There is no LCD display on the MiniDragon+'])
end
% case freCP
%
% extMode = get(extMD, 'Value');
% if(extMode)
% % selected MATLAB communications port is used -> set FreePort to the other port
% matPort = get(matCP, 'Value');
% set(freCP, 'Value', 3-matPort);
% else
% % no external mode -> don't change anything
% end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -