Read line of text from device and include terminator
tline = fgets(obj)
[tline,count] = fgets(obj)
[tline,count,msg] = fgets(obj)
tline = fgets(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
includes the terminator with the text line. To exclude the terminator,
use fgetl
.
[tline,count] = fgets(obj)
returns
the number of values read to count
, including the
terminator.
[tline,count,msg] = fgets(obj)
returns
a warning message to msg
if the read operation
was unsuccessful.
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 fgets
to read the data returned from
the previous write operation, and include the terminator.
settings = fgets(s)
settings = 9600;0;0;NONE;LF
length(settings)
ans = 17
Disconnect s
from the scope, and remove s
from
memory and the workspace.
fclose(s)
delete(s)
clear s
BytesAvailable
| BytesAvailableFcn
| fgetl
| fopen
| InputBufferSize
| Status
| Terminator
| Timeout
| ValuesReceived