How to connect between two GUI via serial visual port ?
1 次查看(过去 30 天)
显示 更早的评论
I want send data between two GUI and I use Virtual serial port software to creat two serial port. I can send data to terminal software But it didn't appear in GUI 2 as I want ?
In GUI1, I set:
if true
a={'a' '123' '456' '789' ...'999' };
s=serial('COM1')
s.ReadAsyncMode = 'continuous';
s.Terminator = 'Lf'; % or 'LF' or 'CR'
s.BytesAvailableFcnMode = 'terminator';.
s.BytesAvailableFcn = @BytesAvailable_Callback;
s.OutputEmptyFcn = @OutputEmpty_Callback;
s.BreakInterruptFcn = @BreakInterrupt_Callback;
s.ErrorFcn = @Error_Callback;
s.PinStatusFcn = @PinStatus_Callback;
s.BreakInterruptFcn = @BreakInterrupt_Callback;
fopen(s) ;
set(s, 'FlowControl', 'software');
get(s) ;
for i=1:length(a)
fprintf(s,'%c',a{i})
end
end
In GUI2, I set:
if true
function connect_com_Callback(hObject, eventdata, handles)
global s ;
s = serial(get_string_callback(handles.select_com),'BaudRate',9600);
s.BytesAvailableFcnCount = 1;
set(s,'Timeout',60);
s.Terminator = 'LF';
s.BytesAvailableFcnMode = 'byte';
s.InputBufferSize = 1400000;
s.OutputBufferSize = 1400000 ;
% Declare some callback functions or interrupt functions
s.BytesAvailableFcn = @BytesAvailable_Callback;
fopen(s) ;
% set(s, 'FlowControl', 'software');
get(s) ;
set(handles.edit_status,'String','Connected') ;% connected to com
handles.com = s;
guidata(hObject, handles);
function BytesAvailable_Callback(obj,event)
global s myData;
myData = fgets(s)
end
Please, help me
1 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!