Saturday, September 25, 2010

Serial Write & Read VI

Summary: For this exercise, the objective is to build a VI that communicates with an RS-232 device. Complete the following steps to use the Instrument I/O Assistant to build a VI that communicates with the NI Instrument Simulator.

NI Instrument Simulator

  1. Power off the NI Instrument Simulator and configure it to communicate through the serial port by setting the following switches on the side of the box.
    Figure 1
    Figure 1 (simserial.png)
    These switch settings configure the instrument as a serial device with the following settings:
    • Baud rate=9,600
    • Data bits=8
    • Parity=no parity
    • Stop bits=1
    • Flow control parameters=hardware handshaking
    Handshaking is a means of data flow control. Software handshaking involves embedding control characters in transmitted data. For example, XON/XOFF flow control works by enclosing a transmitted message between the two control characters XON and XOFF. Hardware handshaking uses voltages on physical wires to control data flow. The RTS and CTS lines of the RS-232 device are frequently used for this purpose. Most lab equipment uses hardware handshaking.
  2. Make sure the NI Instrument Simulator is connected to a serial port on the computer with a serial cable. Make a note of the port number.
  3. Power on the NI Instrument Simulator. The Power, Ready, and Listen LEDs are lit to indicate that the device is in serial communication mode.

Block Diagram

  1. Open a blank VI and build the block diagram shown in Figure 2.
    Figure 2
    Figure 2 (Serialbd.png)
    1. ioassist.png Place the Instrument I/O Express VI, located on the Functions>>Input palette, on the block diagram. Complete the following steps in the Instrument I/O Assistant dialog box that appears to configure the Express VI.
      1. Choose COM1 (or COM2 depending on the connection port of the NI Instrument Simulator) from the Select an instrument pull-down menu.
      2. Click the Add Step button and click Write. In the command field, type *IDN? and select \n as the Termination character.
      3. Click the Add Step button and click Read and Parse.
      4. Click the Add Step button and click Read and Parse again.


        The Instrument Simulator returns the byte size of the response, the termination character, the response, then another termination character. Therefore, after *IDN? is sent to the instrument, the response must be read twice.
      5. Click the Run button (not the Run this step button). The Run button runs the entire sequence.
      6. Return to the first Read and Parse step.
      7. Click the Auto parse button. The value returned is the size in bytes of the query response.
      8. Rename Token to String Length in the Token name text box.
      9. Select the second Read and Parse step.
      10. Click the Auto parse button. The value returned is the identification string of the NI Instrument Simulator.
      11. Rename Token to String in the Token name text box. The configuration window should be similar to the Figure 3.
        Figure 3
        Figure 3 (IOSerial.png)
      12. Select OK to return to the block diagram.
    2. Right-click the String output and select Create>>Indicator from the shortcut menu.
    3. Right-click the String Length output and select Create>>Indicator from the shortcut menu.


      Since LabVIEW is set to handle errors automatically, there is no need to connect a Simple Error Handler VI to error out.
  2. Display the front panel and run the VI.
  3. Save the VI as Serial in the C:\Exercises\LabVIEW Basics I directory.
  4. Close the VI when finished.

Content actions


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers