Get Started with Serial Port Interface
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
serialport
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 for more information about serial port communication.
Create VISA-Serial Object
Create a VISA-Serial object with the visadev
function. Each object is associated with an instrument
connected to a serial port on your computer.
visadev
requires the resource name or alias as an input. The
resource name consists of the name of the serial port connected to your instrument.
You can find the VISA-Serial resource name or alias for a given instrument with the
configuration tool provided by your vendor or with the visadevlist
function. Define the alias using your VISA vendor
configuration tool.
The VISA-Serial resource name has the format
ASRL[port_number]::INSTR
.
For example,use the VISA-Serial interface to connect to the COM1 port, use the following command.
visaserial = visadev("ASRL1::INSTR")
visaserial = Serial with properties: ResourceName: "ASRL1::INSTR" Alias: "COM1" Port: "ASRL1" BaudRate: 9600 Show all properties, functions
The VISA-Serial object visaserial
represents a connection to
your instrument. Click properties
in the object display to see a
full list of VISA-Serial properties.
ResourceName: "ASRL1::INSTR" Alias: "COM1" Port: "ASRL1" BaudRate: 9600 Type: serial PreferredVisa: "National Instruments VISA" ByteOrder: "little-endian" DataBits: 8 StopBits: 1 Parity: none FlowControl: none Timeout: 10 Terminator: "LF" NumBytesWritten: 0 ErrorOccurredFcn: [] UserData: []
You can use dot notation to configure and display property values. For more information about configuring these properties, see visadev Properties.
You can communicate with your instrument using the visadev
Object Functions.
Configure Communication Settings
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 as follows.
VISA-Serial Communication Properties
Property Name | Description |
---|---|
BaudRate | Specify the rate at which bits are transmitted. |
DataBits | Specify the number of data bits to transmit. |
Parity | Specify the type of parity checking. |
StopBits | Specify the number of bits used to indicate the end of a byte. |
Terminator | Specify the character used to terminate commands written to the instrument. |
Refer to your instrument documentation for an explanation of its supported communication settings.