Serial Port Close and Open

2 次查看(过去 30 天)
dmfwlansejr
dmfwlansejr 2021-7-22
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 个)

类别

Help CenterFile 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!

Translated by