Connect interface object to instrument
This example creates the GPIB object g, connects g to the instrument using fopen, writes and reads text data, and then disconnects g from the instrument.
g = gpib('ni',0,1); fopen(g) fprintf(g,'*IDN?') idn = fscanf(g); fclose(g)
Before you can perform a read or write operation, obj must be connected to the instrument with the fopen function. When obj is connected to the instrument
Data remaining in the input buffer or the output buffer is flushed.
The Status property is set to open.
The BytesAvailable, ValuesReceived, ValuesSent, and BytesToOutput properties are set to 0.
An error is returned if you attempt to perform a read or write operation while obj is not connected to the instrument. You can connect only one interface object to a given instrument. For example, on a Windows® machine you can connect only one serial port object to an instrument associated with the COM1 port. Similarly, you can connect only one GPIB object to an instrument with a given board index, primary address, and secondary address.
Some properties are read-only while the interface object is connected, and must be configured before using fopen. Examples include InputBufferSize and OutputBufferSize. Refer to the property reference pages or use the propinfo function to determine which properties have this constraint.
The values for some properties are verified only after obj is connected to the instrument. If any of these properties are incorrectly configured, an error is returned when fopen is issued and obj is not connected to the instrument. Properties of this type include BaudRate and SecondaryAddress, and are associated with instrument settings.