Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Read \r\n terminated string from instrument (GPIB)

HI. all
 
I think this is simple problem.
 
I  would like to read \r\n terminated string from instrument (hp3458a DVM)
For normal null terminated string, I had been no problem for reading other instruments.
My programming environments are
 
visual studio 2005 ( no measurement studio)
C#
NI GPIB driver for .net ver. 2.4
 
 
I tryed following code for open device
How read it?
-------------------------------------- start code--------------------------
public bool OpenDevice()
        {
            if (!bOpened)
            {
                try
                {
                    gpib = new Device(System.Convert.ToInt32(0), System.Convert.ToByte(addr), System.Convert.ToByte(0));
                    this.gpib.IOTimeout = TimeoutValue.T300ms;
                    gpib.TerminateReadOnEndOfString = true;
                    this.gpib.Reset();
                    bOpened = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return false;
                }
            }
            return true;
        }
------------------------------ end code-----------------------------------------
0 Kudos
Message 1 of 3
(3,033 Views)

Hello,

Are you sure this is a valid termination method for your instrument?  If so, make sure it is configured properly.  Are you getting an error?  You may also want to try out Hyperterminal to see if you can get a response from your device using this program.  Let me know how this goes.

Chris R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(3,018 Views)

Thank you for your response.

I had tryed posted code to open instrument and when I used simple readstring function

(ex:

       gpib.Write("OFORMAT ASCII");

       string str = gpib.ReadString()

)  

I met exception of read timeout.

So I changed read function like this.

public double ReadDCV()
 {
       gpib.Write("OFORMAT ASCII");
       string str = gpib.ReadString(18);
        return Convert.ToDouble(str)*1000;  //make to mV
 }

When I debugged above code, str contains 16 byte string data and 2byte (\r\n).

So I checed device send \r\n terminated string to my program.

Acually by above method I successfuly read ascii values from instrument.

But I would like to know the open method for this type of instrument

by simple ReadString function by using some change of open device setting.

Any suggestion would be greatly appreciated.

PS.

NI MAX also does not read from this device(HP3458A DVM) because of string termination.

 

0 Kudos
Message 3 of 3
(3,010 Views)