Open figure in standalone application
11 次查看(过去 30 天)
显示 更早的评论
I have a script controlling a motorized Pan-Tilt Unit (PTU) using a joystick. The way everything is set-up is that control is basically a continuous loop of 1) Check joystick position 2) Send command to PTU according to joystick position. 3) Repeat.
I want to be able to break this loop by pressing a button, so I can properly close all connections. GUIs, callbacks and more were completely new to me yesterday, but I found a simple solution that works in Matlab but not in the stand-alone application. Can anyone point out my mistake? Help is greatly appreciated!
< Note that the joystick control itself works fine (except for a delay, but that's just a minor problem righ tnow). It really is just the figure with stop-button that doesn't show up >
Code that is turned into a stand-alone .exe:
% COMPORT='COM1';
prompt = {'What COMPORT Should be used? Type {COMX} without brackets, replace X by a number'};
dlg_title = 'Comport';
num_lines = 1;
defaultans = {'COM2'};
COMPORT = inputdlg(prompt,dlg_title,num_lines,defaultans);
obj1=StartComms(COMPORT);
% Set PTU message variables
SSS='IP2'; %PTU slave device identifier
MMM='000'; %PTU master controller identifier
JoyID=0; %joystick ID on current machine
RunJoystick(JoyID,SSS,MMM,obj1)
(Note that the Comport dialogue box shows up perfectly!)
Then, the RunJoystick function is of the shape:
function RunJoystick(JoyID,SSS,MMM,obj1)
% Create figure with close button to stop joystick operation
DlgH = figure;
H = uicontrol('Style', 'PushButton', ...
'String', 'Break', ...
'Callback', 'delete(gcbf)');
while ishandle(H)
% Read Joystick position
%[CODE HERE]
% Steer unit if joystick is used
if [Joystick not centered]
[Send move command to PTU]
else %stop unit if joystick is centered
[Send stop command to PTU]
end
end
end
For some reason, the DlgH figure never shows up in the standalone version, while it does when running in Matlab.
If it is of any help, I create the standalone using
mcc -C -W CTF:archive_name_joytest -m SimpleJoystickTest.m
2 个评论
Adam
2018-2-16
Do you get an error when you run it? Either running it from command line or, if you force it to create a log then it will show up in there - I have no idea how to do that from the command line option though as I use the Compiler App instead.
采纳的回答
Greg
2018-2-16
编辑:Greg
2018-2-16
MATLAB does only continue to the next line when MATLAB is finished with the line. For graphics commands, MATLAB is done with the line as soon as the OS/GPU fully receives the command to draw to screen. Your pause(.01) gives enough downtime for the graphics queue to "flush" and the figure to appear.
Use drawnow instead. It is specifically designed for this purpose.
You'll probably also need a drawnow at the bottom of the while loop for the delete in the button's callback to register, thus ending the loop.
4 个评论
Greg
2018-2-19
Sorry for the confusion.
I was intentionally leaving out the pieces you already had, and denoting them with the "..." instances. I realize now that was likely ambiguous because "..." is line continuation.
Your fill-in looks good to me.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!