Serial Port Close and Open

3 ビュー (過去 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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by