Skip to Main Content Skip to Search
Product Documentation

fwrite - Write binary data to instrument

Syntax

fwrite(obj,A)
fwrite(obj,A,'precision')
fwrite(obj,A,'mode')
fwrite(obj,A,'precision','mode')

Arguments

obj

An interface object.

A

The binary data written to the instrument.

'precision'

The number of bits written for each value, and the interpretation of the bits as character, integer, or floating-point values.

'mode'

Specifies whether data is written synchronously or asynchronously.

Description

fwrite(obj,A) writes the binary data A to the instrument connected to obj.

fwrite(obj,A,'precision') writes binary data with precision specified by precision.

precision controls the number of bits written for each value and the interpretation of those bits as integer, floating-point, or character values. If precision is not specified, uchar (an 8-bit unsigned character) is used. The support values for precision are listed in Supported Precisions.

fwrite(obj,A,'mode') writes binary data with command line access specified by mode. If mode is sync, A is written synchronously and the command line is blocked. If mode is async, A is written asynchronously and the command line is not blocked. If mode is not specified, the write operation is synchronous.

fwrite(obj,A,'precision','mode') writes binary data with precision specified by precision and command-line access specified by mode.

Tips

Before you can write data to the instrument, it must be connected to obj with the fopen function. A connected interface object has a Status property value of open. An error is returned if you attempt to perform a write operation while obj is not connected to the instrument.

The ValuesSent property value is increased by the number of values written each time fwrite is issued.

An error occurs if the output buffer cannot hold all the data to be written. You can specify the size of the output buffer with the OutputBufferSize property.

fwrite will return an error message if you set the FlowControl property to hardware on a serial object, and a hardware connection is not detected. This occurs if a device is not connected, or a connected device is not asserting that is ready to receive data. Check you remote device's status and flow control settings to see if hardware flow control is causing errors in MATLAB.

Synchronous Versus Asynchronous Write Operations

By default, data is written to the instrument synchronously and the command line is blocked until the operation completes. You can perform an asynchronous write by configuring the mode input argument to be async. For asynchronous writes,

You can determine whether an asynchronous write operation is in progress with the TransferStatus property.

Synchronous and asynchronous write operations are discussed in more detail in Synchronous Versus Asynchronous Write Operations.

Rules for Completing a Write Operation with fwrite

A binary write operation using fwrite completes when

Supported Precisions

The supported values for precision are listed below.

Data Type

Precision

Interpretation

Character

uchar

8-bit unsigned character

schar

8-bit signed character

char

8-bit signed or unsigned character

Integer

int8

8-bit integer

int16

16-bit integer

int32

32-bit integer

uint8

8-bit unsigned integer

uint16

16-bit unsigned integer

uint32

32-bit unsigned integer

short

16-bit integer

int

32-bit integer

long

32- or 64-bit integer

ushort

16-bit unsigned integer

uint

32-bit unsigned integer

ulong

32- or 64-bit unsigned integer

Floating-point

single

32-bit floating point

float32

32-bit floating point

float

32-bit floating point

double

64-bit floating point

float64

64-bit floating point

See Also

fopen | fprintf | instrhelp | OutputBufferSize | OutputEmptyFcn | Status | Timeout | TransferStatus | ValuesSent

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS