| External Interfaces/API | ![]() |
Specify the M-file action function to execute when a specified number of bytes are available in the input buffer, or a terminator is read
Description
You configure BytesAvailableAction to execute an M-file action function when a bytes-available event occurs. A bytes-available event occurs when the number of bytes specified by the BytesAvailableActionCount property is available in the input buffer, or after a terminator is read, as determined by the the BytesAvailableActionMode property.
If the RecordStatus property value is on, and a bytes-available event occurs, the record file records this information:
BytesAvailableRefer to Creating and Executing Action Functions to learn how to create an action function.
Characteristics
| Read only |
Never |
| Data type |
Action function |
Values
The default value is an empty string.
Example
Create the serial port object s for a Tektronix TDS 210 two-channel oscilloscope connected to the serial port COM1.
s = serial('COM1');
Configure s to execute the M-file action function instraction when 40 bytes are available in the input buffer.
s.BytesAvailableActionCount = 40; s.BytesAvailableActionMode = 'byte'; s.BytesAvailableAction = 'instraction';
Connect s to the oscilloscope.
fopen(s)
Write the *IDN? command, which instructs the scope to return identification information. Since the default value for the ReadAsyncMode property is continuous, data is read as soon as it is available from the instrument.
fprintf(s,'*IDN?')
The resulting output from instraction is shown below.
BytesAvailable event occurred at 18:33:35 for the object: Serial-COM1.
56 bytes are read and instraction is called once. The resulting display is shown above.
s.BytesAvailable
ans =
56
Suppose you remove 25 bytes from the input buffer and then issue the MEASUREMENT? command, which instructs the scope to return its measurement settings.
out = fscanf(s,'%c',25);
fprintf(s,'MEASUREMENT?')
The resulting output from instraction is shown below.
BytesAvailable event occurred at 18:33:48 for the object: Serial-COM1. BytesAvailable event occurred at 18:33:48 for the object: Serial-COM1.
There are now 102 bytes in the input buffer, 31 of which are left over from the *IDN? command. instraction is called twice; once when 40 bytes are available and once when 80 bytes are available.
s.BytesAvailable ans = 102
Functions
Properties
BytesAvailableActionCount, BytesAvailableActionMode, RecordStatus, Terminator, TransferStatus
| BytesAvailable | BytesAvailableActionCount | ![]() |