Trying GUI with serial ports

2 次查看(过去 30 天)
Bence Salanki
Bence Salanki 2015-9-30
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.

回答(1 个)

Walter Roberson
Walter Roberson 2015-9-30
  2 个评论
Bence Salanki
Bence Salanki 2015-9-30
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 2015-9-30
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by