Current location - Quotes Website - Team slogan - Reading serial port data with matlab
Reading serial port data with matlab
If you keep reading data, you can read the serial port with a timer. But it is not necessary, because the serial port has an attribute, when there is data in the receiving buffer, it can be automatically received. As follows:

comPort=get(handles.pumComPort,' String ');

handles . u _ sCom = serial(comPort { get(handles . pum comPort,' Value ')});

baudRate = get(handles . pumbaudrate,' String ');

set(handles.u_sCom,' BaudRate ',str 2 double(BaudRate { get(handles . pum BaudRate,' Value ')));

dataBits = get(handles . pumdatabits,' String ');

set(handles.u_sCom,' DataBits ',str 2 double(DataBits { get(handles . pumdatabits,' Value ')));

stop bits = get(handles . pumstopbits,' String ');

set(handles.u_sCom,' StopBits ',str 2 double(stop bits { get(handles . pumstopbits,' Value ')));

parity=get(handles.pumParity,' String ');

If strcmp (parity,' none') == 1

set(handles.u_sCom,' Parity ',' none ');

other

If strcmp (parity, odd parity) == 1

Set(handles.u_sCom,' parity',' odd');

other

If strcmp (parity, even parity) == 1

Set(handles.u_sCom,' parity',' even');

other

set(handles.u_sCom,' Parity ',' none ');

end

end

end

flow control = get(handles . pum flow control,' String ');

If strcmp (flow control,' none') == 1.

set(handles.u_sCom,' FlowControl ',' none ');

other

If strcmp (flow control,' hardware') == 1.

Set(handles.u_sCom,' flow control',' hardware');

other

If strcmp (flow control,' software') == 1.

Set(handles.u_sCom,' flow control',' software');

other

set(handles.u_sCom,' FlowControl ',' none ');

end

end

end

set(handles.u_sCom,' Timeout ', 1);

set(handles.u_sCom,' InputBufferSize ', 1024);

set(handles.u_sCom,' BytesAvailableFcnMode ',' byte ');

set(handles.u_sCom,' BytesAvailableFcnCount ', 1);

set(handles.u_sCom,' BytesAvailableFcn ',{@BytesAvailableFcnCallback,handles });

fopen(handles . u _ sCom);

Set(handles.txtStatus,' String',' port opened successfully');

set(hObject,' Enable ',' off ');

set(handles.btnClosePort,' Enable ',' On ');

guidata(hObject,handles);

set(handles.btnSendData,' Enable ',' On ');

As for all the formalities, I have sent them to you.