External Interfaces/API | ![]() ![]() |
Writing and Reading Data
For many serial port applications, there are three important questions that you should consider when writing or reading data:
For write operations, these questions are answered in Writing Data. For read operations, these questions are answered in Reading Data.
Example: Introduction to Writing and Reading Data
Suppose you want to return identification information for a Tektronix TDS 210 two-channel oscilloscope connected to the serial port COM1. This requires writing the *IDN?
command to the instrument using the fprintf
function, and then reading back the result of that command using the fscanf
function.
s = serial('COM1'); fopen(s) fprintf(s,'*IDN?') out = fscanf(s)
The resulting identification information is shown below.
out = TEKTRONIX,TDS 210,0,CF:91.1CT FV:v1.16 TDS2CM:CMV:v1.04
fclose(s) delete(s) clear s
![]() | Configuring Communication Settings | Controlling Access to the MATLAB Command Line | ![]() |