| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
tline = fgetl(obj)
[tline,count] = fgetl(obj)
[tline,count,msg] = fgetl(obj)
tline = fgetl(obj) reads one line of text from the device connected to the serial port object, obj, and returns the data to tline. This returned data does not include the terminator with the text line. To include the terminator, use fgets.
[tline,count] = fgetl(obj) returns the number of values read to count, including the terminator.
[tline,count,msg] = fgetl(obj) returns a warning message to msg if the read operation was unsuccessful.
Before you can read text from the device, it must be connected to obj with the fopen function. A connected serial port object has a Status property value of open. An error is returned if you attempt to perform a read operation while obj is not connected to the device.
If msg is not included as an output argument and the read operation was not successful, then a warning message is returned to the command line.
The ValuesReceived property value is increased by the number of values read – including the terminator – each time fgetl is issued.
If you use the help command to display help for fgetl, then you need to supply the pathname shown below.
help serial/fgetl
A read operation with fgetl blocks access to the MATLAB command line until:
The terminator specified by the Terminator property is reached.
The time specified by the Timeout property passes.
The input buffer is filled.
On a Windows platform, create the serial port object s, connect s to a Tektronix® TDS 210 oscilloscope, and write the RS232? command with the fprintf function. RS232? instructs the scope to return serial port communications settings.
s = serial('COM1');
fopen(s)
fprintf(s,'RS232?')
Because the default value for the ReadAsyncMode property is continuous, data is automatically returned to the input buffer.
s.BytesAvailable
ans =
17
Use fgetl to read the data returned from the previous write operation, and discard the terminator.
settings = fgetl(s)
settings =
9600;0;0;NONE;LF
length(settings)
ans =
16
Disconnect s from the scope, and remove s from memory and the workspace.
fclose(s) delete(s) clear s
BytesAvailable, InputBufferSize, ReadAsyncMode, Status, Terminator, Timeout, ValuesReceived
![]() | fgetl | fgets | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |