Serial Port Close and Open
2 次查看(过去 30 天)
显示 更早的评论
I have design in GUIDE
First, I Write and Read. It's OK!
Second, I Write and Read
=> Write is OK! (The Board has LCD display), But Read data is First Write Data or all zero
=>However, Serial Port Close and Open then Second Write data is Read
EXAMPLE
WRITE 2, READ 2
WRTE 3 READ 2 or '0'
PORT CLOSE AND OPEN, THEN READ IS 3
WHERE IS THE PROBLEM?
% ------- Serial Port Open ----------------
function portopen_Callback(hObject, eventdata, handles)
global s
global portnum
s = serial(portnum, 'BaudRate', 115200, 'DataBits', 8, 'StopBits', 1, 'Parity', 'non');
set(s,'Terminator','');
fopen(s);
set(handles.text6,'String',' 115200bps, Data:8, Stop:1, No Parity'); % Overwrite
set(handles.text5,'String', [portnum ' Connect :']); % Overwrite
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in portclose.
function portclose_Callback(hObject, eventdata, handles)
global s
set(handles.text5,'String', ' Disconnect');
set(handles.text6,'String','');
fclose(s);
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Instrument Control Toolbox Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!