GUIDE Callback function error

I am trying to create the simplest of simple GUIs with only one button that when clicked runs a .m file that is available in the Matlab path. The steps I take:
  1. Create new GUI with GUIDE and save as VHDL_Project_2014_Test
  2. Place one button in GUI and tag it buttonOpenCOM
  3. Modify the Callback function for buttonOpenCOM to run the .m file VHDL_Project_Open
  4. Save the project
  5. Run the main .m file (not the .fig file)
  6. When the GUI opens I click the button and get the following error message:
Error in VHDL_Project_2014_Test>buttonOpenCOM_Callback (line 81)
VHDL_Project_Open;
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in VHDL_Project_2014_Test (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)VHDL_Project_2014_Test('buttonOpenCOM_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Why is this error appearing? What can I do to remove it?
Note: I also get another error before this but this error I also get if I run the external .m file by itself (because nothing is connected to COM port 40 on my PC. For clarity this error message is:
Error using serial/fopen (line 72)
Open failed: Port: COM40 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the
requested device.
Error in VHDL_Project_Open (line 22)
fopen(s);

2 Comments

could you attach the file with your code or paste it to see how you code it?
I have added the files to my original post.

Sign in to comment.

 Accepted Answer

the problem isn't your GUI the problem is in your VHDL_Project_Open.m file, at the
fopen(s);
Line, this means that s is not valid!! this is mostly like because you don't have the COM40 port open in your computer, you have to ensure you know the name of the COM port opened in your computer, go to the Windows device administrator to see ports available.

3 Comments

Ketil
Ketil on 7 May 2014
Edited: Ketil on 7 May 2014
I think you might be right Roberto, however I now have a new problem.
If I run the local .m file it opens the COM port and the variable s is displayed in the main Matlab workspace.
If I click the button in the GUI nothing happens the first time. The second time I click it I get the same error message as I pasted in my original post.
This tells me that the .m file is probably executed successfully when I first click the button in the GUI but that the variable s is running in another workspace and not the main Matlab workspace.
Is this correct? What should I do if I want the s variable show up in the main Matlab interface?
On a side note: How do I make sure the s variable is available for other functions within my GUIDE GUI? When I add another button to my GUI and try to use the s variable I get the following error:
Undefined function or variable 's'.
Error in VHDL_Project_Start (line 3)
fwrite(s, '1', 'async');
Roberto
Roberto on 7 May 2014
Edited: Roberto on 7 May 2014
that's right, in fact everything executed in a GUI is running only in the GUI's workspace!! even more: only in the function that executed it!
you have various methods:
  • Nested functions
  • guidata
  • setappdata/getappdata
Try reading this
Thanks!

Sign in to comment.

More Answers (1)

Noor qazaer
Noor qazaer on 2 Oct 2017
i have a problem , what is a solve ????

1 Comment

Please open a new thread for a new question. This "thread hijacking" is confusing only and you cannot accept an answer, if it solves your problem. Please delete this pseudo-answer after you have created your own thread. Thanks.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Asked:

on 7 May 2014

Commented:

Jan
on 2 Oct 2017

Community Treasure Hunt

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

Start Hunting!