MessageBasedSessionWriter Class

NI-VisaNS .NET Class Library Help for Visual Studio 2010

Edition Date: August 2012

Part Number: 370627F-01

»View Product Info
Download Help (Windows Only)

Members Example See Also


Represents a writer that can write formatted data to an IMessageBasedSession.

Namespace: NationalInstruments.VisaNS

Assembly: NationalInstruments.VisaNS (in NationalInstruments.VisaNS.dll) Version: 13.0.40.167

Syntax

Visual Basic (Declaration)
Public Class MessageBasedSessionWriter _
	Inherits MarshalByRefObject

C#
public class MessageBasedSessionWriter : MarshalByRefObject

Remarks

This class provides access to higher level message-based functionality available in VISA for writing numeric, textual, and binary data in various formats.

Examples

The following example creates a GpibSession, a MessageBasedSessionWriter, and a MessageBasedSessionReader to a Fluke 45 digital multimeter. The example resets the device, performs an identification query, configures the device to take a measurement, and writes the results to the console. Finally, the example closes the MessageBasedSessionReader, the MessageBasedSessionWriter, and then the GpibSession.
VB.NET
Sub TakeAMeasurement(ByVal resourceDescriptor As String)
    Dim mbs As New GpibSession(resourceDescriptor)
    Dim writer As New MessageBasedSessionWriter(mbs)
    Dim reader As New MessageBasedSessionReader(mbs)

    Dim vendor As String
    Dim model As Integer
    Dim firmware As Integer
    Dim displayVersion As String
    Dim measurement As Double
    Dim unit As String

    'Reset the device.
    writer.Write("*RST")
    writer.Flush()

    'Send an id query to the device and parse the result.
    'WriteLine implicitly flushes the output buffer.
    writer.WriteLine("*IDN?")
    vendor = reader.ReadMismatch(",")
    reader.ReadString(", ")
    model = reader.ReadInt32()
    reader.ReadString(", ")
    firmware = reader.ReadInt32()
    reader.ReadString(", ")
    displayVersion = reader.ReadString()

    'Remove remaining contents from the input buffer.
    reader.DiscardUnreadData()

    'Configure the device to take a resistance measurement.
    writer.WriteLine("OHMS;RANGE {0};RATE {1};", 1, "M"c)

    'Query the device for a measurement value.
    writer.WriteLine("VAL1?")
    measurement = reader.ReadDouble()
    unit = reader.ReadString()

    'Write the results to the console.
    Console.WriteLine("Vendor: {0}", vendor)
    Console.WriteLine("Model: {0}", model)
    Console.WriteLine("Firmware Version: {0}", firmware)
    Console.WriteLine("Display Version: {0}", displayVersion)
    Console.WriteLine("Measurement: {0:E} {1}", measurement, unit)

    'Dispose the GpibSession.
    mbs.Dispose()
End Sub
C#
public void TakeAMeasurement (string resourceDescriptor)
{
    using (MessageBasedSession mbs = new GpibSession(resourceDescriptor))
    {
        MessageBasedSessionWriter writer = new MessageBasedSessionWriter(mbs);
        MessageBasedSessionReader reader = new MessageBasedSessionReader(mbs);
        string vendor;
        int model;
        int firmware;
        string displayVersion;
        double measurement;
        string unit;

        //Reset the device.
        writer.Write("*RST");
        writer.Flush();

        //Send an id query to the device and parse the result.
        //WriteLine implicitly flushes the output buffer.
        writer.WriteLine("*IDN?");
        vendor = reader.ReadMismatch(",");
        reader.ReadString(", ");
        model = reader.ReadInt32();
        reader.ReadString(", ");
        firmware = reader.ReadInt32();
        reader.ReadString(", ");
        displayVersion = reader.ReadString();

        //Remove remaining contents from the input buffer.
        reader.DiscardUnreadData();

        //Configure the device to take a resistance measurement.
        writer.WriteLine("OHMS;RANGE {0};RATE {1};", 1, 'M');

        //Query the device for a measurement value.
        writer.WriteLine("VAL1?");
        measurement = reader.ReadDouble();
        unit = reader.ReadString();

        //Write the results to the console.
        Console.WriteLine("Vendor: {0}", vendor);
        Console.WriteLine("Model: {0}", model);
        Console.WriteLine("Firmware Version: {0}", firmware);
        Console.WriteLine("Display Version: {0}", displayVersion);
        Console.WriteLine("Measurement: {0:E} {1}", measurement, unit);
    }
}

Inheritance Hierarchy

System.Object
    System.MarshalByRefObject
        NationalInstruments.VisaNS.MessageBasedSessionWriter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

See Also

Reference

MessageBasedSessionWriter Members

NationalInstruments.VisaNS Namespace

WAS THIS ARTICLE HELPFUL?

Not Helpful