MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Manuel d'utilisateur Page 359

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 408
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 358
Writing and Reading Data
8-39
Note that for a given read operation, you may not know the number of bytes
returned by the device. Therefore, you may need to preset the
InputBufferSize property to a sufficiently large value before connecting the
serial port object.
As shown below, after the data is stored in the input buffer, it is then
transferred to the output variable specified by
fscanf.
Reading Text Data
You use the fgetl, fgets, and fscanf functions to read data from the device,
and format the data as text.
For example, suppose you want to return identification information for the
oscilloscope. This requires writing the
*IDN? command to the instrument, and
then reading back the result of that command.
s = serial('COM1');
fopen(s)
fprintf(s,'*IDN?')
out = fscanf(s)
out =
TEKTRONIX,TDS 210,0,CF:91.1CT FV:v1.16 TDS2CM:CMV:v1.04
By default, fscanf reads data using the %c format since the data returned by
many serial port devices is text based. However, you can specify many other
formats as described in the
fscanf reference pages.
out=fscanf(s)
...
MATLABInput Buffer
Bytes used during read
Bytes unused during read
data
Vue de la page 358
1 2 ... 354 355 356 357 358 359 360 361 362 363 364 ... 407 408

Commentaires sur ces manuels

Pas de commentaire