|On this page…|
The serial port interface is supported through a VISA-serial object. The features associated with a VISA-serial object are similar to the features associated with a serial port object. Therefore, only functions and properties that are unique to VISA's serial port interface are discussed in this section.
Refer to Serial Port Overview to learn about writing and reading text and binary data, using events and callbacks, using serial port control lines, and so on.
You create a VISA-serial object with the visa function. Each VISA-serial object is associated with an instrument connected to a serial port on your computer.
visa requires the vendor name and the resource name as input arguments. The vendor name can be agilent, ni, or tek. The resource name consists of the name of the serial port connected to your instrument. You can find the VISA-serial resource name for a given instrument with the configuration tool provided by your vendor, or with the instrhwinfo function. (In place of the resource name, you can use an alias as defined with your VISA vendor configuration tool.) As described in Connecting to the Instrument, you can also configure property values during object creation.
Some vendors do not provide VISA serial support until you enable a port in their configuration tools. Before you create a VISA object, find the instrument in the appropriate vendor VISA explorer. When you find the instrument configured, note the resource string and create the object using that information. For example, to create a VISA-serial object that is associated with the COM1 port, and that uses National Instruments® VISA,
vs = visa('ni','ASRL1::INSTR');
The VISA-serial object vs now exists in the MATLAB® workspace.
To open a connection with the instrument, type:
You can then display the class of vs with the whos command.
whos vs Name Size Bytes Class vs 1x1 888 visa object Grand total is 18 elements using 888 bytes
After you create the VISA-serial object, the properties listed below are automatically assigned values. These properties provide descriptive information about the object based on its class type and address information.
VISA-Serial Descriptive Properties
Specify a descriptive name for the VISA-serial object.
Indicate the serial port name.
Indicate the resource name for a VISA instrument.
Indicate the object type.
You can display the values of these properties for vs.
vs.Name ans = VISA-Serial-ASRL1
vs.Port ans = ASRL1
vs.RsrcName ans = ASRL1::INSTR
vs.Type ans = visa-serial
The VISA-serial object provides you with a convenient display that summarizes important address and state information. You can invoke the display summary these three ways:
Type the VISA-serial object at the command line.
Exclude the semicolon when creating a VISA-serial object.
Exclude the semicolon when configuring properties using the dot notation.
You can also display summary information via the Workspace browser by right-clicking an instrument object and selecting Display Summary from the context menu.
The display summary for the VISA-serial object vs is given below.
VISA-Serial Object Using NI Adaptor : VISA-Serial-ASRL1 Communication Settings Port: ASRL1 BaudRate: 9600 Terminator: 'LF' Communication State Status: closed RecordStatus: off Read/Write State TransferStatus: idle BytesAvailable: 0 ValuesReceived: 0 ValuesSent: 0
Before you can write or read data, both the VISA-serial object and the instrument must have identical communication settings. Configuring serial port communications involves specifying values for properties that control the baud rate and the Serial Data Format. These properties are given below.
VISA-Serial Communication Properties
Specify the rate at which bits are transmitted.
Specify the number of data bits to transmit.
Specify the type of parity checking.
Specify the number of bits used to indicate the end of a byte.
Specify the character used to terminate commands written to the instrument.
Refer to your instrument documentation for an explanation of its supported communication settings. Note that the valid values for StopBits are 1 and 2 and the valid values for Terminator do not include CR/LF and LF/CR. These property values differ from the values supported for the serial port object.
You can display the default communication property values for the VISA-serial object vs created in Creating a VISA-Serial Object.
vs.BaudRate ans = 9600
vs.DataBits ans = 8
vs.Parity ans = none
vs.StopBits ans = 1
vs.Terminator ans = LF