Serial Port Communication Labview
Serial Port Communication Labview
Serial Port Communication Labview
National Instruments
This work is produced by The Connexions Project and licensed under the
∗
Creative Commons Attribution License
Abstract
In this lesson, you will learn about serial communication.
http://cnx.org/content/m12293/latest/
Connexions module: m12293 2
Figure 2
two-state coding scheme, the baud rate is identical to the maximum number of bits of
information, including control bits, that are transmitted per second.
MARK is a negative voltage, and SPACE is positive. Figure 2 shows how the idealized signal
looks on an oscilloscope. The following is the truth table for RS-232:
Signal > 3V = 0
http://cnx.org/content/m12293/latest/
Connexions module: m12293 3
Figure 3
2 Hardware Overview
There are many dierent recommended standards of serial port communication, including
the following most common types.
2.1 RS-232
The RS-449, RS-422, and RS-423 are additional EIA serial communication standards related
to RS-232. RS-449 was issued in 1975 and was supposed to supersede RS-232, but few
manufacturers have embraced the newer standard. RS-449 contains two subspecications
called RS-422 and RS-423. While RS-232 modulates a signal with respect to a common
ground, or single-ended transmission, RS-422 modulates two signals against each other,
or dierential transmission. The RS-232C receiver senses whether the received signal is
suciently negative with respect to ground to be a logical 1, whereas the RS-422 receiver
senses which line is more negative than the other. This makes RS-422 more immune to noise
and interference and more versatile over longer distances. The Macintosh serial ports follow
RS-422, which can be converted to RS-423 by proper wiring of an external cable. RS-423
can then communicate with most RS-232 devices over distances of 15 m or so.
Devices that use serial cables for their communication are split into two categories. These
are DCE and DTE. DCE are devices such as a modem, TA adapter, plotter, and so on,
while DTE is a computer or terminal. RS-232 serial ports come in two sizes, the D-Type
25-pin connector and the D-Type 9-pin connector. Both of these connectors are male on
the back of the PC. Thus, you require a female connector (Figure 3) on the device. pg 4
shows the pin connections for the 9-pin and 25-pin D-Type connectors.
http://cnx.org/content/m12293/latest/
Connexions module: m12293 4
Figure 4
The DB-9 connector is occasionally found on smaller RS-232 lab equipment. It is com-
pact, yet has enough pins for the core set of serial pins (with one pin extra).
Note: The DB-9 pin numbers for transmit and receive (3 and 2) are opposite
of those on the DB-25 connector (2 and 3). Be careful of this dierence when you
are determining if a device is DTE or DCE.
The DB-25 connector (Figure 4) is the standard RS-232 connector, with enough pins to
cover all the signals specied in the standard. pg 4 shows only the core set of pins that are
used for most RS-232 interfaces.
3 Software Overview
Use the VIs and functions located on the Functions>>All Functions>>Instrument
I/O>>Serial palette for serial port communication.
http://cnx.org/content/m12293/latest/
Connexions module: m12293 5
Figure 5
You used some of the VISA functions on this palette for GPIB communication. The
VISA Write and VISA Read functions work with any type of instrument communication
and are the same whether you are doing GPIB or serial communication. However, because
serial communication requires you to congure extra parameters, you must start the serial
port communication with the VISA Configure Serial Port VI.
The VISA Configure Serial Port VI initializes the port identied by VISA resource
name to the specied settings. timeout sets the timeout value for the serial communica-
tion. baud rate, data bits, parity, and flow control specify those specic serial port
parameters. The error in and error out clusters maintain the error conditions for this
VI.
Example 1:
Figure 5 shows how to send the identication query command *IDN? to the in-
strument connected to the COM2 serial port. The VISA Configure Serial Port
VI opens communication with COM2 and sets it to 9,600 baud, eight data bits,
odd parity, one stop bit, and XON/XOFF software handshaking. Then the VISA
Write function sends the command. The VISA Read function reads back up to 200
bytes into the read buer, and the Simple Error Handler VI checks the error
condition.
http://cnx.org/content/m12293/latest/