Trying GUI with serial ports

2 views (last 30 days)
Bence Salanki
Bence Salanki on 30 Sep 2015
Commented: Walter Roberson on 30 Sep 2015
Hi,
I'm trying to make a graphical user interface for serial communication between two of my USB ports. There are 2 edit boxes, one is for the tranciever the other is for the received data. There is a pushbutton also, when it's hit, the data must be sent from port A to port B. I tried this code:
function gomb_Callback(hObject, eventdata, handles)
s1 = get(handles.ado1, 'String'); %ado1 is the tranciever
fprintf(input, s1);
r1 = fscanf(output);
set(handles.vevo, 'String', r1); %vevo is the receiver
The instruments are connected and opened in the command window and it's working there, but in the GUI I get the following errors:
Error in ==> SerialCom>gomb_Callback at 174
fprintf(input, s1);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> SerialCom at 43
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)SerialCom('gomb_Callback',hObject,eventdata,guidata(hObject))
Please help me. Thanks.

Answers (1)

Walter Roberson
Walter Roberson on 30 Sep 2015
  2 Comments
Bence Salanki
Bence Salanki on 30 Sep 2015
Sorry I forgot to tell that in the command window I created 2 ports.
input = serial('COM3'); output = serial('COM4'); fopen(input); fopen(output);
I don't know where should I create it, but when I'd written it in the gui .m file it didn't work either.
Walter Roberson
Walter Roberson on 30 Sep 2015
You created those variables in the base workspace if you did that at the command line. Later when you find the appropriate place to put the code, the variables would be created in the workspace of some function. Either way you need to make the values available from the workspace they were defined in, to the place they need to be used. The link I included above discusses several ways that can be done.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!