Timeout Error fprintf to Arduino using GUIDE
이전 댓글 표시
Hello in the function below it is implemented a "save all" button which takes all modifications from the interface and sends them through the Serial Port to the Arduino.After i send the data i want to set the slider to the value of the textbox from which i have taken the value.(could this be the problem?)
The data is sent row by row delimited by commas.The first character is the identifier while the next after the comma is its value.
So if i send 2,200 it means 2-pwm fan command identifier and 200 the pwm value. Below i send data for 2 fans and 2 heaters.The problem is that when i start using the apply button it sometimes blocks with the following error.
Error using serial/fprintf (line 144)
Unexpected Error: A timeout occurred during the write operation.
Error in gui_3>Apply_btn_Callback (line 191)
fprintf(myport,send);
%-----------------------The function --------------------------------%
function Apply_btn_Callback(hObject, eventdata, handles)
global myport;
handles=guidata(hObject);
if(strcmp(handles.port_stt,'opened'));
%----------------------------------ZONE 1 APPLY------------------------%
handles.FAN_1_PWM=sprintf('%d',str2double(get(handles.SET_Fan1_TB,'String')));
set(handles.pwm_slider,'Value',str2double(handles.FAN_1_PWM));
handles.BULB_1_PWM=sprintf('%d',str2double(get(handles.SET_Bulb1_TB,'String')));
set(handles.pwm_slider_2,'Value',str2double(handles.BULB_1_PWM));
send=strcat('2,',handles.FAN_1_PWM);
fprintf(myport,send);
send=strcat('3,',handles.BULB_1_PWM);
fprintf(myport,send);
%----------------------------------ZONE 2 APPLY------------------------%
handles.FAN_2_PWM=sprintf('%d',str2double(get(handles.SET_Fan2_TB,'String')));
set(handles.pwm_slider_3,'Value',str2double(handles.FAN_2_PWM));
handles.BULB_2_PWM=sprintf('%d',str2double(get(handles.SET_Bulb2_TB,'String')));
set(handles.pwm_slider_4,'Value',str2double(handles.BULB_2_PWM));
send=strcat('4,',handles.FAN_2_PWM);
fprintf(myport,send);
send=strcat('5,',handles.BULB_2_PWM);
fprintf(myport,send);
guidata(hObject,handles);
end
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!